X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/ddd5b4cf19a92582fd114914be5bd5a04d3522a7..3f607d565bc0e2c7b1b738301c11c16d069913d5:/vendor/gems/rspec-1.1.2/stories/resources/steps/running_rspec.rb diff --git a/vendor/gems/rspec-1.1.2/stories/resources/steps/running_rspec.rb b/vendor/gems/rspec-1.1.2/stories/resources/steps/running_rspec.rb new file mode 100644 index 000000000..496847fe4 --- /dev/null +++ b/vendor/gems/rspec-1.1.2/stories/resources/steps/running_rspec.rb @@ -0,0 +1,50 @@ +steps_for :running_rspec do + + Given("the file $relative_path") do |relative_path| + @path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "resources", relative_path)) + unless File.exist?(@path) + raise "could not find file at #{@path}" + end + end + + When("I run it with the $interpreter") do |interpreter| + stderr_file = Tempfile.new('rspec') + stderr_file.close + @stdout = case(interpreter) + when /^ruby interpreter/ + args = interpreter.gsub('ruby interpreter','') + ruby("#{@path}#{args}", stderr_file.path) + when /^spec script/ + args = interpreter.gsub('spec script','') + spec("#{@path}#{args}", stderr_file.path) + when 'CommandLine object' then cmdline(@path, stderr_file.path) + else raise "Unknown interpreter: #{interpreter}" + end + @stderr = IO.read(stderr_file.path) + @exit_code = $?.to_i + end + + Then("the exit code should be $exit_code") do |exit_code| + if @exit_code != exit_code.to_i + raise "Did not exit with #{exit_code}, but with #{@exit_code}. Standard error:\n#{@stderr}" + end + end + + Then("the $stream should match $regex") do |stream, string_or_regex| + written = case(stream) + when 'stdout' then @stdout + when 'stderr' then @stderr + else raise "Unknown stream: #{stream}" + end + written.should smart_match(string_or_regex) + end + + Then("the $stream should not match $regex") do |stream, string_or_regex| + written = case(stream) + when 'stdout' then @stdout + when 'stderr' then @stderr + else raise "Unknown stream: #{stream}" + end + written.should_not smart_match(string_or_regex) + end +end