Search code examples
ruby-on-rails-3.1cucumbersporkguard

How to setup Cucumber, Guard & Spork with Rails 3.1?


I'm trying to setup cucumber, rspec, guard and spork. I've got rspec working fine but cucumber crashes with the trace below.

I've try setting this up several times, rails g cucumber:install --spork spork cucumber --boostrap etc... with no luck.

Gems: rails (3.1.3) guard (0.10.0) guard-bundler (0.1.3) guard-cucumber (0.7.4, 0.7.3) guard-rails (0.0.3) guard-rspec (0.6.0, 0.5.2) guard-spork (0.5.1, 0.5.0) cucumber (1.1.4) cucumber-rails (1.2.1) spork (0.9.0)

Running all features
Using the default profile...
Running tests with args ["--color", "--format", "pretty", "--require", "/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/guard-cucumber-0.7.4/lib/guard/cucumber/notification_formatter.rb", "--format", "Guard::Cucumber::NotificationFormatter", "--out", "/dev/null", "--require", "features", "features", "--format", "pretty", "--strict", "--tags", "~@wip", "features", "--no-profile"]...
Disabling profiles...
Exception encountered: #<RuntimeError: All but one formatter must use --out, only one can print to each stream (or STDOUT)>
backtrace:
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/configuration.rb:198:in `arrange_formats'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/configuration.rb:26:in `parse!'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/main.rb:55:in `configuration'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/main.rb:63:in `run_drb_client'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/cucumber-1.1.4/lib/cucumber/cli/main.rb:34:in `execute!'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/spork-0.9.0/lib/spork/test_framework/cucumber.rb:24:in `run_tests'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/spork-0.9.0/lib/spork/run_strategy/forking.rb:13:in `block in run'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/spork-0.9.0/lib/spork/forker.rb:21:in `block in initialize'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/spork-0.9.0/lib/spork/forker.rb:18:in `fork'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/spork-0.9.0/lib/spork/forker.rb:18:in `initialize'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/spork-0.9.0/lib/spork/run_strategy/forking.rb:9:in `new'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/spork-0.9.0/lib/spork/run_strategy/forking.rb:9:in `run'
/Users/matt/.rvm/gems/ruby-1.9.2-p290@alphascore/gems/spork-0.9.0/lib/spork/server.rb:48:in `run'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1518:in `perform'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
/Users/matt/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
Done.

Solution

  • I finally solved this, after playing around with flags passed to cucumber via my guardfile I was able to resolve conflicting flags and not overriding my cucumber.yml flags.

    Working Guardfile

    guard 'cucumber', :cli => "--drb" 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
    

    cucumber.yml

    <%
    rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
    rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
    std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
    %>
    default: --drb <%= std_opts %> features
    wip: --drb --tags @wip:3 --wip features
    rerun: --drb <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
    

    Conflicting Guardfile

    guard 'cucumber', :cli => "--drb --color --format pretty" 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