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


i'm working through chapter 7 of rails tutorial , seem stuck @ figure 7.22. in brief, i'm unable tests pass. when run . . .

bundle exec rspec spec/requests/user_pages_spec.rb 

. . . see bunch of failed tests read:

 failures:  1) user pages signup page      failure/error: before { visit signup_path }     nameerror:     undefined local variable or method `signup_path' # <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' #<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 invalid information should not create user    failure/error: before { visit signup_path }    nameerror:    undefined local variable or method `signup_path' #<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 valid information should create user    failure/error: before { visit signup_path }    nameerror:    undefined local variable or method `signup_path' #<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 invalid information should not create user rspec ./user_pages_spec.rb:32 # user pages signup page valid information should create user  randomized seed 10291 

i'm guessing main error involves undefined method or varialble "signup_path," have no clue whatsoever it's supposed defined or whether should have @ point automatically been defined rails in first place.

could me this?

update: below routes file.

thanks reply. here's routes file. unless i'm missing something, seems ok me:

secondsampleapp::application.routes.draw    "users/new"   "static_pages/home"   "static_pages/help"   "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 

spec/spec_helper.rb

env["rails_env"] ||= 'test' require file.expand_path("../../config/environment", __file__) require 'rspec/rails' require 'rspec/autorun'   dir[rails.root.join("spec/support/**/*.rb")].each { |f| require f }   activerecord::migration.check_pending! if defined?(activerecord::migration)  rspec.configure |config|   config.include capybara::dsl  config.fixture_path = "#{::rails.root}/spec/fixtures"  config.use_transactional_fixtures = true  config.infer_base_class_for_anonymous_controllers = false  config.order = "random"  config.include rails.application.routes.url_helpers end 

here failing tests in user_pages_spec.rb:

require 'spec_helper'  describe "user pages"  subject { page }  describe "signup page"      before { visit signup_path }      { should have_content('sign up') }     { should have_title(full_title('sign up')) }      let(:submit) { "create account" }       describe "with invalid information"         "should not create user"             expect { click_button submit }.not_to change(user, :count)         end     end      describe "with valid information"          before             fill_in "name",         with: "example user"             fill_in "email",        with: "user@example.com"             fill_in "password",     with: "foobar"             fill_in "confirmation", with: "foobar"         end          "should create user"             expect { click_button submit }.to change(user, :count).by(1)         end     end end  describe "profile page"       let(:user) { factorygirl.create(:user) }      before {visit user_path(user)}     {should have_content(user.name)}     {should have_title(user.name)} end  end 

when going through hartl tutorial , encounter undefined local variable or method error or otherwise want find out current definition of variable or method supposed @ point in tutorial, following technique helpful:

  • go book on web
  • click "view single page" link in upper right hand corner
  • with browser's search command, search backwards in tutorial variable/method name in question. (note: if there lots of them, , you're sure it's method, can narrow search "def variable_or_method_in_question")
  • note definition , file in definition occurs (typically given in header of table/listing/figure)

going github repository helpful well, shows final state/location of code, can misleading.

in case, technique results in finding entry in table 5.1 indicates variable path generated rails result of contents of routes.rb file. should check contents of file , @ defined routes using rake routes on command line.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -