I keep getting the same two failures for a test trying to create a signin page.
Here is the error message: $ bundle exec rspec spec/requests/user_pages_spec.rb
FF
Failures:
1) User pages signup page
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
undefined method |' for "Ruby on Rails Tutorial Sample App":Stringfull_title’
# ./app/helpers/application_helper.rb:9:in
# ./app/views/layouts/application.html.erb:4:in _app_views_layouts_application_html_erb__2148911516627374684_2168968760'block (3 levels) in ‘
# ./spec/requests/user_pages_spec.rb:8:in
2) User pages signup page
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
undefined method |' for "Ruby on Rails Tutorial Sample App":Stringfull_title’
# ./app/helpers/application_helper.rb:9:in
# ./app/views/layouts/application.html.erb:4:in _app_views_layouts_application_html_erb__2148911516627374684_2168968760'block (3 levels) in ‘
# ./spec/requests/user_pages_spec.rb:8:in
Finished in 0.17668 seconds
2 examples, 2 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:10 # User pages signup page
rspec ./spec/requests/user_pages_spec.rb:11 # User pages signup page
And here is the file user_pages_spec.rb
require ‘spec_helper’
describe “User pages” do
subject { page }
describe “signup page” do
before { visit signup_path }
it { should have_selector('h1', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }
end
end
here is the file application_helper.rb:
module ApplicationHelper
# Returns the full title on a per-page basis.
def full_title(page_title)
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
"#{base_title}" | "#{page_title}"
end
end
end
here is the file routes.rb
SampleApp::Application.routes.draw do
get “users/new”
root to: 'static_pages#home'
match '/signup', to: 'users#new'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
I’ve been stuck on this for quite a bit so any help would be greatly appreciated!
Thanks!
The rails error messages it gives you here are pretty descriptive.
If we look at the line
It’s telling us it can’t find a method called
|for the String"Ruby on Rails Tutorial Sample App"on line 9 of application_helper.rb in thefull_titlemethod definition. If we got to that line we can seeWhich ruby interprets as “run the method | on the result of “#{base_title}” (which in this case evaluates to the String “Ruby on Rails Tutorial Sample App”) with the argument “#{page_title}”. Since Strings don’t have a ‘|’ method, it returns an “undefined method” error.
To fix, just change the line to