开发者

How do I write a spec to test whether an object has a specific value?

I'd like 开发者_运维问答to test whether an object has a certain value on a Rails action. How can I do that with Rspec?

My initial attempt at it was:

it "should have @body_class equal to 'buildings'" do
  response.should =~ / buildings /
end

EDIT:

I should specify that @body_class is being set in the controller, and used by a helper to assign a value to the class attribute of the body tag. I expected it might be available in the response object, but it isn't.


Instance variables can be found in the assigns hash:

# controller

def index
  @foo = "foo"
end

# spec

it "should assign foo" do
  get :index
  assigns[:foo].should == "foo"
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜