Authlogic 和 RSpec,仅运行所有示例时出错
我有一个使用 AuthLogic acts_as_authentic
的配置文件控制器,我正在尝试测试此操作:
class ProfilesController < ApplicationController
before_filter :require_user, :except => ['new', 'create']
def index
redirect_to(current_user)
end
end
以下示例位于一个规范文件中,其中包含其他 18 个待处理示例。当 autospec 仅运行此文件时,我会得到如下所示的输出 19 Examples, 0 failure, 18 pending
,表示该示例正在通过,当 autospec 运行我的所有规范时,我会得到 145 Examples, 19 failure
此规范中的所有示例现在都失败了。
describe ProfilesController, "for logged in user" do
before(:each) do
@profile = Factory(:profile)
controller.stubs(:current_user).returns(@profile)
ApplicationController.stubs(:require_user).returns(true)
end
# Index
context "on get to index" do
it "should redirect to show user's profile" do
get :index
response.should redirect_to(profile_url(@profile))
end
end
end
当 autospec 运行所有规范时,对于每个失败的规范,我都会收到此错误:
19)
Spec::Mocks::MockExpectationError in 'ProfilesController for logged in user on get to index should redirect to show user's profile'
Mock "ProfileSession_1005" received unexpected message :priority_record= with (#<Profile id: nil, first_name: "Test", last_name: "User", email: "[email protected]", username: "user133", crypted_password: "7aed8331f6d4518483855c07c1b5a507a3f81e5b52019d93d2e...", password_salt: "Nd2gQZjOUA0Ij0IuO6Vp", created_at: nil, updated_at: nil, is_admin: nil, persistence_token: "b439ff8bd952964a68a6d00126bafe954e4eab053d81872233e...", perishable_token: "xis77hpS32Wn9pu1PF5R", active: false>)
/Library/Ruby/Gems/1.8/gems/authlogic-2.1.5/lib/authlogic/session/persistence.rb:38:in `find'
/Library/Ruby/Gems/1.8/gems/authlogic-2.1.5/lib/authlogic/acts_as_authentic/session_maintenance.rb:96:in `get_session_information'
/Library/Ruby/Gems/1.8/gems/authlogic-2.1.5/lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `each'
/Library/Ruby/Gems/1.8/gems/authlogic-2.1.5/lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `get_session_information'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/proxy/create.rb:6:in `result'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:326:in `run'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:270:in `create'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:301:in `send'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:301:in `default_strategy'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl.rb:20:in `Factory'
/Applications/MAMP/htdocs/my_application/spec/controllers/profiles_controller_spec.rb:5:
仅当运行所有规范时,什么会导致此问题?
I have a Profiles Controller that acts_as_authentic
with AuthLogic and I am trying to test this action:
class ProfilesController < ApplicationController
before_filter :require_user, :except => ['new', 'create']
def index
redirect_to(current_user)
end
end
The following example is in a spec file with 18 other pending examples. When autospec runs only this file I get an output like this 19 examples, 0 failures, 18 pending
which says the example is passing, when autospec runs all my specs I get 145 examples, 19 failures
all examples from this spec are failing now.
describe ProfilesController, "for logged in user" do
before(:each) do
@profile = Factory(:profile)
controller.stubs(:current_user).returns(@profile)
ApplicationController.stubs(:require_user).returns(true)
end
# Index
context "on get to index" do
it "should redirect to show user's profile" do
get :index
response.should redirect_to(profile_url(@profile))
end
end
end
I get this error for every failing spec when autospec runs all the specs:
19)
Spec::Mocks::MockExpectationError in 'ProfilesController for logged in user on get to index should redirect to show user's profile'
Mock "ProfileSession_1005" received unexpected message :priority_record= with (#<Profile id: nil, first_name: "Test", last_name: "User", email: "[email protected]", username: "user133", crypted_password: "7aed8331f6d4518483855c07c1b5a507a3f81e5b52019d93d2e...", password_salt: "Nd2gQZjOUA0Ij0IuO6Vp", created_at: nil, updated_at: nil, is_admin: nil, persistence_token: "b439ff8bd952964a68a6d00126bafe954e4eab053d81872233e...", perishable_token: "xis77hpS32Wn9pu1PF5R", active: false>)
/Library/Ruby/Gems/1.8/gems/authlogic-2.1.5/lib/authlogic/session/persistence.rb:38:in `find'
/Library/Ruby/Gems/1.8/gems/authlogic-2.1.5/lib/authlogic/acts_as_authentic/session_maintenance.rb:96:in `get_session_information'
/Library/Ruby/Gems/1.8/gems/authlogic-2.1.5/lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `each'
/Library/Ruby/Gems/1.8/gems/authlogic-2.1.5/lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `get_session_information'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/proxy/create.rb:6:in `result'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:326:in `run'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:270:in `create'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:301:in `send'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:301:in `default_strategy'
/Library/Ruby/Gems/1.8/gems/factory_girl-1.3.1/lib/factory_girl.rb:20:in `Factory'
/Applications/MAMP/htdocs/my_application/spec/controllers/profiles_controller_spec.rb:5:
What would cause this problem only when all specs are run?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许在您的过滤器之前,您可以添加一些步骤来注销当前会话。
Perhaps in your before filter you could add some steps to log out the current session.