Skip to content

Commit

Permalink
add a couple more negative steps
Browse files Browse the repository at this point in the history
- also escape regexp chars like parens in strings
  • Loading branch information
dchelimsky committed Feb 20, 2010
1 parent 1b27cf5 commit e4e5204
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
3 changes: 2 additions & 1 deletion features/exit_statuses.feature
Expand Up @@ -10,4 +10,5 @@ Feature: exit statuses

Scenario: non-zero exit status
When I run "ruby -e 'exit 56'"
Then the exit status should be 56
Then the exit status should be 56
And the exit status should not be 0
11 changes: 11 additions & 0 deletions features/output.feature
Expand Up @@ -8,13 +8,24 @@ Feature: Output
When I run "ruby -e 'puts \"hello world\"'"
Then I should see "hello world"

Scenario: Detect absence of one-line output
When I run "ruby -e 'puts \"hello world\"'"
Then I should not see "good-bye"

Scenario: Detect subset of multiline output
When I run "ruby -e 'puts \"hello\nworld\"'"
Then I should see:
"""
hello
"""

Scenario: Detect subset of multiline output
When I run "ruby -e 'puts \"hello\nworld\"'"
Then I should not see:
"""
good-bye
"""

Scenario: Detect exact one-line output
When I run "ruby -e 'puts \"hello world\"'"
Then I should see exactly "hello world\n"
Expand Down
28 changes: 22 additions & 6 deletions lib/aruba.rb
Expand Up @@ -31,6 +31,10 @@ def unescape(string)
eval(%{"#{string}"})
end

def compile_and_escape(string)
Regexp.compile(Regexp.escape(string))
end

def combined_output
@last_stdout + (@last_stderr == '' ? '' : "\n#{'-'*70}\n#{@last_stderr}")
end
Expand Down Expand Up @@ -69,11 +73,19 @@ def run(command)
end

Then /^I should see "([^\"]*)"$/ do |partial_output|
combined_output.should =~ /#{partial_output}/
combined_output.should =~ compile_and_escape(partial_output)
end

Then /^I should not see "([^\"]*)"$/ do |partial_output|
combined_output.should_not =~ compile_and_escape(partial_output)
end

Then /^I should see:$/ do |partial_output|
combined_output.should =~ /#{partial_output}/
combined_output.should =~ compile_and_escape(partial_output)
end

Then /^I should not see:$/ do |partial_output|
combined_output.should_not =~ compile_and_escape(partial_output)
end

Then /^I should see exactly "([^\"]*)"$/ do |exact_output|
Expand All @@ -88,6 +100,10 @@ def run(command)
@last_exit_status.should == exit_status.to_i
end

Then /^the exit status should not be (\d+)$/ do |exit_status|
@last_exit_status.should_not == exit_status.to_i
end

Then /^it should (pass|fail) with:$/ do |pass_fail, partial_output|
if pass_fail == 'pass'
@last_exit_status.should == 0
Expand All @@ -98,17 +114,17 @@ def run(command)
end

Then /^the stderr should contain "([^\"]*)"$/ do |partial_output|
@last_stderr.should =~ /#{partial_output}/
@last_stderr.should =~ compile_and_escape(partial_output)
end

Then /^the stdout should contain "([^\"]*)"$/ do |partial_output|
@last_stdout.should =~ /#{partial_output}/
@last_stdout.should =~ compile_and_escape(partial_output)
end

Then /^the stderr should not contain "([^\"]*)"$/ do |partial_output|
@last_stderr.should_not =~ /#{partial_output}/
@last_stderr.should_not =~ compile_and_escape(partial_output)
end

Then /^the stdout should not contain "([^\"]*)"$/ do |partial_output|
@last_stdout.should_not =~ /#{partial_output}/
@last_stdout.should_not =~ compile_and_escape(partial_output)
end

0 comments on commit e4e5204

Please sign in to comment.