features/steps/sandbox_steps.rb in timcharper-spork-0.5.0 vs features/steps/sandbox_steps.rb in timcharper-spork-0.5.5

- old
+ new

@@ -10,11 +10,28 @@ Given /^a file named "([^\"]*)" with:$/ do |file_name, file_content| create_file(file_name, file_content) end -When /^I run (spork|spec)($| .*$)/ do |command, spork_opts| +# the following code appears in "config/environment.rb" after /Rails::Initializer.run/: +Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |file_name, regex, content| + # require 'ruby-debug'; Debugger.start; Debugger.start_control; debugger + + regex = Regexp.new(regex) + in_current_dir do + content_lines = File.read(file_name).split("\n") + 0.upto(content_lines.length - 1) do |line_index| + if regex.match(content_lines[line_index]) + content_lines.insert(line_index + 1, content) + break + end + end + File.open(file_name, 'wb') { |f| f << (content_lines * "\n") } + end +end + +When /^I run (spork|spec|cucumber)($| .*$)/ do |command, spork_opts| if command == 'spork' command = SporkWorld::BINARY else command = %x{which #{command}}.chomp end @@ -37,24 +54,28 @@ puts "I can't seem to launch Spork properly. Output was:\n#{output}" true.should == false end end -Then /^the output should contain$/ do |text| - last_stdout.should include(text) +Then /^the (error output|output) should contain$/ do |which, text| + (which == "error output" ? last_stderr : last_stdout).should include(text) end -Then /^the output should contain "(.+)"$/ do |text| - last_stdout.should include(text) +Then /^the (error output|output) should contain "(.+)"$/ do |which, text| + (which == "error output" ? last_stderr : last_stdout).should include(text) end -Then /^the output should not contain$/ do |text| - last_stdout.should_not include(text) +Then /^the (error output|output) should match \/(.+)\/$/ do |which, regex| + (which == "error output" ? last_stderr : last_stdout).should match(Regexp.new(regex)) end -Then /^the output should not contain "(.+)"$/ do |text| - last_stdout.should_not include(text) +Then /^the (error output|output) should not contain$/ do |which, text| + (which == "error output" ? last_stderr : last_stdout).should_not include(text) end -Then /^the output should be$/ do |text| - last_stdout.should == text +Then /^the (error output|output) should not contain "(.+)"$/ do |which, text| + (which == "error output" ? last_stderr : last_stdout).should_not include(text) +end + +Then /^the (error output|output) should be$/ do |which, text| + (which == "error output" ? last_stderr : last_stdout).should == text end