Ruby-on-Rails [SOLVED]: Why is my test framework unable to find a URL defined in my routes file?

Ruby-on-Rails [SOLVED]: Why is my test framework unable to find a URL defined in my routes file?

Home Forums Frameworks Ruby on Rails Tutorials Ruby-on-Rails [SOLVED]: Why is my test framework unable to find a URL defined in my routes file?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #246752

    Cloudy Point
    Keymaster

    QuestionQuestion

    I’m using Rails 5 and minutest and trying to write a test for a controller. The test is

    # issues_controller_test.rb
    class IssuesControllerTest < ActionDispatch::IntegrationTest
    
      include Devise::Test::IntegrationHelpers
    
      test "logged in should get issues page" do
        sign_in users(:one)
        test_stop_id = 1
        test_line_id = 1
        get new_issue, :stop_id => test_stop_id, :line_id => test_line_id
        assert_equal test_stop_id, @issue.stop_id
        assert_equal test_line_id, @issue.line_id
        assert_response :success
      end
    end
    

    The method in question attempts to access this page, defined in my rails routes …

               new_issue GET      /issues/new(.:format)               issues#new
    

    Yet when I run the test, I get this error

    # Running:
    
    .E
    
    Error:
    IssuesControllerTest#test_logged_in_should_get_issues_page:
    NameError: undefined local variable or method `new_issue' for #<IssuesControllerTest:0x007f816759b330>
        test/controllers/issues_controller_test.rb:10:in `block in <class:IssuesControllerTest>'
    
    
    bin/rails test test/controllers/issues_controller_test.rb:6
    
    
    
    Finished in 0.103956s, 19.2389 runs/s, 9.6195 assertions/s.
    

    Why is the test framework unable to find a method defined in my routes file?

    #246753

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    new_issue that way is just a local variable defined nowhere, try specifying it as a working url with new_issue_url:

    test 'logged in should get issues page' do
      sign_in users :one
      test_stop_id = 1
      test_line_id = 1
      get new_issue_url, stop_id: test_stop_id, line_id: test_line_id
      assert_equal test_stop_id, @issue.stop_id
      assert_equal test_line_id, @issue.line_id
      assert_response :success
    end
    

    Source: https://stackoverflow.com/questions/47963101/why-is-my-test-framework-unable-to-find-a-url-defined-in-my-routes-file
    Author: Sebastian Palma
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.