Module: Dockerspec::Builder::Matchers::MatcherHelpers
- Defined in:
- lib/dockerspec/builder/matchers/helpers.rb
Overview
Some helpers methods for the Docker build RSpec matchers.
Instance Method Summary collapse
-
#maybe_json?(got, expected) ⇒ Boolean
A matcher to check JSON values like
CMD
andENTRYPOINT
. -
#sub_hash?(hash, sub_hash) ⇒ Boolean
Checks whether a hash is a subhash of another.
Instance Method Details
#maybe_json?(got, expected) ⇒ Boolean
A matcher to check JSON values like CMD
and ENTRYPOINT
.
The expected value can be in JSON (a Ruby array) or in String format just like in the Dockerfile.
The real (got) value will always be in array format.
81 82 83 84 |
# File 'lib/dockerspec/builder/matchers/helpers.rb', line 81 def maybe_json?(got, expected) return expected == got if expected.is_a?(Array) !expected.match(got.join(' ')).nil? end |
#sub_hash?(hash, sub_hash) ⇒ Boolean
Checks whether a hash is a subhash of another.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dockerspec/builder/matchers/helpers.rb', line 47 def sub_hash?(hash, sub_hash) sub_hash.all? do |sub_hash_key, sub_hash_value| next false unless hash.key?(sub_hash_key) if sub_hash_value.respond_to?(:match) !sub_hash_value.match(hash[sub_hash_key]).nil? else sub_hash_value == hash[sub_hash_key] end end end |