在监视器监视文件的控制台中没有rspec输出

时间:2012-04-27 12:09:15

标签: ruby ruby-on-rails-3 rspec railstutorial.org guard

我已经安装了'guard'和'guard-rspec',我还配置了Guardfile(用于观察'app / views'中的更改)但是当我运行'bundle exec guard'时,我总是得到这个:

  vagrant@vagrant-debian-squeeze:/vagrant/sample_app$ bundle exec guard
  Guard could not detect any of the supported notification libraries.
  Guard is now watching at '/vagrant/sample_app'
  Guard::RSpec is running, with RSpec 2!
  Running all specs
  ........

  Finished in 0.97359 seconds
  8 examples, 0 failures
  >

它已经完成了警卫控制台提示,如果我从'app / views /'编辑一些文件(例如app / view / static_pages / home.html.erb)并保存它,后卫没有显示任何规格输出,还在等待一些控制台命令。

我想它应该在保存监视文件后显示一些rspec输出。

的Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.9.0'
  gem 'guard-rspec', '0.5.5'
  gem 'guard'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.4'
  gem 'coffee-rails', '3.2.2'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'therubyracer'

  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.0'

group :test do
  gem 'capybara', '1.1.2'
  # gem 'rb-inotify', '0.8.8'
  # gem 'libnotify', '0.5.9'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

Guardfile:

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

require 'active_support/core_ext'

guard 'rspec', :version => 2, :all_after_pass => false do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^lib/(.+)\.rb$})                           { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb", (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : "spec/requests/#{m[1].singularize}_pages_spec.rb")]}
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('spec/spec_helper.rb')                        { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  # Capybara request specs
  watch(%r{^app/views/(.+)/}) do |m|
    "spec/requests/#{m[1].singularize}_pages_spec.rb"
  end
end

“app / views”的警卫监视规则是

  watch(%r{^app/views/(.+)/}) do |m|
    "spec/requests/#{m[1].singularize}_pages_spec.rb"
  end

运行时环境:

Debian-Squeeze 32bit Vagrant box

顺便说一下。我正在学习一个Rails表格ruby-on-rails-tutorial-book,并坚持Automated tests with Guard

感谢任何帮助,谢谢。

4 个答案:

答案 0 :(得分:9)

Guard doesn't pick up filesystems changes made by the Vagrant host(在我的情况下是Ubuntu)。

您可以通过-p选项强制守卫轮询文件系统(增加CPU使用率,不断点击硬盘并导致笔记本电脑温度升高 - 所以不理想,但它有效)

bundle exec guard -p

答案 1 :(得分:0)

取消注释测试组中的通知库,以便您的Gemfile看起来像。

group :test do
  gem 'capybara', '1.1.2'
  gem 'rb-inotify', '0.8.8'
  gem 'libnotify', '0.5.9'
end

应该这样做。享受Rails Tutorial的乐趣,真棒!

编辑:这是假设你在运行Linux。 OS X和Windows有自己的测试库。继续阅读教程,你会看到它。

答案 2 :(得分:0)

改为尝试(来自guard init生成的Guardfile):

watch(%r{^app/views/(.+)/}) { |m| "spec/requests/#{m[1]}_spec.rb" }

正则表达式是正确的,但似乎有关文件名'spec / requests /#{m [1] .singularize} _pages_spec.rb'的内容导致guard无声地失败,就像表达式一样没有匹配。我不明白为什么。

答案 3 :(得分:-3)

我删除了Guard并安装了Watchr,似乎它使他的工作正常。这帮助了我:

How to rails 3 and rspec 2