0

私はいくつかのテストを行おうとしていますが、パスにアクセスしてコンテンツがあるかどうかをテストしようとすると明らかに問題があります。私のビューの賞品/index.html.erbには、実際にこれが含まれています:

大賞

それでうまくいくはずです。

Prizes_controller_spec.rb

require 'spec_helper'
require 'pp'

describe PrizesController do
  subject {page}
  describe "Index" do
    describe "Test" do
      before do
        visit prizes_path
      end

      it { should have_selector('h2', text: 'Grand Prizes') }
    end   
  end
end

賞品/index.html.erb

    <h2>Grand Prizes</h2>
    <%= form_for :prize, :url => update_all_path, :html => { :method => :put }     do %>
    <table>
        <tr>
            <th>Item name</th>
            <th>Price ($)</th>
            <th>Pairs</th>
        </tr>

        <% @prizes_non_consolation.each do |prize| %>
        <%= fields_for "prize[]", prize do |prize_fields| %>
        <tr>
            <td><%= prize_fields.text_field :name %></td>
            <td><%= prize_fields.number_field :price %></td>
            <td><%= prize_fields.number_field :slot %></td>

            <td><%= link_to "Delete", prize, method: :delete,
            data: { confirm: "You sure?" } %></td>
        </tr>
        <% end %>
        <% end %>

    </table>

    <h2>Consolations Prizes</h2>
    <table>
        <tr>
            <th>Item name</th>
        </tr>
        <% @prizes_consolation.each do |prize| %>
        <%= fields_for "prize[]", prize do |prize_fields| %>
        <tr>
            <td><%= prize_fields.text_field :name %></td>

            <td><%= link_to "Delete", prize, method: :delete,
            data: { confirm: "You sure?" } %></td>
        </tr>
        <% end %>

        <% end %>
    </table>

    <div class="actions">
        <%= submit_tag "Save", class: "admin_save_button" %>
    </div>
    <% end %>
    <%= link_to "Add a new prize", new_prize_path %>

Prizes_controller.rb

class PrizesController < ApplicationController
  def index
    @prizes_consolation = Prize.consolation
    @prizes_non_consolation = Prize.non_consolation
  end

失敗メッセージ:

1) PrizesController Index Test should have css "h2" with text "Grand Prizes"
   Failure/Error: it { should have_selector('h2',    text: 'Grand Prizes') }
   Capybara::ExpectationNotMet:
     expected to find css "h2" with text "Grand Prizes" but there were no matches
   # ./spec/controllers/prizes_controller_spec.rb:11:in `block (4 levels) in <top (required)>'

Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.13'

gem 'pg'

gem 'thin'
gem 'coveralls', require: false

group :development, :test do

  gem 'rspec-rails', '~> 2.14.0'
  gem 'spork'
  gem 'capybara'

  gem 'simplecov'

  gem 'rb-fsevent'
  gem 'guard-bundler'
  gem 'guard-rspec'
  gem 'guard-spork'

  gem "factory_girl_rails", "~> 4.0"

end

group :darwin do
  gem 'rb-fsevent', :require => false
end

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

gem 'jquery-rails'
4

1 に答える 1