Question

I am using rspec and webrat for behavior driven development. This is the first time I am using webrat.

I followed webrat's instructions on how to use the gem, so I think it is installed correctly (the gem shows when I use bundle show).

The problem occurs when I just want to test whether my rendered view (welcome/index.html.erb) has an h1 tag. Should be fairly simple.

My code looks like this:

require 'spec_helper'

describe "welcome/index.html.erb" do
  render :template => "welcome/index", :layout => "layouts/application"

  it "displays a welcome message" do
    rendered.should have_selector "h1"
  end
end

I got there because of this question, but maybe it is a little old. When I run the test it gives me

undefined method `render'

What am I doing wrong? How can I fix this?

Was it helpful?

Solution

Found a way to solve it. Apparently this is much easier than I thought:

describe "welcome/index.html.erb" do
  it "displays a welcome message" do
    render
    rendered.should have_selector "h1"
  end
end

Apparently I just have to say render inside the "it" block. This solves the problem for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top