Module: RSpec::ResemblesJsonMatchers

Defined in:
lib/rspec/resembles_json_matchers.rb,
lib/rspec/resembles_json_matchers/helpers.rb,
lib/rspec/resembles_json_matchers/matcherizer.rb,
lib/rspec/resembles_json_matchers/json_matcher.rb,
lib/rspec/resembles_json_matchers/string_indent.rb,
lib/rspec/resembles_json_matchers/attribute_differ.rb,
lib/rspec/resembles_json_matchers/attribute_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_nil_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_date_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_hash_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_array_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_class_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_route_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_any_of_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_string_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_boolean_matcher.rb,
lib/rspec/resembles_json_matchers/resembles_numeric_matcher.rb

Defined Under Namespace

Modules: Helpers, Matcherizer, StringIndent Classes: AttributeDiffer, AttributeMatcher, ExtraAttributeMatcher, JsonMatcher, MissingAttributeMatcher, ResemblesAllOfMatcher, ResemblesAnyOfMatcher, ResemblesArrayMatcher, ResemblesBooleanMatcher, ResemblesClassMatcher, ResemblesDateMatcher, ResemblesHashMatcher, ResemblesMatcher, ResemblesNilMatcher, ResemblesNumericMatcher, ResemblesRouteMatcher, ResemblesStringMatcher

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resembles_matcher_candidatesObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rspec/resembles_json_matchers.rb', line 35

def self.resembles_matcher_candidates
  # Order matters
  @resembles_matcher_candidates ||= [
    JsonMatcher,
    ResemblesAnyOfMatcher,
    ResemblesRouteMatcher,
    ResemblesDateMatcher,
    ResemblesNumericMatcher,
    ResemblesStringMatcher,
    ResemblesBooleanMatcher,
    ResemblesNilMatcher,
    ResemblesClassMatcher
  ].freeze
end

.resembles_matcher_for(expected, **_a) ⇒ Object



50
51
52
# File 'lib/rspec/resembles_json_matchers.rb', line 50

def self.resembles_matcher_for(expected, **_a)
  resembles_matcher_candidates.detect { |candidate| candidate.can_match?(expected) } || RSpec::Matchers::BuiltIn::Eq
end

Instance Method Details

#iso8601_timestampObject



21
22
23
# File 'lib/rspec/resembles_json_matchers.rb', line 21

def iso8601_timestamp
  match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/)
end

#match_json(*a) ⇒ Object Also known as: resemble_json



25
26
27
# File 'lib/rspec/resembles_json_matchers.rb', line 25

def match_json(*a)
  JsonMatcher.new(*a)
end

#resembleObject



33
34
35
# File 'lib/rspec/resembles_json_matchers.rb', line 33

def resembles(*a)
  RSpec::ResemblesJsonMatchers.resembles_matcher_for(*a).new(*a)
end

#resembles(expected) ⇒ Object



30
31
32
# File 'lib/rspec/resembles_json_matchers.rb', line 30

def resembles(*a)
  RSpec::ResemblesJsonMatchers.resembles_matcher_for(*a).new(*a)
end