Rails测试正常,但在使用后卫运行时,它们会失败

时间:2017-10-15 14:12:59

标签: ruby-on-rails ruby minitest guard

我在这里创建了一个带有问题的示例应用程序 https://github.com/jean-francois-labbe/rails-guard-not-working

这只是一个带有rails 5.1.4和ruby 2.4.2的简单脚手架 rails g scaffold user username firstname creation:datetime rails db:migrate bundle exec rails test # => tests ok bundle exec guard # => 3 tests will fail

我在Gemfile中添加了guardguard-minitest

有没有人遇到过这个问题?

测试以下结果:

~/Workspace/guard-tests-fail(master ✗) bundle exec rails test
Run options: --seed 23398

Running:

........

Finished in 0.649120s, 12.3244 runs/s, 15.4055 assertions/s.
8 runs, 10 assertions, 0 failures, 0 errors, 0 skips


~/Workspace/guard-tests-fail(master ✗) bundle exec guard     
19:41:31 - INFO - Guard::Minitest 2.4.6 is running, with Minitest::Unit 5.10.3!
19:41:31 - INFO - Running: all tests
Run options: --guard --seed 38654

Running:

.....F

Failure:
MeetingsControllerTest#test_should_create_meeting [/home/jeff/Workspace/guard-tests-fail/test/controllers/meetings_controller_test.rb:19]:
"Meeting.count" didn't change by 1.
Expected: 3
  Actual: 2


bin/rails test test/controllers/meetings_controller_test.rb:18

F

Failure:
MeetingsControllerTest#test_should_destroy_meeting [/home/jeff/Workspace/guard-tests-fail/test/controllers/meetings_controller_test.rb:42]:
"Meeting.count" didn't change by -1.
Expected: 1
  Actual: 2


bin/rails test test/controllers/meetings_controller_test.rb:41

F

Failure:
MeetingsControllerTest#test_should_update_meeting [/home/jeff/Workspace/guard-tests-fail/test/controllers/meetings_controller_test.rb:38]:
Expected response to be a <3XX: redirect>, but was a <422: Unprocessable Entity>


bin/rails test test/controllers/meetings_controller_test.rb:36




Finished in 1.261359s, 6.3424 runs/s, 6.3424 assertions/s.
8 runs, 8 assertions, 3 failures, 0 errors, 0 skips
19:41:35 - INFO - Guard is now watching at '/home/jeff/Workspace/guard-tests-fail'

使用与rails测试相同的种子保护

~/Workspace/guard-tests-fail(master ✗) bundle exec guard
21:36:17 - INFO - Guard::Minitest 2.4.6 is running, with Minitest::Unit 5.10.3!
21:36:17 - INFO - Running: all tests
Run options: --guard --seed 23398

# Running:

...F

Failure:
MeetingsControllerTest#test_should_destroy_meeting [/home/jeff/Workspace/guard-tests-fail/test/controllers/meetings_controller_test.rb:42]:
"Meeting.count" didn't change by -1.
Expected: 1
  Actual: 2


bin/rails test test/controllers/meetings_controller_test.rb:41

..F

Failure:
MeetingsControllerTest#test_should_update_meeting [/home/jeff/Workspace/guard-tests-fail/test/controllers/meetings_controller_test.rb:38]:
Expected response to be a <3XX: redirect>, but was a <422: Unprocessable Entity>


bin/rails test test/controllers/meetings_controller_test.rb:36

F

Failure:
MeetingsControllerTest#test_should_create_meeting [/home/jeff/Workspace/guard-tests-fail/test/controllers/meetings_controller_test.rb:19]:
"Meeting.count" didn't change by 1.
Expected: 3
  Actual: 2


bin/rails test test/controllers/meetings_controller_test.rb:18




Finished in 1.397142s, 5.7260 runs/s, 5.7260 assertions/s.
8 runs, 8 assertions, 3 failures, 0 errors, 0 skips
21:36:21 - INFO - Guard is now watching at '/home/jeff/Workspace/guard-tests-fail'
[1] guard(main)> 

重现的步骤

1)创建一个新项目(rails new demo)

2)生成一个脚手架(rails g scaffold用户名)

3)rails test =&gt;导轨测试没问题

4)在Gemfile中添加gem'guard'和gem'guard-minitest'。并运行bundle

5)运行警卫init minitest。

6)捆绑exec guard =&gt;而且你的测试会很糟糕

堆栈跟踪

rails test

.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:107:in `block (3 levels) in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:204:in `capture_exceptions'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:104:in `block (2 levels) in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:255:in `time_it'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:103:in `block in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:350:in `on_signal'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:275:in `with_info_handler'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:102:in `run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:839:in `run_one_method'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:324:in `run_one_method'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:311:in `block (2 levels) in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:310:in `each'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:310:in `block in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:350:in `on_signal'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:337:in `with_info_handler'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:309:in `run'
.gem/ruby/2.4.1/gems/railties-5.1.4/lib/rails/test_unit/line_filtering.rb:9:in `run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:159:in `block in __run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:159:in `map'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:159:in `__run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:136:in `run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:63:in `block in autorun'
.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
.gem/ruby/2.4.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
.rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
.rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

保护

.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:107:in `block (3 levels) in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:204:in `capture_exceptions'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:104:in `block (2 levels) in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:255:in `time_it'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:103:in `block in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:350:in `on_signal'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:275:in `with_info_handler'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest/test.rb:102:in `run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:839:in `run_one_method'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:324:in `run_one_method'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:311:in `block (2 levels) in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:310:in `each'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:310:in `block in run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:350:in `on_signal'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:337:in `with_info_handler'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:309:in `run'
.gem/ruby/2.4.1/gems/railties-5.1.4/lib/rails/test_unit/line_filtering.rb:9:in `run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:159:in `block in __run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:159:in `map'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:159:in `__run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:136:in `run'
.gem/ruby/2.4.1/gems/minitest-5.10.3/lib/minitest.rb:63:in `block in autorun'

1 个答案:

答案 0 :(得分:0)

这是guard-minitestspring的问题。前往Guardfile并将此spring命令配置添加到初始化:

# Guardfile

guard "minitest", spring: "bin/rails test" do
  # ...
end

有一些半相关的讨论hereguard-minitest自述文件说这是&#34;由于处理参数的复杂性以及对所选文件的运行测试&#34;。