0

我将慢慢学习 Michael Hartl 的优秀 Ruby on Rails 教程。一切进展顺利……直到第 5 章的练习。现在我很困。在实际练习部分中详细进行了更改后,我的 RSpec 测试现在失败了。

  • 请注意,我正在运行 SPORK(但当我不使用 SPORK 时,测试也会失败)。

这是我从每个测试的静态页面获得的输出示例:

静态页面主页它应该表现得像所有静态页面失败/错误:它{应该有_选择器('title',文本:full_title(page_title))}类型错误:无法将RSpec::Matchers::BuiltIn::Include转换为字符串共享示例组:“所有静态页面”调用自 ./spec/requests/static_pages_spec.rb:19 # (eval):2:in has_selector?' # ./spec/requests/static_pages_spec.rb:9:inblock (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
4

1 回答 1

1

感谢那些试图帮助我的人。

最终我解决了它 - 发现我不小心在utilities.rb中留下了一些冗余代码

到第 5 章结束时,该文件中唯一应该包含的行是:

include ApplicationHelper

巴扎

于 2013-05-28T07:30:31.707 回答