Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Entities::Matcher

Inherits:
Object
  • Object
show all
Includes:
Support::Delegate
Defined in:
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/delegation.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings_collection.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/values/base.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/commands/generate_printable_method.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/sub_matchers/base.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings_collection/exceptions.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/values/with_calling_original.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/sub_matchers/return_its_value.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/sub_matchers/without_arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/sub_matchers/with_any_arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/values/without_calling_original.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/sub_matchers/with_concrete_arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands/generate_printable_arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher/entities/chainings/sub_matchers/arguments/commands/apply_stub_to_track_delegations.rb

Defined Under Namespace

Modules: Commands, Entities

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Concern

included

Constructor Details

#initialize(object, method, block_expectation = nil) ⇒ void

Parameters:

  • object (Object)
  • method (String, Symbol)
  • block_expectation (Proc) (defaults to: nil)


76
77
78
79
80
81
82
83
84
85
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 76

def initialize(object, method, block_expectation = nil)
  ##
  # TODO: `raise unless object.respond_to?(method)`.
  # TODO: `any_block`.
  # TODO: `with_warmup`.
  #
  @object = object
  @method = method
  @block_expectation = block_expectation
end

Instance Attribute Details

#block_expectationObject (readonly)

Returns the value of attribute block_expectation.



63
64
65
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 63

def block_expectation
  @block_expectation
end

#methodObject (readonly)

Returns the value of attribute method.



57
58
59
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 57

def method
  @method
end

#objectObject (readonly)

Returns the value of attribute object.



51
52
53
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 51

def object
  @object
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


261
262
263
264
265
266
267
268
269
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 261

def ==(other)
  return unless other.instance_of?(self.class)

  return false if object != other.object
  return false if method != other.method
  return false if block_expectation != other.block_expectation

  true
end

#and_return_its_valueConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo

Returns:

Raises:

  • (ConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Exceptions::ReturnItsValueChainingIsAlreadySet)


166
167
168
169
170
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 166

def and_return_its_value
  chainings.return_its_value = Entities::Chainings::SubMatchers::ReturnItsValue.new(matcher: self)

  self
end

#chainingsConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Entities::Matcher::Entities::Chainings

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.



228
229
230
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 228

def chainings
  @chainings ||= Entities::ChainingsCollection.new(matcher: self)
end

#delegation_valueObject

Returns Can be any type.

Returns:

  • (Object)

    Can be any type.



213
214
215
216
217
218
219
220
221
222
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 213

def delegation_value
  Utils::Object.memoize_including_falsy_values(self, :@delegation_value) do
    object.__send__(
      method,
      *expected_arguments.args,
      **expected_arguments.kwargs,
      &expected_arguments.block
    )
  end
end

#delegationsArray

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.

Returns:

  • (Array)


236
237
238
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 236

def delegations
  @delegations ||= []
end

#descriptionString

Returns:

  • (String)


112
113
114
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 112

def description
  "delegate to `#{printable_method}`"
end

#expected_argumentsConvenientService::Support::Arguments



193
194
195
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 193

def expected_arguments
  @expected_arguments ||= Support::Arguments.null_arguments
end

#expected_arguments=(arguments) ⇒ ConvenientService::Support::Arguments



201
202
203
204
205
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 201

def expected_arguments=(arguments)
  Utils::Object.instance_variable_delete(self, :@delegation_value)

  @expected_arguments = arguments
end

#failure_messageString

Returns:

  • (String)


119
120
121
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 119

def failure_message
  chainings.failure_message
end

#failure_message_when_negatedString

Returns:

  • (String)


126
127
128
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 126

def failure_message_when_negated
  chainings.failure_message_when_negated
end

#matches?(block_expectation) ⇒ Boolean

Parameters:

  • block_expectation (Proc)

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 91

def matches?(block_expectation)
  @block_expectation = block_expectation

  chainings.arguments = Entities::Chainings::SubMatchers::WithAnyArguments.new(matcher: self) unless chainings.has_arguments?
  chainings.call_original = Entities::Chainings::Values::WithCallingOriginal.new(matcher: self) unless chainings.has_call_original?

  chainings.sub_matchers_match?(block_expectation)
end

#printable_block_expectationString

Returns:

  • (String)


250
251
252
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 250

def printable_block_expectation
  @printable_block_expectation ||= Utils::Proc.display(block_expectation)
end

#printable_methodString

Returns:

  • (String)


243
244
245
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 243

def printable_method
  @printable_method ||= Commands::GeneratePrintableMethod.call(object: object, method: method)
end

#should_call_original?Boolean

Returns:

  • (Boolean)


68
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 68

delegate :should_call_original?, to: :chainings

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 105

def supports_block_expectations?
  true
end

#with_any_argumentsConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo

Returns:

Raises:

  • (ConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Exceptions::ArgumentsChainingIsAlreadySet)


146
147
148
149
150
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 146

def with_any_arguments
  chainings.arguments = Entities::Chainings::SubMatchers::WithAnyArguments.new(matcher: self)

  self
end

#with_argumentsConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo

Returns:

Raises:

  • (ConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Exceptions::ArgumentsChainingIsAlreadySet)


134
135
136
137
138
139
140
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 134

def with_arguments(...)
  self.expected_arguments = Support::Arguments.new(...)

  chainings.arguments = Entities::Chainings::SubMatchers::WithConcreteArguments.new(matcher: self)

  self
end

#with_calling_originalConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo



175
176
177
178
179
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 175

def with_calling_original
  chainings.call_original = Entities::Chainings::Values::WithCallingOriginal.new(matcher: self)

  self
end

#without_argumentsConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo

Returns:

Raises:

  • (ConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Exceptions::ArgumentsChainingIsAlreadySet)


156
157
158
159
160
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 156

def without_arguments
  chainings.arguments = Entities::Chainings::SubMatchers::WithoutArguments.new(matcher: self)

  self
end

#without_calling_originalConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo



184
185
186
187
188
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/matcher.rb', line 184

def without_calling_original
  chainings.call_original = Entities::Chainings::Values::WithoutCallingOriginal.new(matcher: self)

  self
end