【发布时间】:2014-03-13 05:31:23
【问题描述】:
这里是视图:
<!-- 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/' %>
之前我也遇到过类似的问题,这与测试访问错误的链接有关。我在主页上使用了检查来确保标题确实存在,即使我的测试失败了。
这是测试:
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
这是错误:
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
【问题讨论】:
标签: ruby-on-rails rspec railstutorial.org