-1

私は今、Hartl のチュートリアル Ch.8 にいます。正常に動作するサインイン/サインアウト機能の作成が完了しましたが、テストは常に失敗します。解決策が見つかりません。

Failures:

  1) Authentication signin with valid information
     Failure/Error: it { should have_link('Profile',  href: user_path(user)) }
     NoMethodError:
       undefined method `has_link?' for #<ActionDispatch::TestResponse:0x5175738
>
     # ./spec/requests/authentication_pages_spec.rb:39:in `block (4 levels) in <
top (required)>'

  2) Authentication signin with valid information
     Failure/Error: it { should have_link('Sign out',   href: signout_path) }
     NoMethodError:
       undefined method `has_link?' for #<ActionDispatch::TestResponse:0x5395338
>
     # ./spec/requests/authentication_pages_spec.rb:40:in `block (4 levels) in <
top (required)>'

  3) Authentication signin with valid information
     Failure/Error: it { should_not have_link('Sign in', href: signin_path) }
     NoMethodError:
       undefined method `has_link?' for #<ActionDispatch::TestResponse:0x56d6870
>
     # ./spec/requests/authentication_pages_spec.rb:41:in `block (4 levels) in <
top (required)>'

  4) Authentication signin with valid information followed by signout
     Failure/Error: before { click_link "Sign out" }
     ActionController::RoutingError:
       No route matches [GET] "/signout"
     # ./spec/requests/authentication_pages_spec.rb:44:in `block (5 levels) in <
top (required)>'

  5) UserPages signup page with valid information after saving the user
     Failure/Error: it { should have_link('Sign out',   href: signout_path) }
     NoMethodError:
       undefined method `has_link?' for #<ActionDispatch::TestResponse:0x53fb830
>
     # ./spec/requests/user_pages_spec.rb:50:in `block (5 levels) in <top (requi
red)>'

そしていくつかの追加情報:

ルート.rb

resources :users   
resources :sessions, only: [:new, :create, :destroy]

match '/contact', :to => 'pages#contact'

match '/about',   :to => 'pages#about'  

match '/help',    :to => 'pages#help'

match '/signup',  :to => 'users#new'  

match '/signin',  :to => 'sessions#new' 

match '/signout', :to => 'sessions#destroy', :via => :delete

root :to => 'pages#home'

コードをテストする

require 'spec_helper'

describe "Authentication" do

  subject { response }

  describe "signin page" do
    before { visit signin_path }

    it { should have_selector('h1',    content: 'Sign in') }
    it { should have_selector('title', content: 'Sign in') }
  end

  describe "signin" do
    before { visit signin_path }

    describe "with invalid information" do
      before { click_button "Sign in" }

      it { should have_selector('title', content: 'Sign in') }
      it { should have_selector('div.alert.alert-error', content: 'Invalid') }

      describe "after visiting another page" do
        before { click_link "Home" }
        it { should_not have_selector('div.alert.alert-error') }
      end
    end


  describe "with valid information" do
      let(:user) { FactoryGirl.create(:user) }
      before do
        fill_in "Email",    with: user.email.upcase
        fill_in "Password", with: user.password
        click_button "Sign in"
      end

      it { should have_selector('title',    content: user.name) }
      it { should have_link('Profile',      href: user_path(user)) }
      it { should have_link('Sign out',     href: signout_path) }
      it { should_not have_link('Sign in',  href: signin_path) }

      describe "followed by signout" do
        before { click_link "Sign out" }
        it { should have_link('Sign in') }
      end

    end


  end
end

ヘッダー html

<ul class="nav no-margin">
    <li><%= link_to "Home", root_path %></li>
    <li><%= link_to "Help", help_path %></li>
    <% if signed_in? %>
    <li><%= link_to "Users", '#' %></li>
    <li id="fat-menu" class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">
        Account <b class="caret"></b>
      </a>
     <ul class="dropdown-menu">
    <li><%= link_to "Profile", current_user %></li>
    <li><%= link_to "Settings", '#' %></li>
    <li class="divider"></li>
    <li>
      <%= link_to "Sign out", signout_path, method: "delete" %>
    </li>
     </ul>
    </li>
     <% else %>
    <li><%= link_to "Sign in", signin_path %></li>
     <% end %>
      <li><%= link_to "Sign up now!", signup_path, :class => "signup_button" %></li>
</ul>

私のGemfile

source 'https://rubygems.org'

gem 'rails', '3.2.1'

gem 'sqlite3', :group => [:development, :test]
group :production do
  gem 'thin'
  gem 'pg'
end

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
  gem 'bootstrap-sass-rails'
  gem 'bcrypt-ruby', '3.0.1'

  gem 'uglifier', '>= 1.0.3'
end

group :development do
  gem 'rspec-rails', '2.6.1'
  gem 'annotate', '~> 2.4.1.beta' 
end

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'webrat', '0.7.1'
  gem 'spork', '0.9.0.rc8'
  gem 'ZenTest', '4.8.3'
  gem 'capybara', '~> 2.1.0'
  gem 'factory_girl_rails', '4.1.0'
end


gem 'jquery-rails'

あなたが私を助けてくれることを願っています。ありがとう。

4

2 に答える 2