From 122738709af77adcd488a5b2062203e1fe5e4ef1 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Mon, 17 Sep 2018 20:49:43 +0100 Subject: [PATCH] Add a_json_string matcher and improve tests --- Library/Homebrew/test/cmd/commands_spec.rb | 3 +-- Library/Homebrew/test/cmd/info_spec.rb | 2 +- Library/Homebrew/test/spec_helper.rb | 11 +++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index c1407798bb..47bef3a340 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -11,12 +11,11 @@ describe "brew commands", :integration_test do end it "prints a list without headers with the --quiet flag" do - expect { brew "commands", "--quiet" } - .to_not output(/Built-in commands/).to_stdout expect { brew "commands", "--quiet" } .to be_a_success .and not_to_output.to_stderr + .and not_to_output(/Built-in commands/).to_stdout end end diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index 1822aab1b4..2d091de2ed 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -14,7 +14,7 @@ describe "brew info", :integration_test do it "prints as json with the --json=v1 flag" do expect { brew "info", "testball", "--json=v1" } - .to output(/\{.+testball.+\}/).to_stdout + .to output(a_json_string).to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 20bdf95983..c084b1e551 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -171,3 +171,14 @@ end RSpec::Matchers.define_negated_matcher :not_to_output, :output RSpec::Matchers.alias_matcher :have_failed, :be_failed RSpec::Matchers.alias_matcher :a_string_containing, :include + +RSpec::Matchers.define :a_json_string do + match do |actual| + begin + JSON.parse(actual) + true + rescue JSON::ParseError + false + end + end +end