1 $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
5 require File.dirname(__FILE__) + '/smart_match'
9 config = ::Config::CONFIG
10 interpreter = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
11 cmd = "#{interpreter} #{args} 2> #{stderr}"
12 #puts "\nCOMMAND: #{cmd}"
16 def spec(args, stderr)
17 ruby("#{File.dirname(__FILE__) + '/../bin/spec'} #{args}", stderr)
20 def cmdline(args, stderr)
21 ruby("#{File.dirname(__FILE__) + '/cmdline.rb'} #{args}", stderr)
24 Spec::Story::World.send :include, self
28 steps_for :rspec_and_test_unit do
30 Given("the file $relative_path") do |relative_path|
31 @path = File.join(File.dirname(__FILE__), relative_path)
33 When("I run it with the $interpreter") do |interpreter|
34 stderr_file = Tempfile.new('rspec')
36 @stdout = case(interpreter)
37 when 'ruby interpreter' then ruby(@path, stderr_file.path)
38 when 'spec script' then spec(@path, stderr_file.path)
39 when 'CommandLine object' then cmdline(@path, stderr_file.path)
40 else raise "Unknown interpreter: #{interpreter}"
42 @stderr = IO.read(stderr_file.path)
45 Then("the exit code should be $exit_code") do |exit_code|
46 if @exit_code != exit_code.to_i
47 raise "Did not exit with #{exit_code}, but with #{@exit_code}. Standard error:\n#{@stderr}"
50 Then("the $stream should match $regex") do |stream, string_or_regex|
51 written = case(stream)
52 when 'stdout' then @stdout
53 when 'stderr' then @stderr
54 else raise "Unknown stream: #{stream}"
56 written.should smart_match(string_or_regex)
58 Then("the $stream should not match $regex") do |stream, string_or_regex|
59 written = case(stream)
60 when 'stdout' then @stdout
61 when 'stderr' then @stderr
62 else raise "Unknown stream: #{stream}"
64 written.should_not smart_match(string_or_regex)
68 with_steps_for :rspec_and_test_unit do
69 Dir["#{File.dirname(__FILE__)}/**"].each do |file|
70 run file if File.file?(file) && !(file =~ /\.rb$/)