Rspec errors in Ruby 1.8.7 - ruby-on-rails

I have been trying to do bundle exec rspec spec/requests/static_pages_spec.rb but everytime I try to do it I get these 9 errors:
no DRb server is running. Running in local process instead ...
FFFFFFFFF
Failures:
1) Static pages Home page should have the h1 'Sample App'
Failure/Error: visit root_path
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x1047a1cc8>
# ./spec/requests/static_pages_spec.rb:8
2) Static pages Home page should have the base title
Failure/Error: visit root_path
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x1047858e8>
# ./spec/requests/static_pages_spec.rb:13
3) Static pages Home page should not have a custom page title
Failure/Error: visit root_path
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x10477f448>
# ./spec/requests/static_pages_spec.rb:18
4) Static pages Help page should have the h1 'Help'
Failure/Error: visit help_path
ActionView::Template::Error:
undefined method `full_title' for #<#<Class:0x1069a3e98>:0x1069a0bf8>
# ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb___963741010_2202798760'
# ./spec/requests/static_pages_spec.rb:26
5) Static pages Help page should have the title 'Help'
Failure/Error: visit help_path
ActionView::Template::Error:
undefined method `full_title' for #<#<Class:0x1069a3e98>:0x10692e508>
# ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb___963741010_2202798760'
# ./spec/requests/static_pages_spec.rb:31
6) Static pages About page should have the h1 'About Us'
Failure/Error: visit about_path
ActionView::Template::Error:
undefined method `full_title' for #<#<Class:0x1069a3e98>:0x1068fb928>
# ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb___963741010_2202798760'
# ./spec/requests/static_pages_spec.rb:39
7) Static pages About page should have the title 'About Us'
Failure/Error: visit about_path
ActionView::Template::Error:
undefined method `full_title' for #<#<Class:0x1069a3e98>:0x1068bc3e0>
# ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb___963741010_2202798760'
# ./spec/requests/static_pages_spec.rb:44
8) Static pages Contact page should have the content 'Contact'
Failure/Error: visit contact_path
ActionView::Template::Error:
undefined method `full_title' for #<#<Class:0x1069a3e98>:0x106b095a8>
# ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb___963741010_2202798760'
# ./spec/requests/static_pages_spec.rb:52
9) Static pages Contact page should have the title 'Contact'
Failure/Error: visit contact_path
ActionView::Template::Error:
undefined method `full_title' for #<#<Class:0x1069a3e98>:0x106abb740>
# ./app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb___963741010_2202798760'
# ./spec/requests/static_pages_spec.rb:57
I have restarted the spork server and removed the public/index.html file and I still get the errors. Here are the results of my rake routes:
static_pages_home /static_pages/home(.:format) static_pages#home
help GET /help(.:format) static_pages#help
about GET /about(.:format) static_pages#about
contact GET /contact(.:format) static_pages#contact
GET /static_pages/home(.:format) static_pages#home
static_pages_help GET /static_pages/help(.:format) static_pages#help
static_pages_about GET /static_pages/about(.:format) static_pages#about
static_pages_contact GET /static_pages/contact(.:format) static_pages#contact

The root_path errors are because you don't have a "root" route defined. You would need to share your code to analyze the reason for the full_title not being defined. If you're following Hartl's tutorial, you might want to add a tag for that.

Related

undefined local variable or method `new_password_reset'

describe "PasswordResets" do
before(:each) do
visit new_password_reset
end
it "should contain the title" do
page.should have_selector("title", text: "Password reset")
end
end
Failure/Error: visit new_password_reset
NameError:
undefined local variable or method `new_password_reset' for #
When i do a rake routes in my terminal, i get the below.
new_password_reset GET /password_resets/new(.:format) password_resets#new
Why i am getting a undefined local variable when i run my tests though the route is present.
either specify the path directly like
visit '/password-reset'
or
specify the path method which is 'new_password_reset_path' and NOT JUST 'new_password_reset'
visit new_password_reset_path

RoR and Rspec setting up a test using a while loop

Ok so I want to create a test for checking that all pages have a certain title. However I thought it would be nice if I could include the page titles in an array so that I wouldn't have to duplicate the block for each page. And it would allow me to test additional pages by just modifying the pages array.
The issue I am having is that the page variable is not being interpolated in the test. So is this a syntax error or does Rspec not allow interpolation within the it should do... block?
describe "LayoutLinks" do
page = ["home", "contact", "about", "help"]
i = page.count
x = 0
while x < i
it "should have a #{page[x]} page" do
get "#{page[x]}"
response.should have_selector("title", :content => "#{page[x]}")
end
x += 1
end
end
Test shows the following failures:
1) PagesController LayoutLinks should have a help page
Failure/Error: get "#{page[x]}"
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>""}
# ./spec/controllers/layout_links_spec.rb:14:in `block (3 levels) in <top (required)>'
2) PagesController LayoutLinks should have a contact page
Failure/Error: get "#{page[x]}"
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>""}
# ./spec/controllers/layout_links_spec.rb:14:in `block (3 levels) in <top (required)>'
3) PagesController LayoutLinks should have a about page
Failure/Error: get "#{page[x]}"
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>""}
# ./spec/controllers/layout_links_spec.rb:14:in `block (3 levels) in <top (required)>'
4) PagesController LayoutLinks should have a home page
Failure/Error: get "#{page[x]}"
ActionController::RoutingError:
No route matches {:controller=>"pages", :action=>""}
Failure error here is obvious. It shouldn't say get "#{page[x]}" but rather it should be get home and get about, etc...
How do I remedy? Thanks for the help. Much appreciated :)
Try the following:
describe "LayoutLinks" do
%w(home contact about help).each do |page|
it "should have a #{page} page" do
get page
response.should have_selector("title", content: page)
end
end
end
%w creates an array of strings (spaces become commas, so you get ["home", "contact", etc])

Hartl RoR 3.3.2 Passing Title Test

Trying to get my title test to pass and see this error when running:
bundle exec rspec spec/requests/static_pages_spec.rb
Failures:
1) Static pages Help page should have the h1 'Help'
Failure/Error: visit '/static_pages/Help'
ActionController::RoutingError:
No route matches [GET] "/static_pages/Help"
# ./spec/requests/static_pages_spec.rb:19:in `block (3 levels) in <top (required)>'
2) Static pages Help page should have the title 'Help'
Failure/Error: visit '/static_pages/Help'
ActionController::RoutingError:
No route matches [GET] "/static_pages/Help"
# ./spec/requests/static_pages_spec.rb:24:in `block (3 levels) in <top (required)>'
3) Static pages About page should have the h1 'About Us'
Failure/Error: visit '/static_pages/About'
ActionController::RoutingError:
No route matches [GET] "/static_pages/About"
# ./spec/requests/static_pages_spec.rb:31:in `block (3 levels) in <top (required)>'
4) Static pages About page should have the title 'About Us'
Failure/Error: visit '/static_pages/About'
ActionController::RoutingError:
No route matches [GET] "/static_pages/About"
# ./spec/requests/static_pages_spec.rb:36:in `block (3 levels) in <top (required)>'
Finished in 0.16042 seconds
6 examples, 4 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:18 # Static pages Help page should have the h1 'Help'
rspec ./spec/requests/static_pages_spec.rb:23 # Static pages Help page should have the title 'Help'
rspec ./spec/requests/static_pages_spec.rb:30 # Static pages About page should have the h1 'About Us'
rspec ./spec/requests/static_pages_spec.rb:35 # Static pages About page should have the title 'About Us'
SampleApp::Application.routes.draw do
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
I've tried various answers already posted in other threads and haven't been successful. Any help would be much appreciated.
Your URLs should be '/static_pages/help' instead of '/static_pages/Help'.

Hartl's Tutorial - Chapter 5.3 Layout Links

ok ... sort of have been dithering on posting this question but here goes:
it's actually lot like this question.
my spec tests fail too ... but i'm not too concerned about that b/c it just involves the title for all pages... (which i can easily fix)
what i'm really wondering about are the routes issue.
after following all of hartl's directions in section 5.3.2 rail routes, this is what i get:
No route matches [GET] "/static_pages/about"
No route matches [GET] "/static_pages/home"
No route matches [GET] "/static_pages/help"
No route matches [GET] "/static_pages/contact"
config/routes.rb settings
SampleApp::Application.routes.draw do
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
I can fix three of the pages above by prefixing the '/help,' '/about,' and '/contact' with 'static_pages' ...
it still doesn't solve the home page problem.
adding this to spec_helper.rb didn't help (from the link)
config.include Rails.application.routes.url_helpers
what am i missing here, and what other information do i need to add to make the question clearer?
tests are done by this statement: bundle exec rspec spec/requests/static_pages_spec.rb
here is the terminal out after running the statement
Failures:
1) Static pages About page should have the h1 'About Us'
Failure/Error: visit '/static_pages/about'
ActionController::RoutingError:
No route matches [GET] "/static_pages/about"
# ./spec/requests/static_pages_spec.rb:46:in `block (3 levels) in <top (required)>'
2) Static pages About page should not have a custom page title
Failure/Error: visit '/static_pages/about'
ActionController::RoutingError:
No route matches [GET] "/static_pages/about"
# ./spec/requests/static_pages_spec.rb:57:in `block (3 levels) in <top (required)>'
3) Static pages About page should have the base title
Failure/Error: visit '/static_pages/about'
ActionController::RoutingError:
No route matches [GET] "/static_pages/about"
# ./spec/requests/static_pages_spec.rb:51:in `block (3 levels) in <top (required)>'
4) Static pages Home page should have the h1 'Sample App'
Failure/Error: visit '/static_pages/home'
ActionController::RoutingError:
No route matches [GET] "/static_pages/home"
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
5) Static pages Home page should not have a custom page title
Failure/Error: visit '/static_pages/home'
ActionController::RoutingError:
No route matches [GET] "/static_pages/home"
# ./spec/requests/static_pages_spec.rb:19:in `block (3 levels) in <top (required)>'
6) Static pages Home page should have the base title
Failure/Error: visit '/static_pages/home'
ActionController::RoutingError:
No route matches [GET] "/static_pages/home"
# ./spec/requests/static_pages_spec.rb:13:in `block (3 levels) in <top (required)>'
7) Static pages Help page should have the h1 'Help'
Failure/Error: visit '/static_pages/help'
ActionController::RoutingError:
No route matches [GET] "/static_pages/help"
# ./spec/requests/static_pages_spec.rb:27:in `block (3 levels) in <top (required)>'
8) Static pages Help page should not have a custom page title
Failure/Error: visit '/static_pages/help'
ActionController::RoutingError:
No route matches [GET] "/static_pages/help"
# ./spec/requests/static_pages_spec.rb:38:in `block (3 levels) in <top (required)>'
9) Static pages Help page should have the base title
Failure/Error: visit '/static_pages/help'
ActionController::RoutingError:
No route matches [GET] "/static_pages/help"
# ./spec/requests/static_pages_spec.rb:32:in `block (3 levels) in <top (required)>'
10) Static pages Contact page should have the h1 'Contact'
Failure/Error: visit '/static_pages/contact'
ActionController::RoutingError:
No route matches [GET] "/static_pages/contact"
# ./spec/requests/static_pages_spec.rb:65:in `block (3 levels) in <top (required)>'
11) Static pages Contact page should have the title 'Contact'
Failure/Error: visit '/static_pages/contact'
ActionController::RoutingError:
No route matches [GET] "/static_pages/contact"
# ./spec/requests/static_pages_spec.rb:70:in `block (3 levels) in <top (required)>'
Finished in 0.14305 seconds
11 examples, 11 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:45 # Static pages About page should have the h1 'About Us'
rspec ./spec/requests/static_pages_spec.rb:56 # Static pages About page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:50 # Static pages About page should have the base title
rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the h1 'Sample App'
rspec ./spec/requests/static_pages_spec.rb:18 # Static pages Home page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the base title
rspec ./spec/requests/static_pages_spec.rb:26 # Static pages Help page should have the h1 'Help'
rspec ./spec/requests/static_pages_spec.rb:37 # Static pages Help page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:31 # Static pages Help page should have the base title
rspec ./spec/requests/static_pages_spec.rb:64 # Static pages Contact page should have the h1 'Contact'
rspec ./spec/requests/static_pages_spec.rb:69 # Static pages Contact page should have the title 'Contact'
Although you have a root mapping, which routes '/' requests to StaticPagesController home action, you have no mapping for the route static_pages/home. To add it:
match 'static_pages/home', to: 'static_pages#home'
You might have be using the Rails 4 version of the Hartl book while using an older version of Rails on your computer. Try the Rails 3.2 version of the Hartl book: http://ruby.railstutorial.org/chapters/filling-in-the-layout?version=3.2#sec-rails_routes

Rspec no route matches

I'm getting the following error with rspec:
1) LandingController landing#index returns http success
Failure/Error: get :index
ActionController::RoutingError:
No route matches {:controller=>"landing"}
# ./spec/controllers/landing_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
This is the test
require 'spec_helper'
describe LandingController do
describe "landing#index" do
it "returns http success" do
get :index
response.should be_success
end
end
end
I mounted it as root :to => 'landing#index'. All other tests are passing, only this one is failing, can someone help me to understand why?
For completeness this is the output from rake routes
root / landing#index
auth_google_oauth2_callback /auth/google_oauth2/callback(.:format) sessions#create
signout /signout(.:format) sessions#destroy
dashboard /dashboard(.:format) dashboard#index
If you are using Spork you may need to restart the server if you updated routes.
did you try to access the root page with get '/'? should work.

Resources