1 steps_for :running_rspec do
3 Given("the file $relative_path") do |relative_path|
4 @path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "resources", relative_path))
5 unless File.exist?(@path)
6 raise "could not find file at #{@path}"
10 When("I run it with the $interpreter") do |interpreter|
11 stderr_file = Tempfile.new('rspec')
13 @stdout = case(interpreter)
14 when /^ruby interpreter/
15 args = interpreter.gsub('ruby interpreter','')
16 ruby("#{@path}#{args}", stderr_file.path)
18 args = interpreter.gsub('spec script','')
19 spec("#{@path}#{args}", stderr_file.path)
20 when 'CommandLine object' then cmdline(@path, stderr_file.path)
21 else raise "Unknown interpreter: #{interpreter}"
23 @stderr = IO.read(stderr_file.path)
27 Then("the exit code should be $exit_code") do |exit_code|
28 if @exit_code != exit_code.to_i
29 raise "Did not exit with #{exit_code}, but with #{@exit_code}. Standard error:\n#{@stderr}"
33 Then("the $stream should match $regex") do |stream, string_or_regex|
34 written = case(stream)
35 when 'stdout' then @stdout
36 when 'stderr' then @stderr
37 else raise "Unknown stream: #{stream}"
39 written.should smart_match(string_or_regex)
42 Then("the $stream should not match $regex") do |stream, string_or_regex|
43 written = case(stream)
44 when 'stdout' then @stdout
45 when 'stderr' then @stderr
46 else raise "Unknown stream: #{stream}"
48 written.should_not smart_match(string_or_regex)