-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite `have_output` matcher by composing built in matchers.
- Loading branch information
Showing
5 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
RSpec::Matchers.define :have_output do | ||
chain :to_s3 do |path| | ||
@s3_url = path.prepend('s3://com-example-pageflow-out') | ||
output_matchers[:url] = path.prepend('s3://com-example-pageflow-out') | ||
end | ||
|
||
chain :with_label do |label| | ||
output_matchers[:label] = label | ||
end | ||
|
||
chain :with_stream do |stream_attributes| | ||
output_matchers[:streams] = array_including(hash_including(stream_attributes)) | ||
end | ||
|
||
chain :with_all_streams_having do |stream_attributes| | ||
output_matchers[:streams] = all(include(stream_attributes)) | ||
end | ||
|
||
match do |definition| | ||
definition.outputs.detect { |output| output[:url] == @s3_url }.try(:any?) | ||
expect(definition.outputs).to include(hash_including(output_matchers)) | ||
end | ||
|
||
failure_message do |definition| | ||
urls = definition.outputs.map { |output| output[:url] } | ||
"expected to find URL #{@s3_url} in output URLs #{urls}." | ||
"expected #{description_of @actual} to #{description}#{pretty_print_actual(definition)}" | ||
end | ||
|
||
failure_message do |definition| | ||
"expected #{description_of @actual} not to #{description}#{pretty_print_actual(definition)}" | ||
end | ||
|
||
def pretty_print_actual(definition) | ||
"\n\nActual:\n#{JSON.pretty_generate(definition.outputs)}" | ||
end | ||
failure_message_when_negated do | ||
"expected to not find URL #{@s3_url} in output URLs, but found it." | ||
|
||
def output_matchers | ||
@matchers ||= {} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'uri' | ||
|
||
RSpec::Matchers.define :be_relative_url do | ||
match do |url| | ||
begin | ||
uri = URI.parse(url) | ||
uri.host.nil? && !uri.path.start_with?('/') | ||
rescue URI::InvalidURIError | ||
false | ||
end | ||
end | ||
end | ||
|
||
RSpec::Matchers.alias_matcher :a_relative_url, :be_relative_url |