mardi 7 juillet 2015

Rails test - error with routing

I have a very strange problem.

When I run rake test, I get the following wrror:

  1) Error:
StreamsControllerTest#test_should_get_index:
RuntimeError: In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers
     test/controllers/streams_controller_test.rb:5:in `block in <class:StreamsControllerTest>'

I added the following code to /test/test_helper.rb:

include Rails.application.routes.url_helpers
default_url_options[:host] = Configurable[:server_host_name]
default_url_options[:protocol] = Configurable[:server_protocol]

But I still get the same error.

Inside my test class, just to be sure, I added some debugging message:

require 'test_helper'

class StreamsControllerTest < ActionController::TestCase
  test "should get index" do
    puts ">>>> #{streams_url} <<<<"

    get :index
    assert_response :success
  end

end

And I get the expected url:

>>>> http://ift.tt/1HKubUF <<<<

Some idea what is going on here??

Aucun commentaire:

Enregistrer un commentaire