forked from cucumber/cucumber-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the aruba features the default ones.
- Loading branch information
1 parent
c11e00f
commit e610a02
Showing
63 changed files
with
355 additions
and
357 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,166 +1,8 @@ | ||
# encoding: utf-8 | ||
require 'tempfile' | ||
|
||
Given /^I am in (.*)$/ do |example_dir_relative_path| | ||
@current_dir = fixtures_dir(example_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 | ||
end | ||
|
||
Given /^the (.*) directory is empty$/ do |directory| | ||
in_current_dir do | ||
FileUtils.remove_dir(directory) rescue nil | ||
FileUtils.mkdir 'tmp' | ||
end | ||
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 | ||
|
||
Given /^the following profiles? (?:are|is) defined:$/ do |profiles| | ||
create_file('cucumber.yml', profiles) | ||
end | ||
|
||
Given /^I am running spork in the background$/ do | ||
run_spork_in_background | ||
end | ||
|
||
Given /^I am running spork in the background on port (\d+)$/ do |port| | ||
run_spork_in_background(port.to_i) | ||
end | ||
|
||
Given /^I am not running (?:.*) in the background$/ do | ||
# no-op | ||
end | ||
|
||
Given /^I have environment variable (\w+) set to "([^"]*)"$/ do |variable, value| | ||
set_env_var(variable, value) | ||
end | ||
|
||
When /^I run cucumber (.*)$/ do |cucumber_opts| | ||
run "#{Cucumber::RUBY_BINARY} -I rubygems #{cucumber_bin} --no-color #{cucumber_opts} CUCUMBER_OUTPUT_ENCODING=UTF-8" | ||
end | ||
|
||
When /^I run rake (.*)$/ do |rake_opts| | ||
run "rake #{rake_opts} --trace" | ||
end | ||
|
||
When /^I run the following Ruby code:$/ do |code| | ||
run %{#{Cucumber::RUBY_BINARY} -r rubygems -I #{cucumber_lib_dir} -e "#{code}"} | ||
end | ||
|
||
Then /^it should (fail|pass)$/ do |success| | ||
if success == 'fail' | ||
last_exit_status.should_not == 0 | ||
else | ||
if last_exit_status != 0 | ||
raise "Failed with exit status #{last_exit_status}\nSTDOUT:\n#{last_stdout}\nSTDERR:\n#{last_stderr}" | ||
end | ||
end | ||
end | ||
|
||
Then /^it should (fail|pass) with$/ do |success, output| | ||
combined_output.should =~ Regexp.compile(Regexp.escape(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 /^it should (fail|pass) with JSON$/ do |success, text| | ||
JSON.parse(last_stdout).should == JSON.parse(text) | ||
Then("it should #{success}") | ||
end | ||
|
||
Then /^"([^"]*)" should contain$/ do |file, text| | ||
strip_duration(IO.read(file)).should == text | ||
end | ||
|
||
Then /^"([^"]*)" with junit duration "([^"]*)" should contain$/ do |actual_file, duration_replacement, text| | ||
actual = IO.read(actual_file) | ||
actual = replace_junit_duration(actual, duration_replacement) | ||
actual = strip_ruby186_extra_trace(actual) | ||
actual.should == text | ||
end | ||
|
||
Then /^"([^"]*)" should match "(.+?)"$/ do |file, text| | ||
File.open(file, Cucumber.file_mode('r')).read.should =~ Regexp.new(text) | ||
end | ||
|
||
Then /^"([^"]*)" should have the same contents as "([^"]*)"$/ do |actual_file, expected_file| | ||
actual = IO.read(actual_file) | ||
actual = replace_duration(actual, '0m30.005s') | ||
# Comment out to replace expected file. Use with care! | ||
# File.open(expected_file, "w") {|io| io.write(actual)} | ||
actual.should == IO.read(expected_file) | ||
end | ||
|
||
Then /^STDERR should match$/ do |text| | ||
last_stderr.should =~ /#{text}/ | ||
end | ||
|
||
Then /^STDERR should not match$/ do |text| | ||
last_stderr.should_not =~ /#{text}/ | ||
end | ||
|
||
Then /^STDERR should be$/ do |text| | ||
last_stderr.should == text | ||
end | ||
|
||
Then /^STDERR should be empty$/ do | ||
last_stderr.should == "" | ||
end | ||
|
||
Then /^"([^"]*)" should exist$/ do |file| | ||
File.exists?(file).should be_true | ||
FileUtils.rm(file) | ||
end | ||
|
||
Then /^"([^"]*)" should not be required$/ do |file_name| | ||
last_stdout.should_not include("* #{file_name}") | ||
end | ||
|
||
Then /^"([^"]*)" should be required$/ do |file_name| | ||
last_stdout.should include("* #{file_name}") | ||
end | ||
|
||
Then /^exactly these files should be loaded:\s*(.*)$/ do |files| | ||
last_stdout.scan(/^ \* (.*\.rb)$/).flatten.should == files.split(/,\s+/) | ||
end | ||
|
||
Then /^exactly these features should be ran:\s*(.*)$/ do |files| | ||
last_stdout.scan(/^ \* (.*\.feature)$/).flatten.should == files.split(/,\s+/) | ||
end | ||
|
||
Then /^the (.*) profile should be used$/ do |profile| | ||
last_stdout.should =~ /Using the #{profile} profile/ | ||
end | ||
|
||
Then /^print output$/ do | ||
puts last_stdout | ||
When /^I run cucumber "([^"]*)"$/ do |cmd| | ||
run_simple(unescape("cucumber #{cmd}"), false) | ||
end | ||
|
||
Then /^the output should contain the following JSON:$/ do |json_string| | ||
JSON.parse(last_stdout).should == JSON.parse(json_string) | ||
Then /^it should (pass|fail) with JSON:$/ do |pass_fail, json| | ||
JSON.pretty_generate(JSON.parse(all_stdout)).should == JSON.pretty_generate(JSON.parse(json)) | ||
assert_exiting_with(pass_fail == 'pass') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,157 +1,31 @@ | ||
require 'rubygems' | ||
require 'aruba/api' | ||
|
||
require 'tempfile' | ||
require 'rspec/expectations' | ||
require 'fileutils' | ||
require 'forwardable' | ||
require 'cucumber/formatter/unicode' | ||
# This is to force miniunit to be loaded on 1.9.2, and verify that we can still run with --profile. See: | ||
# * disable_mini_test_autorun.rb and | ||
# * http://groups.google.com/group/cukes/browse_thread/thread/5682d41436e235d7 | ||
# * https://rspec.lighthouseapp.com/projects/16211/tickets/677-cucumber-093-prevents-testunit-from-running | ||
require 'test/unit' | ||
|
||
class CucumberWorld | ||
extend Forwardable | ||
def_delegators CucumberWorld, :fixtures_dir, :self_test_dir, :working_dir, :cucumber_lib_dir | ||
|
||
def self.fixtures_dir(subdir=nil) | ||
@fixtures_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '../../fixtures')) | ||
subdir ? File.join(@fixtures_dir, subdir) : @fixtures_dir | ||
end | ||
|
||
def self.self_test_dir | ||
@self_test_dir ||= fixtures_dir('self_test') | ||
end | ||
|
||
def self.working_dir | ||
@working_dir ||= fixtures_dir('self_test/tmp') | ||
end | ||
|
||
def cucumber_lib_dir | ||
@cucumber_lib_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '../../lib')) | ||
end | ||
# Monkey patch aruba to filter out some stuff | ||
module Aruba::Api | ||
alias _all_stdout all_stdout | ||
|
||
# Don't use Cucumber::BINARY (which is the binary used to start the "outer" cucumber) | ||
# Instead we force the use of this codebase's cucumber bin script. | ||
# This allows us to run cucumber's cukes with an older, stable cucumber. | ||
def cucumber_bin | ||
File.expand_path(File.dirname(__FILE__) + '/../../bin/cucumber') | ||
end | ||
|
||
def initialize | ||
@current_dir = self_test_dir | ||
end | ||
|
||
private | ||
attr_reader :last_exit_status, :last_stderr | ||
|
||
# The last standard out, with the duration line taken out (unpredictable) | ||
def last_stdout | ||
strip_1_9_paths(strip_duration(@last_stdout)) | ||
end | ||
|
||
def combined_output | ||
last_stdout + "\n" + last_stderr | ||
end | ||
|
||
def strip_duration(s) | ||
s.gsub(/^\d+m\d+\.\d+s\n/m, "") | ||
end | ||
|
||
def strip_1_9_paths(s) | ||
s.gsub(/#{Dir.pwd}\/fixtures\/self_test\/tmp/m, ".").gsub(/#{Dir.pwd}\/fixtures\/self_test/m, ".") | ||
end | ||
|
||
def replace_duration(s, replacement) | ||
s.gsub(/\d+m\d+\.\d+s/m, replacement) | ||
end | ||
|
||
def replace_junit_duration(s, replacement) | ||
s.gsub(/\d+\.\d\d+/m, replacement) | ||
def all_stdout | ||
out = _all_stdout | ||
|
||
# Remove absolute paths | ||
out.gsub!(/#{Dir.pwd}\/tmp\/aruba/, '.') | ||
# Make duration predictable | ||
out.gsub!(/^\d+m\d+\.\d+s$/, '0m0.012s') | ||
# Remove SimpleCov message | ||
out.gsub!(/Coverage report generated for Cucumber Features to #{Dir.pwd}\/coverage\n$/, '') | ||
|
||
out | ||
end | ||
|
||
def strip_ruby186_extra_trace(s) | ||
s.gsub(/^.*\.\/features\/step_definitions(.*)\n/, "") | ||
end | ||
|
||
def create_file(file_name, file_content) | ||
file_content.gsub!("CUCUMBER_LIB", "'#{cucumber_lib_dir}'") # Some files, such as Rakefiles need to use the lib dir | ||
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 set_env_var(variable, value) | ||
@original_env_vars ||= {} | ||
@original_env_vars[variable] = ENV[variable] | ||
ENV[variable] = value | ||
end | ||
|
||
def background_jobs | ||
@background_jobs ||= [] | ||
end | ||
|
||
def in_current_dir(&block) | ||
Dir.chdir(@current_dir, &block) | ||
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 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 terminate_background_jobs | ||
background_jobs.each do |pid| | ||
Process.kill(Signal.list['TERM'], pid) | ||
end | ||
end | ||
|
||
def restore_original_env_vars | ||
@original_env_vars.each { |variable, value| ENV[variable] = value } if @original_env_vars | ||
end | ||
|
||
end | ||
|
||
World do | ||
CucumberWorld.new | ||
end | ||
require 'aruba/cucumber' | ||
|
||
Before do | ||
FileUtils.rm_rf CucumberWorld.working_dir | ||
FileUtils.mkdir CucumberWorld.working_dir | ||
end | ||
Before do |scenario| | ||
@scenario = scenario | ||
|
||
After do | ||
FileUtils.rm_rf CucumberWorld.working_dir unless ENV['KEEP_FILES'] | ||
terminate_background_jobs | ||
restore_original_env_vars | ||
# Make sure bin/cucumber runs with SimpleCov enabled | ||
set_env('SIMPLECOV', 'true') | ||
|
||
# Set a longer timeout for aruba | ||
@aruba_timeout_seconds = 5 | ||
end |
File renamed without changes.
Oops, something went wrong.