1

How would you write a new.html.erb_spec.rb view spec for this relationship. I am stumped.

  resources :things do
    resources :reviews
  end

Thank you.

Kent

neofetter
  • 3,004
  • 2
  • 26
  • 26

1 Answers1

0
require 'spec_helper'

describe "reviews/new.html.erb" do
  before(:each) do
    assign(:thing,mock_model(Thing) # RSpec 2 syntax
  end

  it "shows the page" do
    render
  end
end

After the render statement add a matcher for content in the page, like:

rendered.should contain("some text to match")
zetetic
  • 47,184
  • 10
  • 111
  • 119
  • Can you show how you would test for presence of forms etc, actions etc. – neofetter Apr 04 '11 at 20:00
  • `render` will fail if there is no matching template file. You can also do `response.should render_template` in a controller test, which has the additional benefit of verifying that the action exists. Take a look at the spec files generated by `rails generate scaffold` -- they contain good examples for model, view, and controller specs. – zetetic Apr 05 '11 at 05:15