Jorge Zapata
Jorge Zapata

Reputation: 45

Ruby on Rails 3 Tutorial Chapter 8 Integration Tests Fail

I have been following the book Ruby on Rails 3 Tutorial by Michael Hartl. It's been going well up until Chapter 8's Integration test. I ran the following command to create the integration tests:

rails generate integration_test users

And it created a file, then I added the 2 tests; one for failure (empty form) and one for success (actual valid form fields).

Here is the users_spec.rb file generated by the command above:

require 'spec_helper'
require 'database_cleaner'

describe "Users" do

  describe "GET /users" 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 users_index_path
      response.status.should be(200)
    end
  end

  describe "signup" do

    describe "failure" do
      it "should not make a new user with empty data" do
        lambda do
          visit signup_path
          fill_in "Name",         :with => ""
          fill_in "Email",        :with => ""
          fill_in "Password",     :with => ""
          fill_in "Confirmation", :with => ""
          click_button
          response.should render_template('users/new')
          response.should have_selector("div#error_explanation")
        end.should_not change(User, :count)
      end #end "should not make a new user with empty data" do
    end #end describe failure

    describe "success" do
      it "should make a new user" do
        lambda do
          visit signup_path
          fill_in "Name",         :with => "Example User"
          fill_in "Email",        :with => "[email protected]"
          fill_in "Password",     :with => "foobar"
          fill_in "Confirmation", :with => "foobar"
          click_button
          response.should have_selector("div.flash.success", :content => "Welcome")
          response.should render_template('users/new')
        end.should change(User, :count).by(1)
      end
    end #end success
  end #end describe signup
end #end describe Users

I do not know why, but all the tests fail when they shouldn't. Am I missing something obvious? I have ran rake db:migrate, cleaned out the DB, but I just don't get it.

Console errors from: rspec spec/requests/users_spec.rb

JorgeZapata:sample_app jorgezapata$ rspec spec/requests/users_spec.rb
Rack::File headers parameter replaces cache_control after Rack 1.5.
FFF

Failures:

  1) Users GET /users works! (now write some real specs)
     Failure/Error: get users_index_path
     NameError:
       undefined local variable or method `users_index_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007ffd9bbd6550>
     # ./spec/requests/users_spec.rb:8:in `block (3 levels) in <top (required)>'

  2) Users signup failure should not make a new user with empty data
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       /Users/jorgezapata/rails_projects/sample_app/app/views/users/new.html.erb:17: syntax error, unexpected tSTRING_BEG, expecting ')'
       ....label :password_confirmation "Confirmation" );@output_buffe...
       ...                               ^
     # <internal:prelude>:10:in `synchronize'
     # ./spec/requests/users_spec.rb:18:in `block (5 levels) in <top (required)>'
     # ./spec/requests/users_spec.rb:17:in `block (4 levels) in <top (required)>'

  3) Users signup success should make a new user
     Failure/Error: visit signup_path
     ActionView::Template::Error:
       /Users/jorgezapata/rails_projects/sample_app/app/views/users/new.html.erb:17: syntax error, unexpected tSTRING_BEG, expecting ')'
       ....label :password_confirmation "Confirmation" );@output_buffe...
       ...                               ^
     # <internal:prelude>:10:in `synchronize'
     # ./spec/requests/users_spec.rb:33:in `block (5 levels) in <top (required)>'
     # ./spec/requests/users_spec.rb:32:in `block (4 levels) in <top (required)>'

Finished in 0.12243 seconds
3 examples, 3 failures

Failed examples:

rspec ./spec/requests/users_spec.rb:6 # Users GET /users works! (now write some real specs)
rspec ./spec/requests/users_spec.rb:16 # Users signup failure should not make a new user with empty data
rspec ./spec/requests/users_spec.rb:31 # Users signup success should make a new user

Thanks in advance and please advise!

Upvotes: 0

Views: 264

Answers (1)

Stuart Nelson
Stuart Nelson

Reputation: 4202

You have your answers in the errors.

1:

undefined local variable or method `users_index_path'

the path doesn't exist. run rake routes from the console to get a list of your available routes. Chances are it's users_path.

2 and 3:

ActionView::Template::Error:
   /Users/jorgezapata/rails_projects/sample_app/app/views/users/new.html.erb:17: syntax error, unexpected tSTRING_BEG, expecting ')'

You have a syntax error in your app/views/users/new.html.erb file at line 17.

Learn to read the error output. It tells you everything you need to know (usually).

Upvotes: 1

Related Questions