web-dev-qa-db-ja.com

Capybaraは:js => trueでテストします...ルーティングエラー:一致するルートはありません[GET] "/ assets"

":js => true"を追加すると、多くのテストで同様のエラーが発生します。例えば:

    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'

私はこれまでにアプリでJavaScript対応のものをテストしたことがなく、Capybara 2にアップグレードしてDatabase Cleanerをインストールすることで設定できるだけです。 config.use_transactional_fixtures = false、受け入れ済みの回答から直接コピーしたspec_helperファイルにbefore/afterフック(フック?)をいくつか追加しました here

私は走っています:

  • Rails 3.2.5
  • Rspec-Rails 2.12.2。

これを攻撃する方法について誰かが手掛かりをくれますか?どうもありがとう!

    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'
42
Reb

不足しているルートは、入力がnilの自動生成されたアセットパスのようです。アセットがcss/sassで正しく指定されているか、このルートがどこから来ているかを確認しますか?

アセットパスがルーティングエラーを引き起こしたという同様の問題に悩んでいます

  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"

その後に、実質的に同じスタックトレースが続きます。私の場合、資産が実際に欠落していることが判明しました(これは私の開発.logと私のテスト環境では気付かれないままでしたが、最近まで私は数ヶ月のアイドル期間後に無謀にプロジェクトを「バンドル更新」していました)

Capybaraのapp_Hostとアセット処理、さまざまな環境でのプリコンパイルされたアセット、Application.configure.assets。[debug | digest | ...]などについて多くのことを学びながら、おそらく最初に検索する必要のある場所です。 。または、sprockets/sass-RailsのURLヘルパーで...すべての行方不明のルートが、空の入力のある自動生成されたアセットパスのように見えます)

上記で解決しない場合の回避策は、environments/test.rbに次の行を追加することです。

config.action_dispatch.show_exceptions = true

問題に直接対処していませんが、私の場合は問題をうまく抑制しました。

別の種類の回避策は、spec_helper.rbにあります。

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

ここで、myapp.devは開発モードで実行中のmyAppのインスタンスで、アセットを提供するか、少なくともアセットのテストルーティングにヒットしませんが、おそらく完全に分離する必要があります。 http://johnbintz.github.com/blog/2012/01/07/cucumber-capybara-asset-pipeline-debug-mode/ で説明されているアセットのコンパイルを回避する戦略に触発されています

また役立つ可能性があります: http://guides.rubyonrails.org/asset_pipeline.htmlhttp://rubydoc.info/github/jnicklas/capybara/master/Capybara#configure-class_method

46

私の場合、追加:

config.assets.debug = true

config/environments/test.rb修正しました。

documentation では、次のように述べられています。

Test.rbを変更する必要はありません。テスト環境のデフォルトは、config.assets.compileがtrueで、config.assets.compress、config.assets.debug、config.assets.digestがfalseです。

しかし、少なくとも私の場合は、変更する必要がありました...なぜそれが機能するのかを正確に説明できる人がいれば、私は喜んでいます...

22

私の場合、私は得ています

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

空のファイルfavicon.icoをapp/assets/imagesにすでに置いているので、開発サーバーは問題ありません。ただし、この場合、テスト環境はアセットの処理方法を認識していません。私が見つけた回避策は、静的な配信をオンにすることでした(静的なアセットを配信するために別のサーバーを使用する代わりに)。もちろんペナルティはパフォーマンスです。

  in environments/test.rb, set
  config.serve_static_assets = true # default is false
1
Dingle

私の場合、デフォルトの欠落している画像はs3を指すように設定されていました。画像が読み込まれたかどうかは気にしませんでした。 PhantomJsには、コマンドライン引数_--load-images=no_を介してイメージのロードを無効にするオプションがあります。

Poltergeistでは、これはドライバーの登録時に設定できます。

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

0
cgat