Home>
Overview

Thank you.
I'm currently working onmichael hert's 5th edition of RailsTutorial: Chapter 11 (11.31).
11.31 Activation test and refactoring.
Below is the corresponding sample code.

11.31 sample code

Therefore, I wrote it as described in the sample code.
Whenrails t,syntax erroris displayed.

The details of this error are as follows.

22:41:06-INFO-Running: test/integration/users_signup_test.rb
bin/rails: /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/test/integration/users_signup_test.rb:33: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)

In consideration of the above, I thought thatendwas mistakenly entered in line 33. The code was also written asendordo.
I researched it, but I couldn't find anyone who was singing in the same way.
More detailed information is given below.

Code you copied
require 'test_helper'
class UsersSignupTest<ActionDispatch :: IntegrationTest
  test setup
    ActionMailer :: Base.deliveries.clear
  end
  test "invalid signup information" do
    get signup_path
    assert_no_difference 'User.count' do
      post users_path, params: {user: {name: "",
                                  email: "user @ invalid",
                                  password: "foo",
                                  password_confirmation: "bar"}}
    end
    assert_template 'users/new'
  end
  test "valid signup information" do
    get signup_pathassert_difference 'User.count', 1 do
      post users_path, params: {user: {name: "Example User",
                                  email: "[email protected]",
                                  password: "password",
                                  password_confirmation: "password"}}
    end
    follow_redirect!
    # assert_template 'users/show'
    # assert is_logged_in?
  end
end
Full error

from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:255: in `load_dependency '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/test_unit/runner.rb:50:in `block in load_tests'
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/test_unit/runner.rb:50:in `each '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/test_unit/runner.rb:50:in `load_tests'
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/test_unit/runner.rb:39:in `run '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands/test/test_command.rb:38:in ` perform '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke '
    from /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top ( required)>'
    from bin/rails: 4: in `require '
    from bin/rails: 4: in `<main>'
Remarks

By the way, every time you return from a previous commit of git, the tests are working.
Also, when writing code, it has already been determined that the test will fail when thesetupfunction is written.

It's more

  • Answer # 1

    test setup
        ActionMailer :: Base.deliveries.clear
      end


    def setup
        ActionMailer :: Base.deliveries.clear
      end


    Is not it?