2012-05-09 16 views
1

RoRチュートリアルのコードをテストする際にエラーが発生しました。 Gemfileの仕様のバージョンが間違っている可能性があります。RoRチュートリアルを作成中にRSpecエラーが発生しました

障害:

1) PagesController GET 'home' should have the right title 
    Failure/Error: response.should have_selector("title", :content => "Home") 
    NoMethodError: 
     undefined method `has_selector?' for #<ActionController::TestResponse:0x007fb3d4d2d108> 
    # ./spec/controllers/pages_controller_spec.rb:14:in `block (3 levels) in <top (required)>' 

    2) PagesController GET 'contact' should have the right title 
    Failure/Error: response.should have_selector("title", :content => "Contact") 
    NoMethodError: 
     undefined method `has_selector?' for #<ActionController::TestResponse:0x007fb3d280b370> 
    # ./spec/controllers/pages_controller_spec.rb:26:in `block (3 levels) in <top (required)>' 

    3) PagesController GET 'about' should have the right title 
    Failure/Error: response.should have_selector("title", :content => "About") 
    NoMethodError: 
     undefined method `has_selector?' for #<ActionController::TestResponse:0x007fb3d2b96e90> 
    # ./spec/controllers/pages_controller_spec.rb:38:in `block (3 levels) in <top (required)>' 

    4) PagesController GET 'help' should have the right title 
    Failure/Error: response.should have_selector("title", :content => "Help") 
    NoMethodError: 
     undefined method `has_selector?' for #<ActionController::TestResponse:0x007fb3d28a19d8> 
    # ./spec/controllers/pages_controller_spec.rb:50:in `block (3 levels) in <top (required)>' 

Finished in 0.1005 seconds 
8 examples, 4 failures 

Failed examples: 

rspec ./spec/controllers/pages_controller_spec.rb:12 # PagesController GET 'home' should have the right title 
rspec ./spec/controllers/pages_controller_spec.rb:24 # PagesController GET 'contact' should have the right title 
rspec ./spec/controllers/pages_controller_spec.rb:36 # PagesController GET 'about' should have the right title 
rspec ./spec/controllers/pages_controller_spec.rb:48 # PagesController GET 'help' should have the right title 

Gemfile:

source 'https://rubygems.org' 

gem 'rails', '3.2.3' 

gem 'sqlite3' 

group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 
    gem 'uglifier', '>= 1.0.3' 
end 

gem 'jquery-rails' 

group :test, :development do 
    gem "rspec-rails", "~> 2.10.1" 
end 

pages_controller_spec.rbリスト:

require 'spec_helper' 

describe PagesController do 
    render_views 

    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 => "Home") 
    end 
    end 

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

    it "should have the right title" do 
     get 'contact' 
     response.should have_selector("title", :content => "Contact") 
    end 
    end 

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

    it "should have the right title" do 
     get 'about' 
     response.should have_selector("title", :content => "About") 
    end 
    end 

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

    it "should have the right title" do 
     get 'help' 
     response.should have_selector("title", :content => "Help") 
    end 
    end 
end 

私が間違って何understangません。

+0

を入力します。これを見てください:http://stackoverflow.com/questions/5388638/broken-controller-tests-after-installing-capybara –

答えて

1

あなたがwebratを使用しない場合、あなたは

response.body.should include 'Contact</h1>' 

むしろより少し小さいクリーンである

response.should have_selector("title", :content => "Contact") 

を使用することができ、私は同意するものとします。

0

あなたGEMFILEを再編集し、webrat方法です

gem 'webrat' 

、その後

タイプ

bundle install 
関連する問題