0
votes

I'l slowly working my way through Michael Hartl's excellent Ruby on Rails Tutorial. All was going very well.. until the exercises in Chapter 5 that is. Now I'm very stuck. After making changes detailed in the actual exercises section, my RSpec tests are now failing.

  • Note that I am running SPORK (but that tests also fail when I am not using SPORK).

Here is an example of the output I get from each static page tested :

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:inblock (3 levels) in '

Here is 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
1
It might be helpful to see static_pages_spec.rb. Can you post that?Sam Backus
Is your full_title function returning a String? In the rails console, try this: helper.full_title("test").classSam Backus
Hi Sam, posted static_pages_spec.rbBazza Formez
Hi Sam. I couldn't seemto run that command in Konsole, ie. helper.full_title("test").class I ran it from the root for the project ...and get message : bash: syntax error near unexpected token `"test"'Bazza Formez
@BazzaFormez what Sam meant is that you should start a rails console (with that exact command) and then try full_title('test')alf

1 Answers

1
votes

Thank you to those who kindly tried to help me.

Eventually I solved it - found that I had accidentally left some redundant code in utilities.rb

The only line that should be in that file by the end of chapter 5 is :

include ApplicationHelper

Bazza