From 6e1374bef9016721ad56d4576397d9524d68c040 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Sun, 16 Sep 2018 21:41:50 +0100 Subject: [PATCH 1/6] Add multiple arguments test for brew cat --- Library/Homebrew/test/cmd/cat_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Library/Homebrew/test/cmd/cat_spec.rb b/Library/Homebrew/test/cmd/cat_spec.rb index 8c230abee2..f88e8b53a4 100644 --- a/Library/Homebrew/test/cmd/cat_spec.rb +++ b/Library/Homebrew/test/cmd/cat_spec.rb @@ -8,4 +8,13 @@ describe "brew cat", :integration_test do .and not_to_output.to_stderr .and be_a_success end + + it "fails when given multiple arguments" do + setup_test_formula "foo" + setup_test_formula "bar" + expect { brew "cat", "foo", "bar" } + .to output(/doesn't support multiple arguments/).to_stderr + .and not_to_output.to_stdout + .and be_a_failure + end end From 193b5aa07ac9e278dfe123d03566c14572321deb Mon Sep 17 00:00:00 2001 From: alexbostock Date: Sun, 16 Sep 2018 21:54:19 +0100 Subject: [PATCH 2/6] Add test for brew commands --quiet --- Library/Homebrew/test/cmd/commands_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index 07844087f0..ab3dd1bce9 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -6,6 +6,12 @@ describe "brew commands", :integration_test do it "prints a list of all available commands" do expect { brew "commands" } .to output(/Built-in commands/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + + expect { brew "commands", "--quiet" } + .to output.to_stdout + .and not_to_output.to_stderr .and be_a_success end end From a4020db526fc8476b4c8606a1f0c6473e1a197c8 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Sun, 16 Sep 2018 22:06:42 +0100 Subject: [PATCH 3/6] Add test for brew info --json=v1 --- Library/Homebrew/test/cmd/info_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index 8deef3d23b..be8912c0a0 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -8,6 +8,11 @@ describe "brew info", :integration_test do .to output(/testball: stable 0.1/).to_stdout .and not_to_output.to_stderr .and be_a_success + + expect { brew "info", "testball", "--json=v1" } + .to output(/\{.+testball.+\}/).to_stdout + .and not_to_output.to_stderr + .and be_a_success end end From e733657f046d79b4be94ab006428174b917ec216 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Mon, 17 Sep 2018 09:50:02 +0100 Subject: [PATCH 4/6] Separate and improve tests --- Library/Homebrew/test/cmd/commands_spec.rb | 8 ++++++-- Library/Homebrew/test/cmd/info_spec.rb | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index ab3dd1bce9..c1407798bb 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -8,11 +8,15 @@ describe "brew commands", :integration_test do .to output(/Built-in commands/).to_stdout .and not_to_output.to_stderr .and be_a_success + 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 output.to_stdout + .to be_a_success .and not_to_output.to_stderr - .and be_a_success end end diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index be8912c0a0..1822aab1b4 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -1,14 +1,18 @@ require "cmd/info" describe "brew info", :integration_test do - it "prints information about a given Formula" do + before do setup_test_formula "testball" + end + it "prints information about a given Formula" do expect { brew "info", "testball" } .to output(/testball: stable 0.1/).to_stdout .and not_to_output.to_stderr .and be_a_success + end + it "prints as json with the --json=v1 flag" do expect { brew "info", "testball", "--json=v1" } .to output(/\{.+testball.+\}/).to_stdout .and not_to_output.to_stderr From 122738709af77adcd488a5b2062203e1fe5e4ef1 Mon Sep 17 00:00:00 2001 From: alexbostock Date: Mon, 17 Sep 2018 20:49:43 +0100 Subject: [PATCH 5/6] 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 From 188aca10759f5b1efee03b4c176b6bafcd71357b Mon Sep 17 00:00:00 2001 From: alexbostock Date: Mon, 17 Sep 2018 21:13:19 +0100 Subject: [PATCH 6/6] Remove blank line --- Library/Homebrew/test/cmd/commands_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index 47bef3a340..5e2ce47dbd 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -11,7 +11,6 @@ describe "brew commands", :integration_test do end it "prints a list without headers with the --quiet flag" do - expect { brew "commands", "--quiet" } .to be_a_success .and not_to_output.to_stderr