Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/exceptions.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/inputs.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/outputs.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/delegation.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matchers/base.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matcher_collection.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matchers/arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/commands/generate_printable_method.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matchers/without_arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matchers/with_any_arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matchers/return_custom_value.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matchers/return_delegation_value.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matchers/with_concrete_arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matchers/arguments/commands/generate_printable_arguments.rb,
lib/convenient_service/rspec/primitive_matchers/classes/delegate_to/entities/sub_matchers/arguments/commands/apply_stub_to_track_delegations.rb

Defined Under Namespace

Modules: Commands, Entities, Exceptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method, block_expectation = proc { Support::UNDEFINED }) ⇒ void

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.

Parameters:

  • object (Object)
  • method (String, Symbol)
  • block_expectation (Proc) (defaults to: proc { Support::UNDEFINED })


66
67
68
69
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 66

def initialize(object, method, block_expectation = proc { Support::UNDEFINED })
  @inputs = Entities::Inputs.new(object: object, method: method, block_expectation: block_expectation)
  @outputs = Entities::Outputs.new
end

Instance Attribute Details

#inputsObject (readonly)

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.



42
43
44
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 42

def inputs
  @inputs
end

#outputsObject (readonly)

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.



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

def outputs
  @outputs
end

Instance Method Details

#==(other) ⇒ Boolean?

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.

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


246
247
248
249
250
251
252
253
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 246

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

  return false if inputs != other.inputs
  return false if outputs != other.outputs

  true
end

#and_returnConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo



195
196
197
198
199
200
201
202
203
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 195

def and_return(...)
  ::ConvenientService.raise Exceptions::ReturnValueChainingIsAlreadySet.new if sub_matchers.has_return_value?

  inputs.update_expected_return_value_block(...)

  sub_matchers.return_value = Entities::SubMatchers::ReturnCustomValue.new(matcher: self)

  self
end

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



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

def and_return_its_value
  ::ConvenientService.raise Exceptions::ReturnValueChainingIsAlreadySet.new if sub_matchers.has_return_value?

  sub_matchers.return_value = Entities::SubMatchers::ReturnDelegationValue.new(matcher: self)

  self
end

#descriptionString

Returns:

  • (String)


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

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

#does_not_match?(block_expectation) ⇒ Boolean

Parameters:

  • block_expectation (Proc)

Returns:

  • (Boolean)


89
90
91
92
93
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 89

def does_not_match?(block_expectation)
  inputs.block_expectation = block_expectation

  !sub_matchers.matches?(inputs.block_expectation)
end

#failure_messageString

Returns:

  • (String)


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

def failure_message
  sub_matchers.failure_message
end

#failure_message_when_negatedString

Returns:

  • (String)


129
130
131
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 129

def failure_message_when_negated
  sub_matchers.failure_message_when_negated
end

#matches?(block_expectation) ⇒ Boolean

Parameters:

  • block_expectation (Proc)

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 77

def matches?(block_expectation)
  inputs.block_expectation = block_expectation

  sub_matchers.matches?(inputs.block_expectation)
end

#sub_matchersConvenientService::RSpec::PrimitiveMatchers::Classes::DelegateTo::Entities::SubMatchers

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.



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

def sub_matchers
  @sub_matchers ||= Entities::SubMatcherCollection.new(matcher: self)
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 102

def supports_block_expectations?
  true
end

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



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

def with_any_arguments
  ::ConvenientService.raise Exceptions::ArgumentsChainingIsAlreadySet.new if sub_matchers.has_arguments?

  sub_matchers.arguments = Entities::SubMatchers::WithAnyArguments.new(matcher: self)

  self
end

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



139
140
141
142
143
144
145
146
147
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 139

def with_arguments(...)
  ::ConvenientService.raise Exceptions::ArgumentsChainingIsAlreadySet.new if sub_matchers.has_arguments?

  inputs.expected_arguments = Support::Arguments.new(...)

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

  self
end

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



210
211
212
213
214
215
216
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 210

def with_calling_original
  ::ConvenientService.raise Exceptions::CallOriginalChainingIsAlreadySet.new if inputs.has_call_original?

  inputs.should_call_original = true

  self
end

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



169
170
171
172
173
174
175
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 169

def without_arguments
  ::ConvenientService.raise Exceptions::ArgumentsChainingIsAlreadySet.new if sub_matchers.has_arguments?

  sub_matchers.arguments = Entities::SubMatchers::WithoutArguments.new(matcher: self)

  self
end

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



223
224
225
226
227
228
229
# File 'lib/convenient_service/rspec/primitive_matchers/classes/delegate_to.rb', line 223

def without_calling_original
  ::ConvenientService.raise Exceptions::CallOriginalChainingIsAlreadySet.new if inputs.has_call_original?

  inputs.should_call_original = false

  self
end