Skip to content

Commit 45307e6

Browse files
authored
Merge pull request #943 from cucumber/issue-942-improve-step-failure-messages
Improve two step failure messages
2 parents 6b05a86 + 411fdc9 commit 45307e6

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

features/03_testing_frameworks/cucumber/steps/command/check_output_of_command.feature

+32
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,38 @@ Feature: All output of commands which were executed
327327
When I run `cucumber`
328328
Then the features should all pass
329329

330+
Scenario: Match passing exit status but fail to match exact output
331+
Given an executable named "bin/aruba-test-cli" with:
332+
"""bash
333+
#!/usr/bin/env bash
334+
335+
echo -ne "hello\nworld"
336+
exit 0
337+
"""
338+
And a file named "features/output.feature" with:
339+
"""cucumber
340+
Feature: Run command
341+
Scenario: Run command
342+
When I run `aruba-test-cli`
343+
Then it should pass with exactly:
344+
\"\"\"
345+
hello
346+
worl
347+
\"\"\"
348+
"""
349+
When I run `cucumber`
350+
Then the features should not pass with:
351+
"""
352+
expected "hello
353+
world" to output string is eq: "hello
354+
worl"
355+
Diff:
356+
@@ -1,3 +1,3 @@
357+
hello
358+
-worl
359+
+world
360+
"""
361+
330362
Scenario: Match failing exit status and partial output
331363
Given an executable named "bin/aruba-test-cli" with:
332364
"""bash

features/03_testing_frameworks/cucumber/steps/command/check_stderr_of_command.feature

+20
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,23 @@ Feature: STDERR of commands which were executed
6666
"""
6767
When I run `cucumber`
6868
Then the features should all pass
69+
70+
Scenario: Failure message when checking that stderr from all processes is empty
71+
Given a file named "features/output.feature" with:
72+
"""
73+
Feature: Run command
74+
Scenario: Run command
75+
When I run `bash -c 'printf "hello\nworld!\n" >&2'`
76+
And I run `printf "hola"`
77+
And the stderr should not contain anything
78+
"""
79+
When I run `cucumber`
80+
Then the features should not pass with:
81+
"""
82+
expected "hello
83+
world!" to output string is eq: ""
84+
Diff:
85+
@@ -1,2 +1,4 @@
86+
+hello
87+
+world!
88+
"""

lib/aruba/cucumber/command.rb

+4-8
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
expect(last_command_stopped).not_to be_successfully_executed
424424
end
425425

426-
expect(last_command_stopped).to have_output an_output_string_being_eq(expected)
426+
expect(last_command_stopped.output).to output_string_eq(expected)
427427
end
428428

429429
Then(/^it should not (pass|fail) (?:with regexp?|matching):$/) do |pass_fail, expected|
@@ -450,14 +450,10 @@
450450
expect(last_command_stopped).to have_output an_output_string_matching(expected)
451451
end
452452

453-
Then(/^(?:the )?(output|stderr|stdout) should not contain anything$/) do |channel|
454-
matcher = case channel
455-
when 'output'; then :have_output
456-
when 'stderr'; then :have_output_on_stderr
457-
when 'stdout'; then :have_output_on_stdout
458-
end
453+
Then '(the ){channel} should not contain anything' do |channel|
454+
combined_output = send(:"all_#{channel}")
459455

460-
expect(all_commands).to include send(matcher, be_nil.or(be_empty))
456+
expect(combined_output).to output_string_eq ''
461457
end
462458

463459
Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:$/) \

0 commit comments

Comments
 (0)