0
votes

Going through Hartl's Rails tutorial and on Chapter 5.4.2 I am not able to get a certain test to pass.

Here is the error:

 1) UserPages GET /user_pages works! (now write some real specs)
     Failure/Error: get user_pages_index_path
     NameError:
       undefined local variable or method `user_pages_index_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f9106e2cce8>
     # ./spec/requests/user_pages_spec.rb:7:in `block (3 levels) in <top (required)>'

Here is the test in user_pages_spec.rb:

require 'spec_helper'

    describe "UserPages" do
      describe "GET /user_pages" do
        it "works! (now write some real specs)" do
          # Run the generator again with the 
          #  --webrat flag if you want to use webrat methods/matchers

          get user_pages_index_path
          response.status.should be(200)
        end
      end
    end

Here is the routes file:

get "users/new"
root  'static_pages#home'
match '/signup',  to: 'users#new',            via: 'get'
match '/help',    to: 'static_pages#help',    via: 'get'
match '/about',   to: 'static_pages#about',   via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
match 'static_pages/home',    to: 'static_pages#home', via: 'get'

Any input is appreciated


Sorry about the formatting. In the very beginning of that section is a spec file: spec/requests/user_pages_spec.rb

require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "signup page" do
    before { visit signup_path }

    it { should have_content('Sign up') }
    it { should have_title(full_title('Sign up')) }
  end
end

and I am getting the following error:

Failure/Error: get user_pages_index_path NameError: undefined local variable or method `user_pages_index_path' for #

Here is the rake routes output:

       Prefix Verb URI Pattern                  Controller#Action
    users_new GET /users/new(.:format)         users#new
         root GET /                            static_pages#home
       signup GET /signup(.:format)            users#new
         help GET /help(.:format)              static_pages#help
        about GET /about(.:format)             static_pages#about
      contact GET /contact(.:format)           static_pages#contact

static_pages_home GET /static_pages/home(.:format) static_pages#home

2
I don't get it. The test in the section 5.4.2 Signup URL of M. Hartl tutorial is different. What are you trying to do? Also can you please format the code in your question. Is hard to read this way. - Marek Takac
Sorry about the formatting. In the very beginning of that section is a spec file: spec/requests/user_pages_spec.rb - user2623706
Please, run 'rake routes' in your terminal. What is the output? - Marek Takac
Just added it. Thanks! - user2623706

2 Answers

0
votes

Just remove the contents at "user_pages_spec.rb" cause there is no such method called user_pages_index_path

so, here is what it should be

user_pages_spec.rb

require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "signup page" do
    before { visit signup_path }

    it { should have_content('Sign up') }
    it { should have_title(full_title('Sign up')) }
  end
end

Also, At /config/routes.rb file

SampleApp::Application.routes.draw do
  get "users/new"

  root  'static_pages#home'
  match '/signup',  to: 'users#new',            via: 'get'
  match '/help',    to: 'static_pages#help',    via: 'get'
  match '/about',   to: 'static_pages#about',   via: 'get'
  match '/contact', to: 'static_pages#contact', via: 'get'
  .
  .
  .
end
0
votes

I was having same issue and I just commented out the "user_pages_spec.rb" file. When I did that I passed all the tests. Is this the correct answer, I don't know but as I stated it allows for the tests to pass.