with_routing test helper doesn't work for integration tests

ruby-on-rails, ruby-on-rails-4

Solution

Ok, so I'm answering my own questions again. Problem is that `with_routing` doesn't work at all inside integration tests. Oversight or something, not sure. It only works for controller tests. So here's the work around:

class ActionDispatch::IntegrationTest
  def with_routing(&block)
    yield ComfortableMexicanSofa::Application.routes
  ensure
    ComfortableMexicanSofa::Application.routes_reloader.reload!
  end
end

Basically you will redefine your application routes within that block and then reload them back from the routes.rb file.

Problem

Simple example that by all accounts should work: ``` require 'test_helper' class FoosController < ApplicationController def index render plain: 'something' end end class UsersControllerTest < ActionDispatch::IntegrationTest def test_some_routing with_routing do |set| set.draw do get '/foos' => 'foos#index' end get '/foos' assert_equal 200, response.status end end end ``` Instead I'm getting: `ActionController::RoutingError: No route matches [GET] "/foos"` What am I doing wrong? This is latest Rails 4.1 btw.

Original source