【发布时间】:2010-09-12 03:54:23
【问题描述】:
我正在尝试模拟控制器的会话哈希,如下所示:
it "finds using the session[:company_id]" do
session.should_receive(:[]).with(:company_id).and_return 100
Company.should_receive(:find).with(100)
get 'show'
end
当我调用 get 'show' 时,它会显示:
received :[] with unexpected arguments
expected: (:company_id)
got: ("flash")
控制器代码如下:
def show
company_id = session[:company_id]
@company = Company.find params[company_id]
end
我也简单地尝试过设置
it "finds using the session[:company_id]" do
session[:company_id]= 100
Company.should_receive(:find).with(100)
get 'show'
end
但随后遇到以下问题:
expected: (100)
got: (nil)
有人知道为什么吗?
【问题讨论】:
-
这是我对这个问题的回答:stackoverflow.com/questions/8043956/…
标签: ruby-on-rails rspec rspec2