ruby-on-rails - Rails 4.2.2-Windows 7/: bundle exec guard 的 git Bash 上未显示测试结果

标签 ruby-on-rails testing minitest guard

一切都很好,除了,
当我运行时

$ bundle exec guard 

我在运行时看不到测试结果:

$ bundle exec rake test 


每次我编辑文件时都会发生这种情况。

02:28:43 - INFO - Run 'gem install win32console' to use color on Windows
02:28:44 - INFO - Guard::Minitest 2.3.1 is running, with Minitest::Unit 5.7.0!

02:28:44 - INFO - Running: all tests
←]2;[Minitest results] Running: all tests
[1] guard(main)>  Guard is now watching at 'c:/row/dev1/sample_app'

02:29:08 - INFO - Running: test/controllers/static_pages_controller_test.rb
[1] guard(main)> ults] Running: test/controllers/static_pages_controller_test.rb

但是我运行的时候看不到测试结果

$ bundle exec rake test

输出是

ansi: 'gem install win32console' to use color on Windows
Started

 FAIL["test_should_get_home", StaticPagesControllerTest, 2015-07-12 12:20:51 -0700]
 test_should_get_home#StaticPagesControllerTest (1436728851.31s)
    <Home | Ruby on Rails Tutorial Sample App> expected but was
    <| Ruby on Rails Tutorial Sample App>..
    Expected 0 to be >= 1.
    test/controllers/static_pages_controller_test.rb:7:in `block in <class:StaticPagesControllerTest>    

3/3: [===================================] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.37550s
3 tests, 6 assertions, 1 failures, 0 errors, 0 skips
02:54:47 - INFO - Run 'gem install win32console' to use color on Windows
←]2;[Minitest results] 3 tests

我看不到我有错误,尽管测试似乎在运行......还是我遗漏了什么?

这是我的保护文件

# Defines the matching rules for Guard.
guard :minitest, spring: true, all_on_start: true do
  watch(%r{^test/(.*)/?(.*)_test\.rb$})
  watch('test/test_helper.rb') { 'test' }
  watch('config/routes.rb')    { integration_tests }

  watch(%r{^app/models/(.*?)\.rb$}) do |matches|
    "test/models/#{matches[1]}_test.rb"
  end
  watch(%r{^app/controllers/(.*?)_controller\.rb$}) do |matches|
    resource_tests(matches[1])
  end
  watch(%r{^app/views/([^/]*?)/.*\.html\.erb$}) do |matches|
    ["test/controllers/#{matches[1]}_controller_test.rb"] +
    integration_tests(matches[1])
  end
  watch(%r{^app/helpers/(.*?)_helper\.rb$}) do |matches|
    integration_tests(matches[1])
  end
  watch('app/views/layouts/application.html.erb') do
    'test/integration/site_layout_test.rb'
  end
  watch('app/helpers/sessions_helper.rb') do
    integration_tests << 'test/helpers/sessions_helper_test.rb'
  end
  watch('app/controllers/sessions_controller.rb') do
    ['test/controllers/sessions_controller_test.rb',
     'test/integration/users_login_test.rb']
  end
  watch('app/controllers/account_activations_controller.rb') do
    'test/integration/users_signup_test.rb'
  end
  watch(%r{app/views/users/*}) do
    resource_tests('users') +
    ['test/integration/microposts_interface_test.rb']
  end
end

# Returns the integration tests corresponding to the given resource.
def integration_tests(resource = :all)
  if resource == :all
    Dir["test/integration/*"]
  else
    Dir["test/integration/#{resource}_*.rb"]
  end
end

# Returns the controller tests corresponding to the given resource.
def controller_test(resource)
  "test/controllers/#{resource}_controller_test.rb"
end

# Returns all tests for the given resource.
def resource_tests(resource)
  integration_tests(resource) << controller_test(resource)
end

这是我的 gemfile

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.2'
# Use SCSS for stylesheets
gem 'sass-rails', '5.0.2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '2.5.3'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '4.1.0'
# Use jquery as the JavaScript library
gem 'jquery-rails', '4.0.3'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '2.2.3'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'turbolinks', '2.3.0'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
   gem 'byebug', '3.4.0'
   gem 'sqlite3', '1.3.10'
   gem 'web-console', '2.2.1'
   gem 'spring', '1.1.3'
   gem 'tzinfo-data'
end

# adding group for postgresql production
group :production do
    gem 'pg', '0.17.1'
    gem 'rails_12factor', '0.0.2'
end

group :test do
    gem 'minitest-reporters', '1.0.5'
    gem 'mini_backtrace', '0.1.3'
    gem 'guard-minitest', '2.3.1'
    gem 'wdm', '>= 0.1.0' if Gem.win_platform?
end

我从我的应用程序的根目录运行:

bundle exec guard init

然后我进入

bundle exec guard

有任何想法吗? 我需要另一个 gem 吗? 还是我不明白什么? 谢谢!

最佳答案

起初我以为您缺少 wdm,但事实并非如此。安装 wdm gem 后,我的输出从与您的相同变为以下内容:

$ 捆绑执行守卫
20:02:44 - 信息 - 运行“gem install win32console”以在 Windows 上使用颜色
20:02:46 - 信息 - Guard::Minitest 2.3.1 正在运行,Minitest::Unit 5.8.3!
[1] guard(main)> Guard 现在正在监视“c:/Users/GeoffRuby/Desktop/sample_app”

20:02:59 - 信息 - 运行:test/controllers/static_pages_controller_test.rb
[1] 守卫(主力)>

可以看到guard命令行的错误输出没有了。我将与 wdm 的创建者讨论,希望我们能得到一些答案。

关于ruby-on-rails - Rails 4.2.2-Windows 7/: bundle exec guard 的 git Bash 上未显示测试结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31380595/

相关文章:

ruby - 我如何在 MiniTest 中 stub ?

ruby - 如何停止 Minitest?

javascript - 使用 javascript 动态渲染消息 - Rails

ruby-on-rails - 基于 ruby​​ on Rails 中的另一个下拉菜单填充下拉菜单

c# - 如何在单元测试中从测试中传递 UserIdentity

java - 如何避免 Selenium 中的 "StaleElementReferenceException"?

java - 使用 ConcurrentSkipListMap 的并发测试队列

mysql - 如何在 ActiveRecord 中查找除原始记录之外的重复记录

ruby-on-rails - 如何在 rspec 中 stub HTTP POST 请求?

ruby - Ruby Minitest 基本介绍