Skip to content

Commit

Permalink
Added to DSL: negative output matching
Browse files Browse the repository at this point in the history
+ Added Aruba::Api#assert_not_matching_output
+ Added the corresponding pair of standard cucumber steps

Reason why: I have faced a situation where a stakeholder wanted to clearly state the
negative match of the output.
  • Loading branch information
argent-smith committed Feb 27, 2012
1 parent fabc92e commit bb9f758
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
19 changes: 19 additions & 0 deletions features/output.feature
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ Feature: Output
important line
"""

@announce
Scenario: Negative matching of one-line output with regex
When I run `ruby --version`
Then the output should contain "ruby"
And the output should not match /ruby is a better perl$/

@announce
@posix
Scenario: Negative matching of multiline output with regex
When I run `ruby -e 'puts "hello\nworld\nextra line1\nextra line2\nimportant line"'`
Then the output should not match:
"""
ruby
is
a
.*
perl
"""

@announce
@posix
Scenario: Match passing exit status and partial output
Expand Down
4 changes: 4 additions & 0 deletions lib/aruba/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def assert_matching_output(expected, actual)
unescape(actual).should =~ /#{unescape(expected)}/m
end

def assert_not_matching_output(expected, actual)
unescape(actual).should_not =~ /#{unescape(expected)}/m
end

def assert_no_partial_output(unexpected, actual)
if Regexp === unexpected
unescape(actual).should_not =~ unexpected
Expand Down
11 changes: 10 additions & 1 deletion lib/aruba/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,20 @@
Then /^the output should match \/([^\/]*)\/$/ do |expected|
assert_matching_output(expected, all_output)
end

Then /^the output should match:$/ do |expected|
assert_matching_output(expected, all_output)
end

# The previous two steps antagonists
Then /^the output should not match \/([^\/]*)\/$/ do |expected|
assert_not_matching_output(expected, all_output)
end

Then /^the output should not match:$/ do |expected|
assert_not_matching_output(expected, all_output)
end

Then /^the exit status should be (\d+)$/ do |exit_status|
assert_exit_status(exit_status.to_i)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/aruba/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,19 @@ def announce_or_puts(*args)

end #with_file_content

describe "#assert_not_matching_output" do
before :each do
@aruba.run_simple("echo foo", false)
end

it "passes when the output doesn't match a regexp" do
@aruba.assert_not_matching_output "bar", @aruba.all_output
end
it "fails when the output does match a regexp" do
expect do
@aruba.assert_not_matching_output "foo", @aruba.all_output
end . to raise_error RSpec::Expectations::ExpectationNotMetError
end
end

end # Aruba::Api

0 comments on commit bb9f758

Please sign in to comment.