簡體   English   中英

瑞克測試僅在測試環境中失敗

[英]Rake test failing in test environment only

我正在通過命令行在Rails 3.0.7(Ruby 1.8.7)項目上運行“ rake測試”。

我仍在學習中,我的rails應用程序是一個非常基本的即用型應用程序。 例如,我的Gemfile是:

source 'http://rubygems.org'
gem 'rails', '3.0.7'
gem 'sqlite3'

在不指定環境的情況下執行此操作即可。 我認為這正在對開發產生影響,因為當我嘗試指出開發環境時,它仍然有效! 同樣,當我運行“ rake test:units”或“ rake test:functionals”時,這些也可以正常工作。

但是,當我在測試環境中運行時,單元測試無法運行? 我已經從Rubymine IDE和命令行嘗試了相同的結果。

跟蹤輸出如下所示-首先是簡單的“瑞克測試”:

C:\Users\Ben\dev\railstest>rake test --trace
(in C:/Users/Ben/dev/railstest)
** Invoke test (first_time)
** Execute test
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute test:prepare
** Execute test:units
Loaded suite C:/dev/lang/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader Started
.......................
Finished in 2.821289 seconds.

23 tests, 24 assertions, 0 failures, 0 errors
** Invoke test:functionals (first_time)
** Invoke test:prepare
** Execute test:functionals
Loaded suite C:/dev/lang/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader Started
.............
Finished in 3.34668 seconds.

13 tests, 25 assertions, 0 failures, 0 errors
** Invoke test:integration (first_time)
** Invoke test:prepare
** Execute test:integration

現在,針對測試環境的失敗運行

C:\Users\Ben\dev\railstest>rake environment RAILS_ENV=test test --trace
(in C:/Users/Ben/dev/railstest)
** Invoke environment (first_time)
** Execute environment
** Invoke test (first_time)
** Execute test
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Invoke test:functionals (first_time)
** Invoke test:prepare
** Execute test:functionals
Loaded suite C:/dev/lang/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader Started
.............
Finished in 3.328125 seconds.

13 tests, 25 assertions, 0 failures, 0 errors
** Invoke test:integration (first_time)
** Invoke test:prepare
** Execute test:integration
Errors running test:units!

錯誤消息中沒有更多文本,也沒有進一步指示錯誤實際上是什么。 我已經在sqlite3環境和db:seed上重新運行了db:schema:load ,以填充一些數據庫表,盡管測試數據通常是通過固定裝置加載的。

我認為這里的問題是試圖針對測試環境運行單元測試,但是我不明白為什么?

運行rake test所有單元rake test ,功能測試和集成測試都在測試環境中運行。 從您所顯示的結果來看,測試正在按預期運行。 您無需顯式地告訴rake使用測試環境-就是假定的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM