razvans
razvans

Reputation: 3251

Upgrade to Rails 5: Route helpers are not defined in helper specs

I'm currently upgrading from rails 4.2 to rails 5.0 and managed to fix/update most of the things except a bunch of rspec tests.

When I run my suite with rspec spec/ or rake parallel:spec I get intermittent test failures similar to:

enter image description here

Printed Rails.application.routes.url_helpers right before the failing tests and there is no route.

This is mostly in my helpers & mailers folder. When I run the helpers with rspec spec/helpers they all pass. Is super strange because some helpers with route paths in them pass and some don't.

Looked at this, https://github.com/rspec/rspec-rails/issues/1644, rails-controller-testing is not the issue. This did not help at all.

I'm using

Upvotes: 0

Views: 273

Answers (1)

razvans
razvans

Reputation: 3251

I spent a lot of time on this and finally found the culprit. I started by removing folders one by one from the specs/ folder and having --format documentation I managed to cut down to a single file that, when it was executed before the helpers in the suite, it crashed them.

That old test had

before(:each) do
  routes.draw { get 'search' => 'warden#search' }
end

and fixed by adding

  after do  
    Rails.application.reload_routes!
  end

I ended up changing the entire test eventually just to get rid if the reload_routes! because it seemed more of a hack than a fix.

Upvotes: 2

Related Questions