【问题标题】:Why does guard start spork both for rspec and cucumber even if I wanted to start it only for rspec using groups?即使我只想使用组为 rspec 启动它,为什么 guard 会同时为 rspec 和 cucumber 启动 spork?
【发布时间】:2012-04-30 11:57:46
【问题描述】:

在我的 Gemfile 中...

group :development, :test do
  gem 'capybara', "1.1.2"
  gem 'database_cleaner', "0.7.0"

  gem 'cucumber', "1.1.2"
  gem 'cucumber-rails', "1.2.0"

  gem 'rspec-rails', "2.7.0"

  gem 'spork', "0.9.0.rc9"

  gem 'launchy' #launches the page

  gem 'guard-spork', "0.3.1"
  gem 'guard-rspec', "0.5.4"
  gem 'guard-cucumber', "0.7.4"

  gem 'factory_girl_rails'
end

我的 Guardfile 有两个组(:specs 和 :features)。

group :specs do

  guard :spork, :rspec_env => { 'RAILS_ENV' => 'test' } do
    watch('config/application.rb')
    watch('config/environment.rb')
    watch(%r{^config/environments/.+\.rb$})
    watch(%r{^config/initializers/.+\.rb$})
    watch('spec/spec_helper.rb')
  end

  guard :rspec, :version => 2 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{^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"] }
    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/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }
  end

end

group :features do

  guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' } do
    watch('config/application.rb')
    watch('config/environment.rb')
    watch(%r{^config/environments/.+\.rb$})
    watch(%r{^config/initializers/.+\.rb$})
    watch('spec/spec_helper.rb')
  end

  guard 'cucumber' do
    watch(%r{^features/.+\.feature$})
    watch(%r{^features/support/.+$})          { 'features' }
    watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
  end

end

当我尝试运行 :specs 组时,我希望警卫只为 Rspec 运行 Spork。

guard -g specs start

但是,我可以从输出中看到,guard 为 Rspec 和 Cucumber 运行了 Spork。

~/current[master]% guard -g specs start
WARNING: You are using Guard outside of Bundler, this is dangerous and may not work. Using `bundle exec guard` is safer.
Guard could not detect any of the supported notification libraries.
Guard is now watching at '/Users/rupert/Desktop/cws-rails'
Starting Spork for RSpec & Cucumber 
Using RSpec
Using Cucumber
Preloading Rails environment
Preloading Rails environment
Loading Spork.prefork block...
Loading Spork.prefork block...
Spork is ready and listening on 8990!
Spork is ready and listening on 8989!
Spork server for RSpec & Cucumber successfully started
Guard::RSpec is running, with RSpec 2!
Running all specs

是否有任何我可能遗漏的 SPORK 或警卫配置文件?

更新:

  1. 去掉保护黄瓜

  2. 删除或重命名功能文件夹

【问题讨论】:

    标签: rspec cucumber spork guard


    【解决方案1】:

    您必须在 RSpec 组的 Spork 中禁用 Cucumber,反之亦然:

    specs :specs    
      guard :spork, :cucumber => false do
        # ...
      end
    end
    
    specs :features    
      guard 'spork', :rspec => false do
        # ...
      end
    end
    

    【讨论】:

      【解决方案2】:

      我知道它很旧,但我现在也偶然发现了这个问题并想通了:

      我的项目中有一个features 子目录,其中包含一个文件: features/step_definitions/email_steps.rb

      查看提交后,我意识到这是从 rails_apps_composer: testing framework 添加的。

      所以:

      删除子目录features 可防止spork 尝试使用黄瓜。

      【讨论】:

        猜你喜欢
        • 2013-09-20
        • 1970-01-01
        • 2013-01-13
        • 2013-10-05
        • 1970-01-01
        • 2017-01-08
        • 2011-12-31
        • 1970-01-01
        • 2014-03-06
        相关资源
        最近更新 更多