diff --git a/features/issue_117.feature b/features/issue_117.feature new file mode 100644 index 0000000000..7e8431d014 --- /dev/null +++ b/features/issue_117.feature @@ -0,0 +1,63 @@ +@spork @my_issues +Feature: DRb Server Integration: Regression test for Issue #117 + To prevent waiting for Rails and other large Ruby applications to load their environments + for each feature run Cucumber ships with a DRb client that can speak to a server which + loads up the environment only once. + + This regression test highlights bug related to DRb server arguments processing, for more + details see https://github.com/cucumber/cucumber/issues/117 + + Background: App with Spork support + Spork is a gem that has a DRb server and the scenarios below illustrate how to use it. + However, any DRb server that adheres to the protocol that the client expects would work. + + Given a directory without standard Cucumber project directory structure + And a file named "features/support/env.rb" with: + """ + require 'rubygems' + require 'spork' + + Spork.prefork do + puts "I'm loading all the heavy stuff..." + end + + Spork.each_run do + puts "I'm loading the stuff just for this run..." + end + """ + And a file named "config/cucumber.yml" with: + """ + <% + std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip" + %> + default: --drb <%= std_opts %> features + """ + And a file named "features/sample.feature" with: + """ + # language: en + Feature: Sample + Scenario: this is a test + Given I am just testing stuff + """ + And a file named "features/step_definitions/all_your_steps_are_belong_to_us.rb" with: + """ + Given /^I am just testing stuff$/ do + # no-op + end + """ + + Scenario: Single feature passing with '-r features' option + Given I am running spork in the background + When I run cucumber "features/sample.feature -r features --tags ~@wip" + And it should pass with: + """ + 1 step (1 passed) + """ + + Scenario: Single feature passing without '-r features' option + Given I am running spork in the background + When I run cucumber "features/sample.feature --tags ~@wip" + And it should pass with: + """ + 1 step (1 passed) + """ \ No newline at end of file diff --git a/features/step_definitions/cucumber-features/cucumber_ruby_mappings.rb b/features/step_definitions/cucumber-features/cucumber_ruby_mappings.rb index e459561c82..71712a57ef 100644 --- a/features/step_definitions/cucumber-features/cucumber_ruby_mappings.rb +++ b/features/step_definitions/cucumber-features/cucumber_ruby_mappings.rb @@ -163,6 +163,35 @@ def assert_undefined_scenario def failed_output "failed" end + + def run_spork_in_background(port = nil) + require 'spork' + + pid = fork + in_current_dir do + if pid + background_jobs << pid + else + # STDOUT.close + # STDERR.close + port_arg = port ? "-p #{port}" : '' + cmd = "#{Cucumber::RUBY_BINARY} -I #{Cucumber::LIBDIR} #{Spork::BINARY} cuc #{port_arg}" + exec cmd + end + end + sleep 1.0 + end + + def background_jobs + @background_jobs ||= [] + end + + def terminate_background_jobs + background_jobs.each do |pid| + Process.kill(Signal.list['TERM'], pid) + end + end + end World(CucumberRubyMappings) diff --git a/features/step_definitions/drb_steps.rb b/features/step_definitions/drb_steps.rb new file mode 100644 index 0000000000..00df00b6e6 --- /dev/null +++ b/features/step_definitions/drb_steps.rb @@ -0,0 +1,3 @@ +Given /^I am running spork in the background$/ do + run_spork_in_background +end \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index f235ea16f9..d9b811b039 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -24,3 +24,7 @@ def unrandom(out) # Set a longer timeout for aruba @aruba_timeout_seconds = 15 end + +After do + terminate_background_jobs +end