Rspec 如何编写规范来测试对象是否具有特定值?
我想测试对象在Rails操作中是否具有特定值。我怎样才能用Rspec做到这一点 我最初的尝试是:Rspec 如何编写规范来测试对象是否具有特定值?,rspec,ruby-on-rails-3,Rspec,Ruby On Rails 3,我想测试对象在Rails操作中是否具有特定值。我怎样才能用Rspec做到这一点 我最初的尝试是: it "should have @body_class equal to 'buildings'" do response.should =~ / buildings / end 编辑: 我应该指定@body_class正在控制器中设置,并由助手用于为body标记的class属性赋值。我希望它可能在响应对象中可用,但它不可用。实例变量可以在赋值哈希中找到: # controller def
it "should have @body_class equal to 'buildings'" do
response.should =~ / buildings /
end
编辑:
我应该指定@body_class正在控制器中设置,并由助手用于为body标记的class属性赋值。我希望它可能在响应对象中可用,但它不可用。实例变量可以在
赋值
哈希中找到:
# controller
def index
@foo = "foo"
end
# spec
it "should assign foo" do
get :index
assigns[:foo].should == "foo"
end