【发布时间】:2011-09-30 11:27:03
【问题描述】:
我正在使用 Ruby on Rails 3.1.0 和 rspec-rails 2gem。我想测试一些session 数据是否已设置为nil。
在我的控制器中,我有:
def create
...
session[:user] = nil
...
end
在相关的规范文件中,我想做如下内容:
it "should be set to nil" do
# Here I would like to expect if the 'session[:user]' is set to 'nil'
# NOT using this approach:
#
# session[:user].should be_nil
#
# That is, I would be sure that the 'session[:user] = nil' runs the same way
# I may do with method "expectation". For example:
#
# mock_model(User).should_receive(:find).and_return(nil)
#
# Maybe a solution can be similar to this (note: of course, the following
# doesn't work):
#
# session[:user].should_receive(:"=").and_return(nil)
post :create, { ... }, { ... }
...
end
有可能吗?如果有,怎么做?
P.S.:我想使用这种方法来检查一些特定的内部行为。
更新 ...我如何测试以下内容?
session[:user][:nested_key] = nil
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 rspec rspec2