문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top