2011-05-26 60 views
6

我希望能夠在Heroku上的演示應用程序上運行rspec和黃瓜。我有一個單獨的生產應用程序,我將我的開發分支推向舞臺,將我的主分支推向生產。你如何在Heroku上運行rspec和黃瓜?

我已經將RACK_ENV變量設置爲'staging'並且還添加了一個staging.rb配置文件。

運行RSpec的,黃瓜在本地:

兩個RSpec的,黃瓜運行正常本地使用命令

$ rspec spec 

..

$ cucumber features 

在Heroku上升級應用 rspec的運行

問題是我無法讓他們在我的Heroku分段程序上運行。我明白,RSPEC在Heroku上正確的做法是:

$ heroku rake spec --remote staging 

每當我跑這雖然我得到以下錯誤:

rake aborted! 
You have a nil object when you didn't expect it! 
You might have expected an instance of Array. 
The error occurred while evaluating nil.[] 
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.7/lib/active_record/railties/databases.rake:429:in `block (3 levels) in <top (required)>' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:634:in `call' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:634:in `block in execute' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:629:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:629:in `execute' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:595:in `block in invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:605:in `block in invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:594:in `block in invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:581:in `invoke' 
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.7/lib/active_record/railties/databases.rake:460:in `block (3 levels) in <top (required)>' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:634:in `call' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:634:in `block in execute' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:629:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:629:in `execute' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:595:in `block in invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:605:in `block in invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:594:in `block in invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:581:in `invoke' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2041:in `invoke_task' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2019:in `block (2 levels) in top_level' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2019:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2019:in `block in top_level' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2013:in `top_level' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1992:in `run' 
/usr/ruby1.9.2/bin/rake:31:in `<main>' 
(in /app) 

在Heroku上升級應用程序運行黃瓜

同樣:

$ heroku rake cucumber --remote staging 

結果於:

rake aborted! 
You have a nil object when you didn't expect it! 
You might have expected an instance of Array. 
The error occurred while evaluating nil.[] 
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.7/lib/active_record/railties/databases.rake:429:in `block (3 levels) in <top (required)>' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:634:in `call' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:634:in `block in execute' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:629:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:629:in `execute' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:595:in `block in invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:605:in `block in invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:594:in `block in invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:581:in `invoke' 
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.0.7/lib/active_record/railties/databases.rake:460:in `block (3 levels) in <top (required)>' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:634:in `call' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:634:in `block in execute' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:629:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:629:in `execute' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:595:in `block in invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:605:in `block in invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:594:in `block in invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:605:in `block in invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:602:in `invoke_prerequisites' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:594:in `block in invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:581:in `invoke' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2041:in `invoke_task' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2019:in `block (2 levels) in top_level' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2019:in `each' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2019:in `block in top_level' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2013:in `top_level' 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1992:in `run' 
/usr/ruby1.9.2/bin/rake:31:in `<main>' 
(in /app) 

這個問題顯然是與數據庫有關,但我不知道如何解決它。

+0

你在'database.yml'中設置了'staging'嗎? – 2011-05-26 15:25:55

+0

@Thomas是的我可以 – 2011-05-27 11:32:46

+0

你能解釋爲什麼你想在Heroku上運行這些嗎?這不一定是個壞主意,因爲您的開發平臺可能存在差異,但我只是想知道您的想法是什麼,因爲大多數人只會在本地運行它們,並在像哈德森這樣的持續集成環境中運行它們。 – 2011-05-27 13:40:30

回答

5

問題是測試使用單獨的數據庫,而不是運行應用程序的數據庫。這第二個數據庫你沒有在Heroku上得到。有關類似問題的答案,請參閱Running Rails unit tests on Heroku

+0

謝謝你。如果你只是在heroku上使用單獨的實例,那麼你可以使用該實例上的生產數據庫進行測試? – 2011-08-15 09:20:11

+0

您可以創建一個單獨的實例進行測試,將RACK_ENV設置爲「測試」,然後使用生產數據庫進行測試(請參閱http://stackoverflow.com/questions/5981508/share-database-between-2-apps-in -heroku/5981700#5981700),但要小心,運行測試會在您每次運行數據庫時清除數據庫。 – eugen 2011-08-15 10:00:20

+0

太好了,謝謝,我會試試看 – 2011-08-15 11:45:31