开发者

Railstutorial.org - Integration Test breaking on webrat visit root_path

I'm working through the rails tutorial at railstutorial.org.

Specifically the video.

After a bumpy start with various gem versions - things were working well. That is until I hit the 'integration test' section. (NOTE: Section 5.5 / listing 5.33 in the web tutorial)

As instructed in the video I added this t开发者_Python百科o layout_links_spec.rb

it "should have the right links on the layout" do 
   visit root_path
   response.should have_selector('title', :content => "Home")
end

When I run the 'rspec spec/' - I get this error

Failure/Error: response.should have_selector('title', :content => 'Home') 
expected following output to contain a <title>Home</title> tag: 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"

Before adding this last spec - all my rspec tests worked - aka I was 'green'.

My current Gemfile contains

group :development do
  gem 'rspec-rails', '2.3.0'
end

group :test do
  gem 'rspec', '2.3.0'
  gem 'webrat', '0.7.1'
  gem 'spork', '0.8.4'
end

As recommended by the railstutorial site -> http://railstutorial.org/chapters/updating-showing-and-deleting-users#code:final_gemfile

Any help would be extremely appreciated. I really want to embrace to BDD / TDD - but these gem 'issues' are really frustrating.

Thanks Dave


All you need to do is add a line at the top of your spec to render the views (otherwise RSpec does not have the complete html response to work with).

require 'spec_helper'

describe PagesController do
  render_views                    # <--- This is the line you need to add!

  describe "GET 'home'" do
    it "should be successful" do
      get 'home'
      response.should be_success
    end

    it "should have the right title" do
      get 'home'
      response.should have_selector("title",
                        :content => "Ruby on Rails Tutorial Sample App | Home")
    end
  end
end

Here is where Michael Hartl introduces the idea in the Ruby on Rails Tutorial book:

http://railstutorial.org/chapters/static-pages#code:pages_controller_spec_title

"Note that the render_views line...is necessary for the title tests to work."

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜