From d92d1b8f202da3c28b1b1327ec95432ba1166723 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sat, 3 Mar 2018 12:57:23 +0100 Subject: [PATCH 1/8] Remove obsolete RSpec version checks Aruba depends on rspec-expectations >= 3.4, so these version checks will always pass. --- lib/aruba/matchers/command/be_successfully_executed.rb | 4 +--- lib/aruba/matchers/command/have_finished_in_time.rb | 4 +--- lib/aruba/matchers/command/have_output.rb | 4 +--- lib/aruba/matchers/directory/be_an_existing_directory.rb | 4 +--- lib/aruba/matchers/directory/have_sub_directory.rb | 4 +--- lib/aruba/matchers/file/be_a_command_found_in_path.rb | 4 +--- lib/aruba/matchers/file/be_an_existing_executable.rb | 4 +--- lib/aruba/matchers/file/be_an_existing_file.rb | 4 +--- lib/aruba/matchers/file/have_file_content.rb | 4 +--- lib/aruba/matchers/file/have_file_size.rb | 4 +--- lib/aruba/matchers/file/have_same_file_content.rb | 4 +--- lib/aruba/matchers/path/a_path_matching_pattern.rb | 4 +--- lib/aruba/matchers/path/be_an_absolute_path.rb | 4 +--- lib/aruba/matchers/path/be_an_existing_path.rb | 4 +--- lib/aruba/matchers/path/have_permissions.rb | 4 +--- lib/aruba/matchers/string/include_output_string.rb | 6 ++---- lib/aruba/matchers/string/match_output_string.rb | 8 +++----- lib/aruba/matchers/string/output_string_eq.rb | 4 +--- 18 files changed, 21 insertions(+), 57 deletions(-) diff --git a/lib/aruba/matchers/command/be_successfully_executed.rb b/lib/aruba/matchers/command/be_successfully_executed.rb index 79f8c8f00..aafedc88c 100644 --- a/lib/aruba/matchers/command/be_successfully_executed.rb +++ b/lib/aruba/matchers/command/be_successfully_executed.rb @@ -29,6 +29,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.1' - RSpec::Matchers.define_negated_matcher :have_failed_running, :be_successfully_executed -end +RSpec::Matchers.define_negated_matcher :have_failed_running, :be_successfully_executed diff --git a/lib/aruba/matchers/command/have_finished_in_time.rb b/lib/aruba/matchers/command/have_finished_in_time.rb index 256d720ea..d1dc633c2 100644 --- a/lib/aruba/matchers/command/have_finished_in_time.rb +++ b/lib/aruba/matchers/command/have_finished_in_time.rb @@ -32,6 +32,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.1' - RSpec::Matchers.define_negated_matcher :run_too_long, :have_finished_in_time -end +RSpec::Matchers.define_negated_matcher :run_too_long, :have_finished_in_time diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb index cc2ccae6f..435f25984 100644 --- a/lib/aruba/matchers/command/have_output.rb +++ b/lib/aruba/matchers/command/have_output.rb @@ -31,6 +31,4 @@ description { "have output: #{description_of expected}" } end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :a_command_having_output, :have_output -end +RSpec::Matchers.alias_matcher :a_command_having_output, :have_output diff --git a/lib/aruba/matchers/directory/be_an_existing_directory.rb b/lib/aruba/matchers/directory/be_an_existing_directory.rb index a0e0ac9cf..b02c24206 100644 --- a/lib/aruba/matchers/directory/be_an_existing_directory.rb +++ b/lib/aruba/matchers/directory/be_an_existing_directory.rb @@ -33,6 +33,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :an_existing_directory, :be_an_existing_directory -end +RSpec::Matchers.alias_matcher :an_existing_directory, :be_an_existing_directory diff --git a/lib/aruba/matchers/directory/have_sub_directory.rb b/lib/aruba/matchers/directory/have_sub_directory.rb index 279939d18..b4ba2893c 100644 --- a/lib/aruba/matchers/directory/have_sub_directory.rb +++ b/lib/aruba/matchers/directory/have_sub_directory.rb @@ -48,6 +48,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :a_directory_having_sub_directory, :have_sub_directory -end +RSpec::Matchers.alias_matcher :a_directory_having_sub_directory, :have_sub_directory diff --git a/lib/aruba/matchers/file/be_a_command_found_in_path.rb b/lib/aruba/matchers/file/be_a_command_found_in_path.rb index 539bf0ece..3ea32da4b 100644 --- a/lib/aruba/matchers/file/be_a_command_found_in_path.rb +++ b/lib/aruba/matchers/file/be_a_command_found_in_path.rb @@ -31,6 +31,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :a_command_found_in_path, :be_a_command_found_in_path -end +RSpec::Matchers.alias_matcher :a_command_found_in_path, :be_a_command_found_in_path diff --git a/lib/aruba/matchers/file/be_an_existing_executable.rb b/lib/aruba/matchers/file/be_an_existing_executable.rb index 58ec4cb84..3ed072657 100644 --- a/lib/aruba/matchers/file/be_an_existing_executable.rb +++ b/lib/aruba/matchers/file/be_an_existing_executable.rb @@ -32,6 +32,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :an_existing_executable, :be_an_existing_executable -end +RSpec::Matchers.alias_matcher :an_existing_executable, :be_an_existing_executable diff --git a/lib/aruba/matchers/file/be_an_existing_file.rb b/lib/aruba/matchers/file/be_an_existing_file.rb index 5ce761a70..162240065 100644 --- a/lib/aruba/matchers/file/be_an_existing_file.rb +++ b/lib/aruba/matchers/file/be_an_existing_file.rb @@ -33,6 +33,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :an_existing_file, :be_an_existing_file -end +RSpec::Matchers.alias_matcher :an_existing_file, :be_an_existing_file diff --git a/lib/aruba/matchers/file/have_file_content.rb b/lib/aruba/matchers/file/have_file_content.rb index e31ce4c88..a81b75891 100644 --- a/lib/aruba/matchers/file/have_file_content.rb +++ b/lib/aruba/matchers/file/have_file_content.rb @@ -57,6 +57,4 @@ description { "have file content: #{description_of expected}" } end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :a_file_having_content, :have_file_content -end +RSpec::Matchers.alias_matcher :a_file_having_content, :have_file_content diff --git a/lib/aruba/matchers/file/have_file_size.rb b/lib/aruba/matchers/file/have_file_size.rb index 3a3f20bd8..e1a96875a 100644 --- a/lib/aruba/matchers/file/have_file_size.rb +++ b/lib/aruba/matchers/file/have_file_size.rb @@ -42,6 +42,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :a_file_of_size, :have_file_size -end +RSpec::Matchers.alias_matcher :a_file_of_size, :have_file_size diff --git a/lib/aruba/matchers/file/have_same_file_content.rb b/lib/aruba/matchers/file/have_same_file_content.rb index eaeebdc9f..8f19338b1 100644 --- a/lib/aruba/matchers/file/have_same_file_content.rb +++ b/lib/aruba/matchers/file/have_same_file_content.rb @@ -43,6 +43,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :a_file_with_same_content_like, :have_same_file_content_like -end +RSpec::Matchers.alias_matcher :a_file_with_same_content_like, :have_same_file_content_like diff --git a/lib/aruba/matchers/path/a_path_matching_pattern.rb b/lib/aruba/matchers/path/a_path_matching_pattern.rb index 1f1030578..2f5d43278 100644 --- a/lib/aruba/matchers/path/a_path_matching_pattern.rb +++ b/lib/aruba/matchers/path/a_path_matching_pattern.rb @@ -20,6 +20,4 @@ # RSpec.describe do # it { expect(files).to include a_path_matching_pattern /asdf/ } # end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :a_path_matching_pattern, :match -end +RSpec::Matchers.alias_matcher :a_path_matching_pattern, :match diff --git a/lib/aruba/matchers/path/be_an_absolute_path.rb b/lib/aruba/matchers/path/be_an_absolute_path.rb index e47a943f3..32445816d 100644 --- a/lib/aruba/matchers/path/be_an_absolute_path.rb +++ b/lib/aruba/matchers/path/be_an_absolute_path.rb @@ -31,6 +31,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :an_absolute_path, :be_an_absolute_path -end +RSpec::Matchers.alias_matcher :an_absolute_path, :be_an_absolute_path diff --git a/lib/aruba/matchers/path/be_an_existing_path.rb b/lib/aruba/matchers/path/be_an_existing_path.rb index 61ea695f1..aae920566 100644 --- a/lib/aruba/matchers/path/be_an_existing_path.rb +++ b/lib/aruba/matchers/path/be_an_existing_path.rb @@ -32,6 +32,4 @@ end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :an_existing_path, :be_an_existing_path -end +RSpec::Matchers.alias_matcher :an_existing_path, :be_an_existing_path diff --git a/lib/aruba/matchers/path/have_permissions.rb b/lib/aruba/matchers/path/have_permissions.rb index 066886b4b..95360b792 100644 --- a/lib/aruba/matchers/path/have_permissions.rb +++ b/lib/aruba/matchers/path/have_permissions.rb @@ -59,6 +59,4 @@ def permissions(file) end end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :a_path_having_permissions, :have_permissions -end +RSpec::Matchers.alias_matcher :a_path_having_permissions, :have_permissions diff --git a/lib/aruba/matchers/string/include_output_string.rb b/lib/aruba/matchers/string/include_output_string.rb index b59e0c9f3..26492ae41 100644 --- a/lib/aruba/matchers/string/include_output_string.rb +++ b/lib/aruba/matchers/string/include_output_string.rb @@ -30,7 +30,5 @@ description { "string includes: #{description_of expected}" } end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :an_output_string_including, :include_output_string - RSpec::Matchers.alias_matcher :file_content_including, :include_output_string -end +RSpec::Matchers.alias_matcher :an_output_string_including, :include_output_string +RSpec::Matchers.alias_matcher :file_content_including, :include_output_string diff --git a/lib/aruba/matchers/string/match_output_string.rb b/lib/aruba/matchers/string/match_output_string.rb index 7a58cd366..9d6f3c5c0 100644 --- a/lib/aruba/matchers/string/match_output_string.rb +++ b/lib/aruba/matchers/string/match_output_string.rb @@ -30,8 +30,6 @@ description { "output string matches: #{description_of expected}" } end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :an_output_string_matching, :match_output_string - RSpec::Matchers.alias_matcher :a_file_name_matching, :match_output_string - RSpec::Matchers.alias_matcher :file_content_matching, :match_output_string -end +RSpec::Matchers.alias_matcher :an_output_string_matching, :match_output_string +RSpec::Matchers.alias_matcher :a_file_name_matching, :match_output_string +RSpec::Matchers.alias_matcher :file_content_matching, :match_output_string diff --git a/lib/aruba/matchers/string/output_string_eq.rb b/lib/aruba/matchers/string/output_string_eq.rb index e23cca3d0..c36bcae34 100644 --- a/lib/aruba/matchers/string/output_string_eq.rb +++ b/lib/aruba/matchers/string/output_string_eq.rb @@ -30,6 +30,4 @@ description { "output string is eq: #{description_of expected}" } end -if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :an_output_string_being_eq, :output_string_eq -end +RSpec::Matchers.alias_matcher :an_output_string_being_eq, :output_string_eq From f8ea1143a86fec4bbf952c6489a88599981ec03d Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 4 Mar 2018 09:20:51 +0100 Subject: [PATCH 2/8] Remove duplicate scenario --- .../command/check_output_of_command.feature | 17 ----------------- 1 file changed, 17 deletions(-) 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 c369888e2..4a4117034 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 @@ -179,23 +179,6 @@ Feature: All output of commands which were executed When I run `cucumber` Then the features should all pass - Scenario: Detect subset of one-line output - Given an executable named "bin/aruba-test-cli" with: - """bash - #!/usr/bin/env bash - - echo 'hello world' - """ - And a file named "features/output.feature" with: - """cucumber - Feature: Run command - Scenario: Run command - When I run `aruba-test-cli` - Then the output should contain "hello world" - """ - When I run `cucumber` - Then the features should all pass - Scenario: Detect subset of one-line output with regex Given an executable named "bin/aruba-test-cli" with: """bash From ce54ddceec60aadeb50aae2b1bd9938707e294b5 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 4 Mar 2018 12:43:40 +0100 Subject: [PATCH 3/8] Fix failure output for single-line single-command case --- .../command/check_output_of_command.feature | 21 ++++++++++ lib/aruba/cucumber/command.rb | 41 ++++++++++++++----- 2 files changed, 51 insertions(+), 11 deletions(-) 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 4a4117034..cd71a4787 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 @@ -41,6 +41,27 @@ Feature: All output of commands which were executed When I run `cucumber` Then the features should all pass + Scenario: Failed detection of one-line output + Given an executable named "bin/aruba-test-cli" with: + """bash + #!/usr/bin/env bash + + echo 'hello world' + """ + And a file named "features/output.feature" with: + """cucumber + Feature: Run command + Scenario: Run command + When I run `aruba-test-cli` + Then the output should contain "goodbye world" + """ + When I run `cucumber` + Then the features should not all pass with: + """ + -/goodbye\ world/ + +"hello world" + """ + Scenario: Detect subset of multiline 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 10e89670a..5d1c73543 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -137,16 +137,26 @@ all_commands end - output_string_matcher = if exactly - :an_output_string_being_eq - else - :an_output_string_including - end + expected = unescape_text(expected) + expected = if exactly + expected + else + Regexp.new(Regexp.escape(expected)) + end - if negated - expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected)) + if commands.length == 1 + command = commands.first + if negated + expect(command).not_to send(matcher, expected) + else + expect(command).to send(matcher, expected) + end else - expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected)) + if negated + expect(commands).not_to include_an_object send(matcher, expected) + else + expect(commands).to include_an_object send(matcher, expected) + end end end @@ -178,10 +188,19 @@ :an_output_string_including end - if negated - expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected)) + if commands.length == 1 + command = commands.first + if negated + expect(command).not_to send(matcher, send(output_string_matcher, expected)) + else + expect(command).to send(matcher, send(output_string_matcher, expected)) + end else - expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected)) + if negated + expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected)) + else + expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected)) + end end end From 2b28ee0a80cc4a89f0afdf9a1bef0ee6afefaa91 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 4 Mar 2018 23:16:17 +0100 Subject: [PATCH 4/8] Special case include_an_object for single-element collections --- lib/aruba/matchers/collection/include_an_object.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/aruba/matchers/collection/include_an_object.rb b/lib/aruba/matchers/collection/include_an_object.rb index dfdfbe59d..0dd41f83a 100644 --- a/lib/aruba/matchers/collection/include_an_object.rb +++ b/lib/aruba/matchers/collection/include_an_object.rb @@ -19,7 +19,7 @@ class IncludeAnObject < BaseMatcher def initialize(matcher) @matcher = matcher - @failed_objects = {} + @failed_objects = [] @any_succeeded_object = false end @@ -30,8 +30,9 @@ def failure_message return "#{improve_hash_formatting(super)}, but was not iterable" end + return failed_objects.first if failed_objects.size == 1 all_messages = [improve_hash_formatting(super)] - failed_objects.each do |index, matcher_failure_message| + failed_objects.each_with_index do |matcher_failure_message, index| all_messages << failure_message_for_item(index, matcher_failure_message) end all_messages.join("\n\n") From 7f18cbdb346698e239815271f511ff7cdcd04536 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Sun, 4 Mar 2018 23:17:37 +0100 Subject: [PATCH 5/8] Make have_output failure message work nicely with include_an_object --- .../command/check_output_of_command.feature | 5 ++- lib/aruba/cucumber/command.rb | 41 +++++-------------- lib/aruba/matchers/base/message_indenter.rb | 19 +++++++++ .../matchers/collection/include_an_object.rb | 9 +--- lib/aruba/matchers/command/have_output.rb | 7 ++++ 5 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 lib/aruba/matchers/base/message_indenter.rb 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 cd71a4787..9f4f35c09 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 @@ -58,8 +58,9 @@ Feature: All output of commands which were executed When I run `cucumber` Then the features should not all pass with: """ - -/goodbye\ world/ - +"hello world" + expected `aruba-test-cli` to have output string includes: "goodbye world" + but was: + hello world (RSpec::Expectations::ExpectationNotMetError) """ Scenario: Detect subset of multiline output diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb index 5d1c73543..10e89670a 100644 --- a/lib/aruba/cucumber/command.rb +++ b/lib/aruba/cucumber/command.rb @@ -137,26 +137,16 @@ all_commands end - expected = unescape_text(expected) - expected = if exactly - expected - else - Regexp.new(Regexp.escape(expected)) - end + output_string_matcher = if exactly + :an_output_string_being_eq + else + :an_output_string_including + end - if commands.length == 1 - command = commands.first - if negated - expect(command).not_to send(matcher, expected) - else - expect(command).to send(matcher, expected) - end + if negated + expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected)) else - if negated - expect(commands).not_to include_an_object send(matcher, expected) - else - expect(commands).to include_an_object send(matcher, expected) - end + expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected)) end end @@ -188,19 +178,10 @@ :an_output_string_including end - if commands.length == 1 - command = commands.first - if negated - expect(command).not_to send(matcher, send(output_string_matcher, expected)) - else - expect(command).to send(matcher, send(output_string_matcher, expected)) - end + if negated + expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected)) else - if negated - expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected)) - else - expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected)) - end + expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected)) end end diff --git a/lib/aruba/matchers/base/message_indenter.rb b/lib/aruba/matchers/base/message_indenter.rb new file mode 100644 index 000000000..dce303504 --- /dev/null +++ b/lib/aruba/matchers/base/message_indenter.rb @@ -0,0 +1,19 @@ +module Aruba + module Matchers + module Base + # Provide #indent_multiline_message helper method. + # + # @api private + module MessageIndenter + module_function + + def indent_multiline_message(message) + message = message.sub(/\n+\z/, '') + message.lines.map do |line| + line =~ /\S/ ? ' ' + line : line + end.join + end + end + end + end +end diff --git a/lib/aruba/matchers/collection/include_an_object.rb b/lib/aruba/matchers/collection/include_an_object.rb index 0dd41f83a..42d5321e8 100644 --- a/lib/aruba/matchers/collection/include_an_object.rb +++ b/lib/aruba/matchers/collection/include_an_object.rb @@ -1,4 +1,5 @@ require 'aruba/matchers/base/base_matcher' +require 'aruba/matchers/base/message_indenter' # Aruba module Aruba @@ -8,6 +9,7 @@ module Matchers # Provides the implementation for `include_an_object`. # Not intended to be instantiated directly. class IncludeAnObject < BaseMatcher + include Base::MessageIndenter protected # @private @@ -93,13 +95,6 @@ def failure_message_for_item(index, failure_message) def add_new_line_if_needed(message) message.start_with?("\n") ? message : "\n#{message}" end - - def indent_multiline_message(message) - message = message.sub(/\n+\z/, '') - message.lines.map do |line| - line =~ /\S/ ? ' ' + line : line - end.join - end end end end diff --git a/lib/aruba/matchers/command/have_output.rb b/lib/aruba/matchers/command/have_output.rb index 435f25984..d97fccd92 100644 --- a/lib/aruba/matchers/command/have_output.rb +++ b/lib/aruba/matchers/command/have_output.rb @@ -1,3 +1,5 @@ +require 'aruba/matchers/base/message_indenter' + # @!method have_output # This matchers checks if has created output # @@ -29,6 +31,11 @@ diffable description { "have output: #{description_of expected}" } + + failure_message do |actual| + "expected `#{@old_actual.commandline}` to have output #{description_of expected}\n" \ + "but was:\n#{Aruba::Matchers::Base::MessageIndenter.indent_multiline_message @actual}" + end end RSpec::Matchers.alias_matcher :a_command_having_output, :have_output From 9d949cb4941216f30105d2891e8f1eed598cd899 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Mon, 5 Mar 2018 08:13:17 +0100 Subject: [PATCH 6/8] Add scenario for multi-line output --- .../command/check_output_of_command.feature | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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 9f4f35c09..d73178de4 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 @@ -201,6 +201,33 @@ Feature: All output of commands which were executed When I run `cucumber` Then the features should all pass + Scenario: Failed detection of exact multi-line output + Given an executable named "bin/aruba-test-cli" with: + """bash + #!/usr/bin/env bash + + echo -e "goodbye\nworld" + """ + And a file named "features/output.feature" with: + """cucumber + Feature: Run command + Scenario: Run command + When I run `aruba-test-cli` + Then the output should contain exactly: + \"\"\" + hello + world + \"\"\" + """ + When I run `cucumber` + Then the features should not all pass with: + """ + expected `aruba-test-cli` to have output output string is eq: "hello\nworld" + but was: + goodbye + world (RSpec::Expectations::ExpectationNotMetError) + """ + Scenario: Detect subset of one-line output with regex Given an executable named "bin/aruba-test-cli" with: """bash From b7e4ca54880d4c986d46a76672187727c7ff392d Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Mon, 5 Mar 2018 08:16:34 +0100 Subject: [PATCH 7/8] Remove scenario for internal matcher The include_an_object matcher is not part of Aruba's public API so should not be described in the feature files. --- .../collection/include_an_object.feature | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 features/05_use_rspec_matchers/collection/include_an_object.feature diff --git a/features/05_use_rspec_matchers/collection/include_an_object.feature b/features/05_use_rspec_matchers/collection/include_an_object.feature deleted file mode 100644 index b61cfbb37..000000000 --- a/features/05_use_rspec_matchers/collection/include_an_object.feature +++ /dev/null @@ -1,72 +0,0 @@ -Feature: `include_an_object` Matcher - - Use the `include_an_object` matcher to specify that a collection's objects include_an_object pass an expected matcher. - This works on include_an_object enumerable object. - - ```ruby - expect([1, 4, 5]).to include_an_object( be_odd ) - expect([1, 3, 'a']).to include_an_object( be_an(Integer) ) - expect([1, 3, 11]).to include_an_object( be < 10 ) - ``` - - The matcher also supports compound matchers: - - ```ruby - expect([1, 'a', 11]).to include_an_object( be_odd.and be < 10 ) - ``` - - Background: - Given I use a fixture named "cli-app" - - Scenario: Array usage - Given a file named "spec/array_include_an_object_matcher_spec.rb" with: - """ruby - require 'spec_helper' - - RSpec.describe [1, 4, 'a', 11] do - it { is_expected.to include_an_object( be_odd ) } - it { is_expected.to include_an_object( be_an(Integer) ) } - it { is_expected.to include_an_object( be < 10 ) } - it { is_expected.not_to include_an_object( eq 'b' ) } - end - - RSpec.describe [14, 'a'] do - it { is_expected.to include_an_object( be_odd ) } - it { is_expected.to include_an_object( be_an(Symbol) ) } - it { is_expected.to include_an_object( be < 10 ) } - it { is_expected.not_to include_an_object( eq 'a' ) } - end - """ - When I run `rspec` - Then the output should contain all of these lines: - | 8 examples, 4 failures | - | expected [14, "a"] to include an object be odd | - | expected [14, "a"] to include an object be a kind of Symbol | - | expected [14, "a"] to include an object be < 10 | - | expected [14, "a"] not to include an object eq "a" | - - Scenario: Compound Matcher Usage - Given a file named "spec/compound_include_an_object_matcher_spec.rb" with: - """ruby - require 'spec_helper' - - RSpec.describe [1, 'anything', 'something'] do - it { is_expected.to include_an_object( be_a(String).and include("thing") ) } - it { is_expected.to include_an_object( be_a(String).and end_with("g") ) } - it { is_expected.to include_an_object( start_with("s").or include("y") ) } - it { is_expected.not_to include_an_object( start_with("b").or include("b") ) } - end - - RSpec.describe ['anything', 'something'] do - it { is_expected.to include_an_object( be_a(Integer).and include("thing") ) } - it { is_expected.to include_an_object( be_a(Integer).and end_with("z") ) } - it { is_expected.to include_an_object( start_with("z").or include("1") ) } - it { is_expected.not_to include_an_object( start_with("a").or include("some") ) } - end - """ - When I run `rspec` - Then the output should contain all of these lines: - | 8 examples, 4 failures | - | expected ["anything", "something"] to include an object be a kind of Integer and include "thing" | - | expected ["anything", "something"] to include an object be a kind of Integer and end with "z" | - | expected ["anything", "something"] to include an object start with "z" or include "1" | From 435aa111b32c20847ea8438957d918cd53658ef3 Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Mon, 5 Mar 2018 09:20:55 +0100 Subject: [PATCH 8/8] Add specs for #include_an_object This is a replacement for the feature file which was removed. --- spec/aruba/matchers/collection_spec.rb | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/aruba/matchers/collection_spec.rb diff --git a/spec/aruba/matchers/collection_spec.rb b/spec/aruba/matchers/collection_spec.rb new file mode 100644 index 000000000..55cfe7c28 --- /dev/null +++ b/spec/aruba/matchers/collection_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' +require 'rspec/matchers/fail_matchers' + +RSpec.describe 'Collection Matchers' do + include RSpec::Matchers::FailMatchers + + describe '#include_an_object' do + context 'when succeeding' do + describe [1, 4, 'a', 11] do + it { is_expected.to include_an_object( be_odd ) } + it { is_expected.to include_an_object( be_an(Integer) ) } + it { is_expected.to include_an_object( be < 10 ) } + it { is_expected.not_to include_an_object( eq 'b' ) } + end + end + + context 'when failing' do + it 'emits failure messages for all candidate objects' do + expect { expect([14, 'a']).to include_an_object(be_odd) }. + to fail_with <<-MESSAGE.strip_heredoc.strip + expected [14, "a"] to include an object be odd + + object at index 0 failed to match: + expected `14.odd?` to return true, got false + + object at index 1 failed to match: + expected "a" to respond to `odd?` + MESSAGE + end + + it 'emits plain failure message when negated' do + expect { expect([14, 'a']).not_to include_an_object(be_even) }. + to fail_with 'expected [14, "a"] not to include an object be even' + end + + it 'skips boiler plate if only one candidate object is given' do + expect { expect([14]).to include_an_object(be_odd) }. + to fail_with "expected `14.odd?` to return true, got false" + end + end + + context 'when succeeding with compound matchers' do + describe [1, 'anything', 'something'] do + it { is_expected.to include_an_object( be_a(String).and include("thing") ) } + it { is_expected.to include_an_object( be_a(String).and end_with("g") ) } + it { is_expected.to include_an_object( start_with("q").or include("y") ) } + it { is_expected.not_to include_an_object( start_with("b").or include("b") ) } + end + end + end +end