43

I'm getting a similar error in a number of tests when I add ":js => true" to them. eg:

    An error occurred in an after hook
      ActionController::RoutingError: No route matches [GET] "/assets"
      occurred at /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'

I haven't been testing JavaScript-enabled stuff in my app before and have only just set up to do so by upgrading to Capybara 2 and installing Database Cleaner. config.use_transactional_fixtures = false, and I've added some before/after hooks (hooks?) to my spec_helper file that I've copied directly from the accepted answer here.

I'm running:

  • Rails 3.2.5
  • Rspec-rails 2.12.2.

Can anyone clue me in on how I can attack this one? Many thanks!

    4) Event pages 'CREATE' submitting a valid form provides a success notification and displays new event's page 
    Failure/Error: Unable to find matching line from backtrace
    ActionController::RoutingError:
    No route matches [GET] "/assets"
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/railties-3.2.5/lib/rails/rack/logger.rb:26:in `call_app'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/railties-3.2.5/lib/rails/rack/logger.rb:16:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/request_id.rb:22:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/activesupport-3.2.5/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/static.rb:62:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/railties-3.2.5/lib/rails/engine.rb:479:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/railties-3.2.5/lib/rails/application.rb:220:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/builder.rb:134:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/urlmap.rb:64:in `block in call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/urlmap.rb:49:in `each'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/urlmap.rb:49:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/bundler/gems/capybara-8368069cfd05/lib/capybara/server.rb:19:in `call'
    # /Users/appletart/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
    # /Users/appletart/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
    # /Users/appletart/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
    # /Users/appletart/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Community
  • 1
  • 1
Reb
  • 649
  • 1
  • 8
  • 12
  • Are you using `capybara-webkit`? Also if I put `js: true` in a test, all the tests that are executed inside that run failed too, even if they don't have `js:true`. – Pigueiras Feb 14 '13 at 19:45
  • Pigueiras, no, using the capybara gem, not the capybara-webkit one. Is that not okay? (I'm a bit of a noob...) – Reb Mar 08 '13 at 09:04
  • 1
    `capybara-webkit` is a gem for making the tests with `js:true` faster, the tests run without opening a Firefox window. Could your problem be related with testing a page with a non existing image? I believe that this is what was happening to me. Try to remove all `image_tag` in your tested page and tell me if the tests run smoothly plz. – Pigueiras Mar 08 '13 at 13:46
  • Right, I just added the capybara-webkit gem. THANK YOU - was getting sick of the Firefox window! Yes that's exactly what happens: with image_tag removed from my tested page the tests all pass! – Reb Mar 08 '13 at 14:33
  • Oh hell. I am indeed testing a page with a non-existing image. Thank you Pigueiras. I am ashamed. Glad to see you seem to have solved a problem of your own in the meantime! – Reb Mar 08 '13 at 17:52

4 Answers4

47

Your missing route looks like some auto-generated assets path with nil input. Are you sure your assets are correctly specified in your css/sass or wherever this route comes from?

I have been struggling with a similiar issue where an asset path induced a routing error

  1) user signup: [ JS ] : creates User on successful signup
     Failure/Error: Unable to find matching line from backtrace
     ActionController::RoutingError:
       No route matches [GET] "/assets/images/leftArrow.png"

followed by a stack trace virtually identical to yours. In my case it turned out the asset was in fact missing (which went unnoticed in my development.log and in my test environment until recently I recklessly 'bundle updated' an project after several idle months)

Along the way I learned a lot about Capybara's app_host and asset handling, assets precompiling in different environments, Application.configure.assets.[debug|digest|...] and alike, which probably is where you should be searching in the first place. Or in the sprockets/sass-rails url helper ... after all your missing route still looks like some auto-generated assets path with empty input)

If the above doesn't help a workaround might be adding the following line in environments/test.rb:

config.action_dispatch.show_exceptions = true

While not addressing the problem directly, it successfully suppressed it in my case.

Another kind of workaround could be in spec_helper.rb:

 ActionController::Base.asset_host = "http://myapp.dev"

where myapp.dev is a running instance of myApp in development mode, which delivers the assets or at least does not hit your test routing for the assets, but probably one should do this only in complete desparation. It's inspired by the strategy to avoid asset compiling as explained in http://johnbintz.github.com/blog/2012/01/07/cucumber-capybara-asset-pipeline-debug-mode/

Also potentially helpful: http://guides.rubyonrails.org/asset_pipeline.html http://rubydoc.info/github/jnicklas/capybara/master/Capybara#configure-class_method

christian.buggle
  • 1,211
  • 1
  • 13
  • 24
  • Nice answer! Both solutions worked, but the first one only moves the exception to the `test.log`. Thanks a lot! – Pigueiras Feb 18 '13 at 21:23
  • Hey Christian, thanks. Sorry I didn't see your response earlier, I figured nobody had anything to offer and didn't check back. I think I've isolated the problem to something to do with rmagick, as removing a link to an image (which uses rmagick) causes all my failing tests to pass. It works fine in development though, so would it be right do you think to figure that it's not really an rmagick setup problem and that your advice on where to start still stands? Can't believe I still haven't figured this out after a month... I'll take a look at the things you suggest - thanks! – Reb Mar 08 '13 at 07:34
  • Should clarify, by "works fine in development" I mean the image displays in my web browser while I'm developing. It doesn't, however, display during any tests, whether I put 'js: true' or not. – Reb Mar 08 '13 at 07:46
  • Changing the `show_exceptions` value worked for me, though I'm not sure why. I'll have to dig into it when I have some time later on. Thanks! – Matt Huggins Jul 24 '13 at 19:06
  • 1
    @MattHuggins setting config.action_dispatch.show_exceptions = true doesn't really solve your problem. It really just obscures it by rendering an exception page describing the error that was raised. In your case the exception `ActionController::RoutingError` is caught and a page is rendered. You most likely don't want this behavior in test environment because tests might start passing in places where you expect them to fail. – vitaLee Aug 27 '14 at 12:32
  • OHHHH WOW! I've been stuck on this for months!!! I couldn't run Capybara JS tests because of this weird error about missing "application.js". Following your solution, a more meaningful exception was thrown, which made me realize I had a "before" block in my test that was failing, not handled gracefully by the test framework. "show_exceptions = true" was key. THANK YOU! – Amin Ariana Oct 08 '14 at 20:16
24

In my case, adding:

config.assets.debug = true

to config/environments/test.rb fixed it.

In the documentation, it is said that:

You should not need to change test.rb. The defaults in the test environment are: config.assets.compile is true and config.assets.compress, config.assets.debug and config.assets.digest are false.

But, at least in my case, I needed to change it... If anyone could explain exactly why it works, I would be glad...

Waiting for Dev...
  • 12,629
  • 5
  • 47
  • 57
1

In my case, I am getting

 Failure/Error: Unable to find matching line from backtrace
 ActionController::RoutingError:
   No route matches [GET] "/favicon.ico"

I have already put an empty file favicon.ico under app/assets/images, so the development server is fine. But the test environment doesn't know how to handle the assets in this case. The workaround I found was to turn on static serving (instead of using a different server to serve static assets). The penalty of course is the performance.

  in environments/test.rb, set
  config.serve_static_assets = true # default is false
Dingle
  • 2,402
  • 19
  • 12
0

In my case, the default missing image was set to point to s3. I didn't really care if the image was loaded or not. PhantomJs has an option to disable image loading via the command line arg --load-images=no.

In Poltergeist, this can be setup when registering the driver:

Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, :phantomjs_options => ['--load-images=no']) end

cgat
  • 3,689
  • 4
  • 24
  • 38