Skip to content
Browse files

Use aruba for dirs and running cucumber processes.

This is way slicker now: Minimal duplication of code between cucumber's env.rb and
ours, fewer redundant step definitions.

Now, all actions that invoke cucumber (or create a directory hierarchy) take place in
tmp/aruba. Also adjust paths for this, and flatten the self_test directory.
  • Loading branch information...
1 parent a575996 commit 6e373aa26fb8115bde1a4ee41b90b2450173ed26 @antifuchs antifuchs committed
View
1 .gitignore
@@ -1,2 +1,3 @@
*.fasl
features/step_definitions/*.wire
+tmp/
View
4 features/sharing_state.feature
@@ -38,8 +38,8 @@ Scenario: State resetting between features
Then clucumber variable "a" should be undefined
Then clucumber variable "b" should be undefined
"""
- When I run cucumber -f progress
- Then it should pass with
+ When I run "cucumber -f progress"
+ Then it should pass with exactly:
"""
......
View
4 features/snippet_texts.feature
@@ -16,8 +16,8 @@ Scenario: Suggestions for undefined steps with and without arguments
When I use a step with "one arg"
Then the step "with two args" should "suggest two args"
"""
- When I run cucumber -f progress
- Then it should pass with
+ When I run "cucumber -f progress"
+ Then it should pass with exactly:
"""
UUU
View
12 features/step_definitions/clucumber_steps.rb
@@ -8,7 +8,7 @@
end
When /^I start clucumber on port (\d+)$/ do |port|
- @clucumber = ClucumberSubprocess.new(File.join(working_dir, 'features'), :port => port)
+ @clucumber = ClucumberSubprocess.new(File.join(current_dir, 'features'), :port => port)
@clucumber.start
end
@@ -21,17 +21,17 @@
end
Then /^files should be loaded in this order:$/ do |expected|
- actual = File.readlines(File.join(working_dir, "files")).map {|line| [line.strip] }
+ actual = File.readlines(File.join(current_dir, "files")).map {|line| [line.strip] }
expected.diff!(actual)
end
Then /^the packages should be$/ do |expected|
- actual = File.readlines(File.join(working_dir, "packages")).map {|line| [line.strip] }
+ actual = File.readlines(File.join(current_dir, "packages")).map {|line| [line.strip] }
expected.diff!(actual)
end
Given /^the standard clucumber setup$/ do
- in_current_dir do
- FileUtils.cp "../clucumber_setup/clucumber_setup.rb", "features/support/"
- end
+ FileUtils.cp(File.expand_path(File.join("..", "..", "self_test", "clucumber_setup.rb"),
+ File.dirname(__FILE__)),
+ File.join(current_dir, "features/support/"))
end
View
62 features/step_definitions/cucumber_steps.rb
@@ -1,62 +1,16 @@
# Taken from cucumber's step definitions
-Given /^I am in (.*)$/ do |relative_path|
- @current_dir = self_test_dir(relative_path)
-end
-
Given /^a standard Cucumber project directory structure$/ do
- @current_dir = working_dir
- in_current_dir do
- FileUtils.rm_rf 'features' if File.directory?('features')
- FileUtils.mkdir_p 'features/support'
- FileUtils.mkdir 'features/step_definitions'
- end
+ create_dir 'features/support'
+ create_dir 'features/step_definitions'
end
-Given /^a file named "([^\"]*)"$/ do |file_name|
- create_file(file_name, '')
-end
-
-Given /^a file named "([^\"]*)" with:$/ do |file_name, file_content|
- create_file(file_name, file_content)
-end
-
-When /^I run cucumber (.*)$/ do |cucumber_opts|
- run "#{Cucumber::RUBY_BINARY} -r rubygems #{Cucumber::BINARY} --no-color #{cucumber_opts} CUCUMBER_OUTPUT_ENCODING=UTF-8"
-end
-
-Then /^it should (fail|pass)$/ do |success|
- if success == 'fail'
- last_exit_status.should_not == 0
+## This may be interesting for the aruba project (if we drop the :
+Then /^it should (pass|fail) with exactly:$/ do |pass_fail, exact_output|
+ strip_duration(combined_output).should == exact_output
+ if pass_fail == 'pass'
+ Then "the exit status should be 0"
else
- if last_exit_status != 0
- raise "Failed with exit status #{last_exit_status}\nSTDOUT:\n#{last_stdout}\nSTDERR:\n#{last_stderr}"
- end
+ Then "the exit status should not be 0"
end
end
-
-Then /^it should (fail|pass) with$/ do |success, output|
- last_stdout.gsub(/\n[dhms0-9]+s\n$/, '').should == output
- Then("it should #{success}")
-end
-
-Then /^the output should contain$/ do |text|
- last_stdout.should include(text)
-end
-
-Then /^the output should not contain$/ do |text|
- last_stdout.should_not include(text)
-end
-
-Then /^the output should be$/ do |text|
- last_stdout.should == text
-end
-
-Then /^print output$/ do
- puts last_stdout
-end
-
-Then /^print stderr$/ do
- puts last_stderr
-end
-
View
12 features/success-and-failure.feature
@@ -21,8 +21,8 @@ Scenario: Succeeding simple scenario
(Given* #?"^this step succeeds$" () t)
"""
- When I run cucumber -f progress
- Then it should pass with
+ When I run "cucumber -f progress"
+ Then it should pass with exactly:
"""
.
@@ -49,8 +49,8 @@ Scenario: Failing simple scenario
(assert (= 1 0)))
"""
- When I run cucumber -f progress
- Then it should fail with
+ When I run "cucumber -f progress"
+ Then it should fail with exactly:
"""
F
@@ -85,8 +85,8 @@ Scenario: Pending simple scenario
(pending "optional message"))
"""
- When I run cucumber -s
- Then it should pass with
+ When I run "cucumber -s"
+ Then it should pass with exactly:
"""
Feature: Test pendingness
View
52 features/support/env.rb
@@ -1,64 +1,14 @@
require 'fileutils'
require 'tempfile'
+require 'aruba'
require File.expand_path("../../clucumber.rb", File.dirname(__FILE__))
class ClucumberWorld
- extend Forwardable
- def_delegators ClucumberWorld, :examples_dir, :self_test_dir, :working_dir
-
- def self.self_test_dir(subdir=nil)
- @examples_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '../../self_test'))
- subdir ? File.join(@examples_dir, subdir) : @examples_dir
- end
-
- def self.working_dir
- @working_dir ||= self_test_dir('tmp')
- end
-
- def initialize
- @current_dir = self_test_dir
- end
-
- def in_current_dir(&block)
- Dir.chdir(@current_dir, &block)
- end
-
- def create_file(file_name, file_content)
- in_current_dir do
- FileUtils.mkdir_p(File.dirname(file_name)) unless File.directory?(File.dirname(file_name))
- File.open(file_name, 'w') { |f| f << file_content }
- end
- end
-
- def run(command)
- stderr_file = Tempfile.new('cucumber')
- stderr_file.close
- in_current_dir do
- mode = Cucumber::RUBY_1_9 ? {:external_encoding=>"UTF-8"} : 'r'
- IO.popen("#{command} 2> #{stderr_file.path}", mode) do |io|
- @last_stdout = io.read
- end
- @last_exit_status = $?.exitstatus
- end
- @last_stderr = IO.read(stderr_file.path)
- end
-
def strip_duration(s)
s.gsub(/^\d+m\d+\.\d+s\n/m, "")
end
-
- attr_reader :last_exit_status, :last_stderr
-
- def last_stdout
- strip_duration(@last_stdout)
- end
end
World do
ClucumberWorld.new
end
-
-Before do
- FileUtils.rm_rf ClucumberWorld.working_dir
- FileUtils.mkdir ClucumberWorld.working_dir
-end
View
0 features/support/support
No changes.
View
1 self_test/.gitignore
@@ -1 +0,0 @@
-tmp
View
2 self_test/clucumber_setup/clucumber_setup.rb → self_test/clucumber_setup.rb
@@ -1,4 +1,4 @@
-require "../../clucumber.rb"
+require File.expand_path("../../../../clucumber.rb", File.dirname(__FILE__))
begin
@main_clucumber = ClucumberSubprocess.new(File.expand_path("../", File.dirname(__FILE__)),

0 comments on commit 6e373aa

Please sign in to comment.
Something went wrong with that request. Please try again.