2009-09-02 6 views
2

"rake test:functionals"を実行してもテストは失敗しますが、autotestを使って一貫して渡します。Authlogicを使って "autotest"を使ってテストに合格 "rake test"しない

rakeを使用しているときにAuthlogicがユーザーに正しくログインしていないことが問題のテストに関係しているようです。次のように試験中にユーザにログイン容易にするため、私はテストヘルパーメソッドを有する

class ActionController::TestCase 
    def signin(user, role = nil) 
    activate_authlogic 
    UserSession.create(user) 
    user.has_role!(role) if role 
    end 
end 

上記方法は、ユーザがサインインするために使用される

マイスタックはshoulda/authlogic/acl9あります/ factory_girl /モカ

私はAuthlogicが問題であることを疑う理由は、失敗のテストは次のようになります:

 54) Failure: 
test: A logged in user PUT :update with valid data should redirect to user profile. (UsersControllerTest) 
    [/var/lib/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/action_controller/macros.rb:202:in `__bind_1251895098_871629' 
    /var/lib/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `call' 
    /var/lib/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `test: A logged in user PUT :update with valid data should redirect to user profile. ']: 
Expected response to be a redirect to <http://test.host/users/92> but was a redirect to <http://test.host/signin>. 

55) Failure: 
test: A logged in user PUT :update with valid data should set the flash to /updated successfully/i. (UsersControllerTest) 
    [/var/lib/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/assertions.rb:55:in `assert_accepts' 
    /var/lib/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/action_controller/macros.rb:41:in `__bind_1251895098_935749' 
    /var/lib/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `call' 
    /var/lib/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/context.rb:351:in `test: A logged in user PUT :update with valid data should set the flash to /updated successfully/i. ']: 
Expected the flash to be set to /updated successfully/i, but was {:error=>"You must be signed in to access this page"} 

答えて

1

あなたの問題がどこにあるのか分かりませんが、ユニットテスト/ rspecの代わりにコントローラとユーザインタラクションをテストするためにCucumberを使用することをお勧めします。その理由は、あなたが持っている認証コードと認証コードを含めて、あなたのアプリ全体を動かすからです。

2

Autotestはすべてのテストファイルupfront AFAIRを読み込みます(RSpecではそうしていますが、私は間違いがあるかもしれないので、これまでずっとプレーンテストを行っていません)。

コントローラを適切にテストするには、setUpメソッドでactivate_authlogicを呼び出す必要があります。これはおそらく統合テストのために自動的に(グローバルに)行われます。

autotestはすべてのテストを読み込むので、このグローバルなsetUpと機能テストが合格になります。機能テストのみを実行すると、authlogicは有効にならず、テストは失敗します。

0

明らかに、ユーザーはログインしていません.Bragi Ragnarsonのようなものがあるかもしれません。ここで

は、問題を特定するためにいくつかの他のものです:テストが不完全または自動テストのいくつかの副作用に頼っている場合

  • を理解します。自身でテストを実行します。

    ルビーテスト/汎関数/ users_controllers_test.rb

  • おそらくそれは動作しません。そうでなければ、自動テストによって非機能テストのために呼び出されるいくつかのグローバルコードがあります。おそらく、テスト/統合ディレクトリまたはテスト/ユニットディレクトリのコード設定か、そこに必要なディレクトリの1つです。

関連する問題