2011-07-25 10 views
0

私のスペック/コントローラ/ superadmin/users_controller_spec.rbで、次のとおりです。このスペック/コントローラテストに合格しないのはなぜですか?それは前にやった...(レール、RSpecの)

describe "GET index" do 
    it "receives the where action twice" do 
     User.should_receive(:where).twice 
     get :index 
    end 

    it "assigns @superadmins" do 
     get :index 
     assigns[:superadmins].should_not be_nil 
    end 

    it "assigns @admins" do 
     get :index 
     assigns[:admins].should_not be_nil 
    end 
    end 

私のアプリ/コントローラ/ superadmin/users_controller.rbで、次のとおりです。

正しくリコールすれば、このテストに合格しました。テストと開発環境用のデータベースとしてPostgreSQLをセットアップして以来、このテストは失敗しています...なぜその理由はわかりません。

エラーメッセージ:

Failures: 

    1) Superadmin::UsersController GET index receives the where action twice 
    Failure/Error: User.should_receive(:where).twice 
     (<User(id: integer, role: string, first_name: string, last_name: string, login: string, email: string, crypted_password: string, password_salt: string, persistence_token: string, single_access_token: string, perishable_token: string, login_count: integer, failed_login_count: integer, last_request_at: datetime, current_login_at: datetime, last_login_at: datetime, current_login_ip: string, last_login_ip: string, created_at: datetime, updated_at: datetime, restaurant_id: integer, organization_id: integer) (class)>).where(any args) 
      expected: 2 times 
      received: 0 times 
    # ./spec/controllers/superadmin/users_controller_spec.rb:6:in `block (3 levels) in <top (required)>' 

    2) Superadmin::UsersController GET index assigns @superadmins 
    Failure/Error: assigns[:superadmins].should_not be_nil 
     expected: not nil 
      got: nil 
    # ./spec/controllers/superadmin/users_controller_spec.rb:12:in `block (3 levels) in <top (required)>' 

    3) Superadmin::UsersController GET index assigns @admins 
    Failure/Error: assigns[:admins].should_not be_nil 
     expected: not nil 
      got: nil 
    # ./spec/controllers/superadmin/users_controller_spec.rb:17:in `block (3 levels) in <top (required)> 

支援感謝します!

+0

どのテストに失敗していますか?失敗メッセージとは何ですか?誰もあなたの質問にもっと情報なしで答えることは非常に難しいでしょう。 – Emily

+0

ああ、私はそれを忘れることができました - それを今追加... – dmonopoly

答えて

1

あなたが提供したコードで、これらのテストが失敗するようなことはありません。失敗するかもしれないbefore_filtersがありますか?私はそのコントローラが認証を必要としていると推測しています。前のブロックであなたのテストにそれを設定していますか?

+0

ああ - 認証の欠如が問題です!あなたの直感に感謝します。私はテストをより頻繁に行うべきだと思うので、私のテストが何を破壊するのかが分かります。データベースの変更が原因であると考えるのは不合理でした。私は、(1)検証を追加し、(2)間にテストを実行せずにdbsを変更する必要があります。学んだ教訓。 :] – dmonopoly

+0

私はオートテストを強くお勧めします:https://rubygems.org/gems/autotest – Emily

+0

Hmm。申し訳ありませんが、テーブルに何が追加されているのかわかりません... https://github.com/rspec/rspec/wiki/autotestを意味していますか? – dmonopoly

関連する問題