7

After upgrading to Rails 3.2.6 or Rspec 2.11.0, my specs starts to show routing errors like the following:

  4) UsersController GET activate activation code not exist 
     Failure/Error: subject{ get :activate }
     ActionController::RoutingError:
       No route matches {:controller=>"users", :action=>"activate"}

There is also a after each hook error

An error occurred in an after(:each) hook
  RSpec::Mocks::MockExpectationError: (#<EmailSubscriber[...]>).update_attributes({:enable=>true})
    expected: 1 time
    received: 0 times
  occurred at [...]/spec/controllers/users_controller_spec.rb:75:in `block (3 levels) in <top (required)>'

The application in development mode still runs fine.

prusswan
  • 6,853
  • 4
  • 40
  • 61
lulalala
  • 17,572
  • 15
  • 110
  • 169

2 Answers2

7

Both Rspec 2.11.0 and Rails 3.2.6 uses the latest Journey gem (1.0.4). It has some problems, and by explictly lock it to the previous version the spec error disappears.

gem 'journey', '1.0.3'

UPDATE

I recently updated Rails to 3.2.11 with Journey 1.0.4, and all spec passed. My Rspec is 2.11.0 Therefore there is no need to downlock journey anymore, just update Rails.

lulalala
  • 17,572
  • 15
  • 110
  • 169
  • how do you find it ? I fixed the error in rails test by following your answer but basically the error message didn't tell anything. – u19964 Jul 17 '12 at 00:47
  • 2
    Well it is a routing error, and my test are so basic that it must be one of the gem updates, and I found out journey is the common dependency of the two updates – lulalala Jul 17 '12 at 01:48
  • +1 Worked for me -- downgraded a `Rails 3.2.6` app to explicitly use `1.0.3` instead of `1.0.4`. – Nathan Jul 24 '12 at 00:53
  • The later version of journey doesn't have any problems, it's just changed how permissive it is with allowing nil to be passed to routes that take arguments and not throwing an error. Before it allowed it, now it doesn't. Check your routes and usage of routes helpers and make sure you're not passing nil in anywhere. – te_chris Jul 24 '12 at 02:37
  • 1
    @te_chris no, my tests are as simple as it can get. This may be the issue https://github.com/rails/journey/issues/42 – lulalala Jul 24 '12 at 02:47
  • @lulalala Any news regarding this error? Were you able to resolve it? I've checked the related issues, but the cause seems to be a different one - still stuck at Rails 3.2.6 for that reason. – user569825 Sep 03 '12 at 13:31
  • 3
    This does not work for Rails 2.3.8 as it has a dependency of journey 1.0.4 or better. – Kris Oct 07 '12 at 18:46
  • @Kris see my update and see if update to Rails 3.2.11 worked for you – lulalala Jan 11 '13 at 06:28
  • @lulalala I use minitest, but had the same issue. Now I tried once again to upgrade from 3.2.6 (to 3.2.11), but I am still getting the `No route matches` errors. Did you change anything else in order to make it work? – user569825 Jan 12 '13 at 22:25
  • I guess my theory is wrong. I have updated so many things during this 6 months, so it is pretty hard to tell what's the cure :/ Maybe when I have time. – lulalala Feb 01 '13 at 15:01
2

It appears that the environment is stricter in functional tests than it is in production or development.

In the latter two, it is unable to "know" the parameter names beforehand as they are determined by looking at the according/matching route definition.

In a test, however, one provides the parameter name explicitly. This allows the environment to be more picky.

As that behaviour drifts away from the principle of having a test-env match a prod-env as closely as possible, I consider it a bug and filed an issue accordingly (https://github.com/rails/journey/issues/59).

In order to work around the problem for now, make sure your parameter names match your routes exactly.

I suggest adding the according routes until an outcome is decided in regards to the filed issue. That way, if it's consired a bug and resolved, you just need to remove the routes again - instead of fiddling with your production logic on controller level (which is working flawlessly already).

user569825
  • 2,369
  • 1
  • 25
  • 45