簡體   English   中英

守衛不起作用

[英]Guard doesn't work

我研究了Michael Hartl( https://www.railstutorial.org/ )上的Ruby on Rails教程。

在3.6.2中,我想使用Guard自動進行測試。 我編寫與本書相同的代碼並修改測試文件,但是測試不會自動運行。

這是執行Guard的消息。

[vagrant@localhost sample_app]$ bundle exec guard
which: no notify-send in (/home/vagrant/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/bin:/home/vagrant/.rbenv/versions/2.2.1/bin:/usr/local/.rbenv/libexec:/home/vagrant/.rbenv/plugins/ruby-build/bin:/home/vagrant/.rbenv/shims:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/pgsql-9.3/bin:/usr/local/.rbenv/bin:/home/vagrant/bin)
14:32:55 - INFO - Guard is using TerminalTitle to send notifications.
14:32:55 - INFO - Starting Spork for RSpec
Using RSpec, Rails
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!
14:32:59 - INFO - Spork server for RSpec successfully started

14:32:59 - INFO - Guard::RSpec is running
14:32:59 - INFO - Running all specs
Running tests with args ["--color", "--failure-exit-code", "2", "--format",     "progress", "--format", "Guard::RSpec::Formatter", "--require", "/home/vagrant/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/guard-rspec-2.5.0/lib/guard/rspec/formatter.rb", "spec"]...
...........

Finished in 0.6213 seconds
11 examples, 0 failures


Randomized with seed 44839

Done.

14:33:01 - INFO - Guard is now watching at '/vagrant/sample_app'

這是Guardfile。

# A sample Guardfile
# More info at https://github.com/guard/guard#readme
require 'active_support/inflector'
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' },
  :rspec_env    => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch('config/environments/test.rb')
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
end

guard 'rspec', 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{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_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"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/features/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }

  # Custom Rails Tutorial specs
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  do |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")]
  end
  watch(%r{^app/views/(.+)/}) do |m|
    (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
        "spec/requests/#{m[1].singularize}_pages_spec.rb")
  end
  watch(%r{^app/controllers/sessions_controller\.rb$}) do |m|
    "spec/requests/authentication_pages_spec.rb"
  end
end

這是static_pages_spec.rb

require 'spec_helper'

describe "Static pages" do

  subject { page }

  shared_examples_for "all static pages" do
    it { should have_content(heading) }
    it { should have_title(full_title(page_title)) }
  end

  describe "Home page" do
    before { visit root_path }
    let(:heading)    { 'Sample App' }
    let(:page_title) { '' }

    it_should_behave_like "all static pages"
    it { should_not have_title('| Home') }
  end

  describe "Help page" do
    before { visit help_path }
    let(:heading) {'Help'}
    let(:page_title) {'Help'}

    it_should_behave_like "all static pages"
  end

  describe "About page" do
    before { visit about_path }
    let(:heading) {'About'}
    let(:page_title) {'About Us'}

    it_should_behave_like "all static pages"
  end

  describe "Contact page" do
    before { visit contact_path }

    let(:heading) {'Contact'}
    let(:page_title) {'Contact'}

    it_should_behave_like "all static pages"
  end
end

[開發環境] centos 6.6 Rails 4.0.5 ruby​​ 2.2.1 gem'guard','2.6.1'gem'guard-rspec','2.5.0'gem'spork-rails','4.0.0'gem'守衛豬'','1.5.0'

我自己解決這個問題。

試試這個命令。

bundle exec guard -p

暫無
暫無

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

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