2010-12-13 7 views
21

私はテストのためにRSpecを使用しています。金曜日の午後に仕事を辞めたとき、私のテストは合格でした。しかし、家に帰って私のリポジトリを同期させると、ラップトップでテストが失敗しました。仕事に戻り、テストはまだ失敗しています。 rspecを単独で実行するとエラーが返され、sporkも起動しないので、自分のコードを信じてはいけません。RSpecで初期化されていない定数エラーを取得しています。何が起こっているのか分かりません

Using RSpec 
Loading Spork.prefork block... 
uninitialized constant ActionView::Template::Handlers::ERB::ENCODING_FLAG (NameError) 
/home/jeff/.rvm/gems/[email protected]/gems/rspec-core-2.2.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:85:in `<class:ERB>' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:70:in `<module:Handlers>' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:28:in `<class:Template>' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:27:in `<module:ActionView>' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:6:in `<top (required)>' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template/handlers.rb:10:in `extended' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template.rb:99:in `extend' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template.rb:99:in `<class:Template>' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template.rb:8:in `<module:ActionView>' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template.rb:6:in `<top (required)>' 
<internal:lib/rubygems/custom_require>:29:in `require' 
<internal:lib/rubygems/custom_require>:29:in `require' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/template/resolver.rb:3:in `<top (required)>' 
<internal:lib/rubygems/custom_require>:29:in `require' 
<internal:lib/rubygems/custom_require>:29:in `require' 
/home/jeff/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/testing/resolvers.rb:1:in `<top (required)>' 
<internal:lib/rubygems/custom_require>:29:in `require' 
<internal:lib/rubygems/custom_require>:29:in `require' 
/home/jeff/.rvm/gems/[email protected]/gems/rspec-rails-2.2.1/lib/rspec/rails/view_rendering.rb:1:in `<top (required)>' 
<internal:lib/rubygems/custom_require>:29:in `require' 
<internal:lib/rubygems/custom_require>:29:in `require' 
/home/jeff/.rvm/gems/[email protected]/gems/rspec-rails-2.2.1/lib/rspec/rails.rb:9:in `<top (required)>' 
<internal:lib/rubygems/custom_require>:33:in `require' 
<internal:lib/rubygems/custom_require>:33:in `rescue in require' 
<internal:lib/rubygems/custom_require>:29:in `require' 
/home/jeff/Projects/Rails/vahsfbhistory/spec/spec_helper.rb:10:in `block in <top (required)>' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork.rb:23:in `prefork' 
/home/jeff/Projects/Rails/vahsfbhistory/spec/spec_helper.rb:5:in `<top (required)>' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/test_framework.rb:138:in `load' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/test_framework.rb:138:in `block (2 levels) in preload' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/app_framework.rb:64:in `preload' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/test_framework.rb:134:in `block in preload' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork.rb:67:in `exec_prefork' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/test_framework.rb:120:in `preload' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/run_strategy/forking.rb:25:in `preload' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/runner.rb:74:in `run' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/runner.rb:9:in `run' 
/home/jeff/.rvm/gems/[email protected]/gems/spork-0.8.4/bin/spork:10:in `<top (required)>' 
/home/jeff/.rvm/gems/[email protected]/bin/spork:19:in `load' 
/home/jeff/.rvm/gems/[email protected]/bin/spork:19:in `<main>' 

誰もがこれを引き起こしている可能性が知っている:私は先割れスプーンを起動しようとすると、私は次のエラーメッセージが表示されますか?

+3

なぜこのエラーが発生したのですか?私は今自分自身を経験している。私がしたのは 'rspec/rails' – Despo

答えて

24

この問題が発生しました。

require "rails" 

私の状況で働いていた
require "rails/all" 

で:spec_helper.rbで交換してください。

+0

wtfです。これはどうやって分かりましたか?なぜこうなった? – Jwan622

+0

これは私のRails 4.2.5アプリで私の問題を解決していません –

-1

それはRailsのアプリではありませんし、あなたのspec_helper.rbにこれを追加し、レールのすべてを含めない場合:

require 'action_view' 
+0

これは非レールアプリでは動作しません。 'NameError:初期化されていない定数ActionController :: TestCase'で失敗します。代わりに私の答えを見てください。 – thisismydesign

10

あなたは、環境を初期化する必要があり、spec_helper.rbに次の行を追加します:

require File.expand_path("../../config/environment", __FILE__) 
+0

うわー、ちょうど今のところこの問題の解決策を見つけようとしています。 –

+0

@Зелёныйはちょうど時間で答えました:) –

+0

このDIDは私のRails 4.2.5アプリで症状を修正しました –

0

あなたは非レールのプロジェクトにrspec-railsを使用しようとしている場合は、この問題が発生することがあります。それはであなたを残してのActiveRecordのものを必要とすると思いますので、その場合はrequire "rails/all"を使用することはオプションではありません。

ActiveRecord::ConnectionNotEstablished: No connection pool with 'primary' found.

代わりにあなたがこの問題を修正することができます:あなたがこれまでに知りました

require "action_controller/railtie"