Authlogic 和 RSpec,仅运行所有示例时出错

发布于 2024-09-08 04:08:46 字数 2872 浏览 4 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贩梦商人 2024-09-15 04:08:46

也许在您的过滤器之前,您可以添加一些步骤来注销当前会话。

Perhaps in your before filter you could add some steps to log out the current session.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文