Class: RSpec::JsonMatchers::Expectation Abstract

Inherits:
Object
  • Object
show all
Extended by:
AbstractClass
Defined in:
lib/rspec/json_matchers/expectation.rb

Overview

This class is abstract.

This class MUST be used after being inherited Subclasses MUST override #expect? to allow this gem to determine the test result

Represents an expectation of an object (usually called expected) Built to avoid Object#=== usage like other matcher gems, like rspec-json_matcher Actually rspec-mocks 3.x also uses it, but only internally

API:

  • This class can be extended to create custom kinds of expectation But only used for this gem

Defined Under Namespace

Classes: Builder

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(value) ⇒ Expectation

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

“Build” an expectation object (not class) depends on value

Parameters:

  • expected value, could be an expectation object as well

Returns:

API:

  • private



44
45
46
# File 'lib/rspec/json_matchers/expectation.rb', line 44

def build(value)
  Builder.new(value).build
end

.build_many(values) ⇒ Array<Expectation>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

“Build” expectation objects (not classes) depending on values

Returns:

See Also:

API:

  • private



53
54
55
# File 'lib/rspec/json_matchers/expectation.rb', line 53

def build_many(values)
  values.flat_map { |v| build(v) }
end

Instance Method Details

#expect?(_value) ⇒ Bool

This method is abstract.

This method MUST be overridden to allow this gem to determine the test result

Determine the value passed in is “expected” by self or not And return the result

Parameters:

  • actual value to be evaluated

Returns:

  • Whether the value is expected

API:

  • This class can be extended to create custom kinds of expectation But only used for this gem



31
32
33
# File 'lib/rspec/json_matchers/expectation.rb', line 31

def expect?(_value)
  fail NotImplementedError
end