changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/stories/resources/steps/running_rspec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1steps_for :running_rspec do
2
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}"
7 end
8 end
9
10 When("I run it with the $interpreter") do |interpreter|
11 stderr_file = Tempfile.new('rspec')
12 stderr_file.close
13 @stdout = case(interpreter)
14 when /^ruby interpreter/
15 args = interpreter.gsub('ruby interpreter','')
16 ruby("#{@path}#{args}", stderr_file.path)
17 when /^spec script/
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}"
22 end
23 @stderr = IO.read(stderr_file.path)
24 @exit_code = $?.to_i
25 end
26
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}"
30 end
31 end
32
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}"
38 end
39 written.should smart_match(string_or_regex)
40 end
41
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}"
47 end
48 written.should_not smart_match(string_or_regex)
49 end
50end