문제

Here is the view:

<!-- Only have to provide what is not provided in the layout. 
    The layour is the skeleton. --!>
<div class="center hero-unit">
    <h1>Sample App</h1>

    <h2>
    This is the home page for 
    <%= link_to "Ruby on Rails Tutorial", 'http://railstutorial.org/' %>
    sample application! 
    </h2>

    <%= link_to "Sign up now!", signup_path, class: "btn btn-large btn-primary" %>
</div>

<%= link_to image_tag("rails.png", alt: "Rails"), 'http://railstutorial.org/' %>

I had a similar problem before that had to do with the test visiting the wrong link. I used inspect on the home page to make sure that the heading really was there, even though my tests fail.

Here is the test:

require 'spec_helper'

describe "Static pages" do

  subject { page }

  shared_examples_for "all static pages" do
    it { should have_selector('h1', text: heading) }
    it { should have_title(full_title(page_title)) }
  end

  describe "Home page" do
    before { visit root_path }
    let(:heading)    { 'Sample App' }
    let(:page_title) { '' }

    it_should_behave_like "all static pages"
    it { should_not have_title('| Home') }
  end
end

Here is the error:

Failures:

  1) Static pages Home page it should behave like all static pages 
     Failure/Error: it { should have_selector('h1', text: heading) }
       expected #has_selector?("h1", {:text=>"Sample App"}) to return true, got false
     Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:17
     # ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'

Finished in 0.44614 seconds
30 examples, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:8 # Static pages Home page it should behave like all static pages 
도움이 되었습니까?

해결책

The problem is here

<!-- Only have to provide what is not provided in the layout. 
    The layour is the skeleton. --!>

This is not correct comment syntax for HTML. Closing comment tag should be --> and not --!>. Use the following.

<!-- Only have to provide what is not provided in the layout. 
    The layour is the skeleton. -->

Your tests are failing because your HTML comments are not terminated and therefore your H1 is missing.

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