我有一个配置文件控制器acts_as_authentic
与AuthLogic,我正在尝试测试此操作:
class ProfilesController < ApplicationController
before_filter :require_user, :except => ['new', 'create']
def index
redirect_to(current_user)
end
end
以下示例位于包含其他18个待处理示例的规范文件中。当autospec仅运行此文件时,我得到一个类似于此19 examples, 0 failures, 18 pending
的输出,表示示例正在传递,当autospec运行我的所有规范时,我得到145 examples, 19 failures
此规范中的所有示例现在都失败了。
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: "user133@example.com", 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:
只有在运行所有规格时才会导致此问题?
答案 0 :(得分:0)
也许在您之前的过滤器中,您可以添加一些步骤来注销当前会话。