【发布时间】:2011-07-23 20:16:47
【问题描述】:
使用 Rails 3.0.5、RSpec 2 和 Capybara 0.4.1.2,我正在尝试为我的 SessionsController#new 操作编写控制器规范。
it "assigns the empty session to a variable" do
get :new
assigns(:session).should == ActiveRecord::Base::Session.new
end
我正在使用 ActiveRecord::Base 命名空间,因为我不使用它时它似乎与 Capybara Session 类发生冲突。
这里是 SessionsController:
class SessionsController < ApplicationController
def new
@session = Session.new
end
end
RSpec 似乎不理解这些是相同的对象。这是我的测试返回的结果:
Failure/Error: assigns(:session).should == ActiveRecord::Base::Session.new
expected: #<Session id: nil, session_id: nil, data: nil, created_at: nil, updated_at: nil>
got: #<Session id: nil, session_id: nil, data: nil, created_at: nil, updated_at: nil> (using ==)
Diff:
# ./spec/controllers/sessions_controller_spec.rb:17:in `block (3 levels) in <top (required)>'
有什么提示吗?
【问题讨论】:
标签: ruby-on-rails-3 session rspec2 capybara