From 403e18bebe3f407d04addfe0532d1d88b5e3f763 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Tue, 19 Nov 2024 21:22:51 +0100 Subject: [PATCH 1/2] Fix cucumber step ' should not contain anything' This fixes two things: - It requires all commands to have no output on the channel, not just one. - It improves the failure message so that it shows the actual output. --- .../command/check_stderr_of_command.feature | 20 +++++++++++++++++++ lib/aruba/cucumber/command.rb | 10 +++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/features/03_testing_frameworks/cucumber/steps/command/check_stderr_of_command.feature b/features/03_testing_frameworks/cucumber/steps/command/check_stderr_of_command.feature index 4eebfd64e..cc0e7aad9 100644 --- a/features/03_testing_frameworks/cucumber/steps/command/check_stderr_of_command.feature +++ b/features/03_testing_frameworks/cucumber/steps/command/check_stderr_of_command.feature @@ -66,3 +66,23 @@ Feature: STDERR of commands which were executed """ When I run `cucumber` Then the features should all pass + + Scenario: Failure message when checking that stderr from all processes is empty + Given a file named "features/output.feature" with: + """ + Feature: Run command + Scenario: Run command + When I run `bash -c 'printf "hello\nworld!\n" >&2'` + And I run `printf "hola"` + And the stderr should not contain anything + """ + When I run `cucumber` + Then the features should not pass with: + """ + expected "hello + world!" to output string is eq: "" + Diff: + @@ -1,2 +1,4 @@ + +hello + +world! + """ diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index 71459d5eb..1eb2fd4cc 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -450,14 +450,10 @@ expect(last_command_stopped).to have_output an_output_string_matching(expected) end -Then(/^(?:the )?(output|stderr|stdout) should not contain anything$/) do |channel| - matcher = case channel - when 'output'; then :have_output - when 'stderr'; then :have_output_on_stderr - when 'stdout'; then :have_output_on_stdout - end +Then '(the ){channel} should not contain anything' do |channel| + combined_output = send(:"all_#{channel}") - expect(all_commands).to include send(matcher, be_nil.or(be_empty)) + expect(combined_output).to output_string_eq '' end Then(/^(?:the )?(output|stdout|stderr) should( not)? contain all of these lines:$/) \ From 411fdc9f160adf48acd9f5cc65efdb7e2a5bb19a Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Wed, 20 Nov 2024 11:24:43 +0100 Subject: [PATCH 2/2] Fix cucumber step 'it should pass|fail with exactly:' This fixes the failure message of the output comparison so that it shows the correct diff. --- .../command/check_output_of_command.feature | 32 +++++++++++++++++++ lib/aruba/cucumber/command.rb | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/features/03_testing_frameworks/cucumber/steps/command/check_output_of_command.feature b/features/03_testing_frameworks/cucumber/steps/command/check_output_of_command.feature index 8061f9c81..3266514b5 100644 --- a/features/03_testing_frameworks/cucumber/steps/command/check_output_of_command.feature +++ b/features/03_testing_frameworks/cucumber/steps/command/check_output_of_command.feature @@ -327,6 +327,38 @@ Feature: All output of commands which were executed When I run `cucumber` Then the features should all pass + Scenario: Match passing exit status but fail to match exact output + Given an executable named "bin/aruba-test-cli" with: + """bash + #!/usr/bin/env bash + + echo -ne "hello\nworld" + exit 0 + """ + And a file named "features/output.feature" with: + """cucumber + Feature: Run command + Scenario: Run command + When I run `aruba-test-cli` + Then it should pass with exactly: + \"\"\" + hello + worl + \"\"\" + """ + When I run `cucumber` + Then the features should not pass with: + """ + expected "hello + world" to output string is eq: "hello + worl" + Diff: + @@ -1,3 +1,3 @@ + hello + -worl + +world + """ + Scenario: Match failing exit status and partial output Given an executable named "bin/aruba-test-cli" with: """bash diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index 1eb2fd4cc..1f9fc1827 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -423,7 +423,7 @@ expect(last_command_stopped).not_to be_successfully_executed end - expect(last_command_stopped).to have_output an_output_string_being_eq(expected) + expect(last_command_stopped.output).to output_string_eq(expected) end Then(/^it should not (pass|fail) (?:with regexp?|matching):$/) do |pass_fail, expected|