开发者

Test flash notice in layout view spec (rspec2, rails3)

I'd like to spec the fact that my application layout view prints out flash notices. However the following code does not run, the flash method does not exist in view specs (as opposed to controller specs where it works perfectly):

describe 'layouts/application' do
  it "renders flash notices" do
    flash[:notice] = "This is a notice!"
    render
    response.should contain "This is a notice!"
  end
end

Is my code wrong or is it a "not-yet-implemented feature" in Rspec 2? I'm on Rails3 and R开发者_开发知识库spec2 from its master branch on Git.

Thanks!


Funny, I was just searching here on the flash issue because my authentication cucumber stories in Rails 3 beta 3 and RSpec 2 appear to be broken where they are hitting the flash notices.

So, I think you're right. There is either some new trick in using flash notices in Rails3 with RSpec2 or RSpec2 has not implemented this.

Very problematic if you're trying to port Cucumber stories over to Rails3 right now.


I don't think there's an easy way to do this with Rspec. However, it's a perfect application for Cucumber, where you could write something like this:

  Scenario: Layout displays flash messages
    Given a layout
    When I render the view
    Then I should see "This is a notice!"

Of course your scenario would do something unique to your application, so you could test that the actual message you expected is being rendered.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜