我正在慢慢努力通过Michael Hartl出色的Ruby on Rails教程。 一切都很顺利..直到第五章的练习。现在我很困难。 在实际练习部分中进行了详细的更改后,我的RSpec测试现在失败了。Rspec测试现在失败 - 陷入第5章 - Hartl的Ruby on Rails教程
- 请注意,我正在运行SPORK(但当我不使用SPORK时,测试也失败)。
下面是输出,我从每个测试的静态页面得到的一个例子:
Static pages Home page it should behave like all static pages Failure/Error: it { should have_selector('title', text: full_title(page_title)) } TypeError: can't convert RSpec::Matchers::BuiltIn::Include to String Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:19 # (eval):2:in
has_selector?' # ./spec/requests/static_pages_spec.rb:9:in
block (3 levels) in '
这里是static_pages_spec.rb:
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_selector('title', text: full_title(page_title)) }
end
describe "Home page" do
before { visit root_path }
before { visit root_path }
let(:heading) { 'Sample App' }
let(:page_title) { '' }
it_should_behave_like "all static pages"
it { should_not have_selector 'title', text: '| Home' }
end
describe "Help page" do
before { visit root_path }
before { visit root_path }
let(:heading) { 'Sample App' }
let(:page_title) { '' }
it_should_behave_like "all static pages"
it { should_not have_selector 'title', text: '| Help' }
end
describe "About page" do
before { visit root_path }
let(:heading) { 'Sample App' }
let(:page_title) { '' }
it_should_behave_like "all static pages"
it { should_not have_selector 'title', text: '| About' }
end
describe "Contact page" do
before { visit root_path }
let(:heading) { 'Sample App' }
let(:page_title) { '' }
it_should_behave_like "all static pages"
it { should_not have_selector 'title', text: '| Contact' }
end
这可能是有益的,看看static_pages_spec.rb。你可以发布吗? –
你的full_title函数是否返回一个String? 在rails控制台中,试试这个: helper.full_title(“test”)。class –
Hi Sam,posted static_pages_spec.rb –