4
私は機能テストをしようとしており、Wardenにログインする必要があります。ワーデンの機能テスト?
私が行っている:
class ActionController::TestCase
include Warden::Test::Helpers
end
を私のテストケースは単純です:
def test_access_admin_as_superuser
login_as(Person.make(:superuser))
get :index
assert_response :success
assert_nil flash[:warning]
end
私はlogin_as(user)
を行うと、私がそれをして失敗しますget '/admin'
を行うとき以外は動作するようです:
1) Error:
test_access_admin_as_superuser(AdminControllerTest):
NoMethodError: undefined method `user' for nil:NilClass
/home/silas/.rubygems/gems/gems/rails_warden-0.5.2/lib/rails_warden/controller_mixin.rb:21:in `current_user'
app/controllers/application_controller.rb:100:in `require_user'
test/functional/admin_controller_test.rb:20:in `test_access_admin_as_superuser'
代替として、私はこのcontroller.stubs @ のようないくつかのモックを使用するためにあなたを指すことができます(:CURRENT_USER).returns(@user) この上の任意の運? –