Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Failure/Error: before { visit signup_path } NameError: undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup


  • Please log in to reply
3 replies to this topic

#1 ExNihil

ExNihil

    Passenger

  • Members
  • 7 posts

Posted 07 October 2013 - 06:08 AM

I'm currently working through chapter seven of Rails Tutorial and seem to be stuck at figure 7.22. In brief, I'm unable to get the tests to pass. When I run . . .
 
    bundle exec rspec spec/requests/user_pages_spec.rb
 
. . . I see a bunch of failed tests that read:
 
     Failures:
 
    1) User pages signup page 
        Failure/Error: before { visit signup_path }
        NameError:
        undefined local variable or method `signup_path' for # <RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fb2be028410>
     # ./user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
 
  2) User pages signup page 
     Failure/Error: before { visit signup_path }
     NameError:
       undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fb2be048ad0>
     # ./user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
 
  3) User pages signup page with invalid information should not create a user
     Failure/Error: before { visit signup_path }
     NameError:
       undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x007fb2be062e80>
     # ./user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
 
  4) User pages signup page with valid information should create a user
     Failure/Error: before { visit signup_path }
     NameError:
       undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_2:0x007fb2be083158>
     # ./user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
 
    Finished in 0.00374 seconds
    4 examples, 4 failures
 
    Failed examples:
 
    rspec ./user_pages_spec.rb:11 # User pages signup page 
    rspec ./user_pages_spec.rb:12 # User pages signup page 
    rspec ./user_pages_spec.rb:18 # User pages signup page with invalid information should not create a user
    rspec ./user_pages_spec.rb:32 # User pages signup page with valid information should create a user
 
    Randomized with seed 10291
 
 
I'm guessing the main error involves the undefined method or varialble "signup_path," but I have no clue whatsoever where it's supposed to be defined or whether it should have at some point automatically been defined by Rails in the first place.
 
Could someone help me with this?


#2 ExNihil

ExNihil

    Passenger

  • Members
  • 7 posts

Posted 07 October 2013 - 03:44 PM

Here's my routes, file, by the way:

 

Thanks for your reply. Here's my routes file. Unless I'm missing something, everything seems OK to me:
 
    SecondSampleApp::Application.routes.draw do
 
      get "users/new"
      get "static_pages/home"
      get "static_pages/help"
      get "static_pages/about"
 
      resources :users
 
      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


#3 kany

kany

    Passenger

  • Members
  • 2 posts

Posted 09 October 2013 - 02:56 PM

Try updating this:

 

match "/signup", to: "users#new", via: "get"

 

To:

match "/signup", to: "users#new", via: "get", as: "signup"



#4 Ohm

Ohm

    Guard

  • Members
  • 179 posts
  • LocationCopenhagen

Posted 09 October 2013 - 06:33 PM

What in your spec/requests/user_pages_spec.rb-file?

 

In your routes.rb-file, you can replace all the 

match "/something", to: "this#that", via: "get"

with

get "something", to: "this#that"

though this probably isn't your problem.


Blog: http://ohm.sh | Twitter: madsohm





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users