Add a_json_string matcher and improve tests

This commit is contained in:
alexbostock 2018-09-17 20:49:43 +01:00
parent e733657f04
commit 122738709a
3 changed files with 13 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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