Class: ConvenientService::RSpec::Matchers::Classes::Results::Base

Inherits:
Object
  • Object
show all
Includes:
Support::AbstractMethod
Defined in:
lib/convenient_service/rspec/matchers/classes/results/base.rb,
lib/convenient_service/rspec/matchers/classes/results/base/constants.rb,
lib/convenient_service/rspec/matchers/classes/results/base/exceptions.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/chain.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/validator.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/null.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/error.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/failure.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/success.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result_code.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result_data.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result_step.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result_type.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_got_parts.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result_status.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result_message.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/validator/commands/validate_result_service.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_got_step_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_expected_parts.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_got_service_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_expected_code_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_expected_data_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_expected_step_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_expected_status_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_expected_message_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/base/commands/generate_expected_service_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/error/commands/generate_got_jsend_attributes_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/failure/commands/generate_got_jsend_attributes_part.rb,
lib/convenient_service/rspec/matchers/classes/results/base/entities/printers/success/commands/generate_got_jsend_attributes_part.rb

Defined Under Namespace

Modules: Constants, Entities, Exceptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Concern

included

Constructor Details

#initialize(statuses: self.statuses, result: nil) ⇒ 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.



35
36
37
38
39
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 35

def initialize(statuses: self.statuses, result: nil)
  chain.statuses = statuses

  @result = result
end

Instance Attribute Details

#resultObject (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.



21
22
23
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 21

def result
  @result
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)


267
268
269
270
271
272
273
274
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 267

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

  return false if chain != other.chain
  return false if result != other.result

  true
end

#and_code(code) ⇒ String, ...



181
182
183
184
185
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 181

def and_code(code)
  chain.code = code

  self
end

#and_data(data) ⇒ ConvenientService::RSpec::Matchers::Classes::Results::Base



122
123
124
125
126
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 122

def and_data(data)
  chain.data = data

  self
end

#and_message(message) ⇒ ConvenientService::RSpec::Matchers::Classes::Results::Base

Parameters:

  • message (String)

Returns:



157
158
159
160
161
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 157

def and_message(message)
  chain.message = message

  self
end

#chainConvenientService::RSpec::Matchers::Classes::Results::Base::Entities::Chain

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.



239
240
241
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 239

def chain
  @chain ||= Entities::Chain.new
end

#comparing_by(comparison_method) ⇒ ConvenientService::RSpec::Matchers::Classes::Results::Base

Parameters:

  • comparison_method (Symbo, String)

Returns:



228
229
230
231
232
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 228

def comparing_by(comparison_method)
  chain.comparison_method = comparison_method

  self
end

#descriptionString

Returns:

  • (String)


79
80
81
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 79

def description
  printer.description
end

#failure_messageString

Returns:

  • (String)


88
89
90
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 88

def failure_message
  printer.failure_message
end

#failure_message_when_negatedString

Returns:

  • (String)


100
101
102
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 100

def failure_message_when_negated
  printer.failure_message_when_negated
end

#matches?(result) ⇒ Boolean



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 47

def matches?(result)
  @result = result

  ##
  # IMPORTANT: Makes `result.class.include?` idempotent.
  #
  # TODO: Explainer when `result.class.commit_config!` is required. It was introduced in panic when the first thread-safety issues occurred. Looks like it is an outdated operation now. It is probably useful only when a config has almost zero plugins.
  #
  # TODO: Resolve a bug in `delegate_to`. It makes `respond_to?` always return `true`, even for classes that do NOT have the `commit_config!` method. See specs for details.
  #
  #   let(:result) { "foo" }
  #
  #   specify do
  #     expect { matcher.matches?(result) }
  #       .not_to delegate_to(result.class, :commit_config!)
  #       .with_any_arguments
  #       .without_calling_original
  #   end
  #
  #   `result.class.method(:commit_config!)`
  #   # => <Method: String.commit_config!(*args, &block) /usr/local/bundle/gems/rspec-mocks-3.11.2/lib/rspec/mocks/method_double.rb:63>
  #
  result.class.commit_config!(trigger: Constants::Triggers::BE_RESULT) if result.class.respond_to?(:commit_config!)

  validator.valid_result?
end

#of_service(service) ⇒ ConvenientService::RSpec::Matchers::Classes::Results::Base



193
194
195
196
197
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 193

def of_service(service)
  chain.service = service

  self
end

#of_step(step) ⇒ ConvenientService::RSpec::Matchers::Classes::Results::Base

Parameters:

  • step (Class, Symbol)

Returns:



205
206
207
208
209
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 205

def of_step(step)
  chain.step = step

  self
end

#printerConvenientService::RSpec::Matchers::Classes::Results::Base::Entities::Printers::Base

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.



248
249
250
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 248

def printer
  @printer ||= Entities::Printers.create(matcher: self)
end

#statusesString, Symbol

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:

  • (String, Symbol)


28
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 28

abstract_method :statuses

#validatorConvenientService::RSpec::Matchers::Classes::Results::Base::Entities::Validator

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.



257
258
259
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 257

def validator
  @validator ||= Entities::Validator.new(matcher: self)
end

#with_code(code) ⇒ String, ...



169
170
171
172
173
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 169

def with_code(code)
  chain.code = code

  self
end

#with_data(data) ⇒ ConvenientService::RSpec::Matchers::Classes::Results::Base



110
111
112
113
114
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 110

def with_data(data)
  chain.data = data

  self
end

#with_message(message) ⇒ ConvenientService::RSpec::Matchers::Classes::Results::Base

Parameters:

  • message (String)

Returns:



145
146
147
148
149
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 145

def with_message(message)
  chain.message = message

  self
end

#without_dataConvenientService::RSpec::Matchers::Classes::Results::Base



133
134
135
136
137
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 133

def without_data
  chain.data = {}

  self
end

#without_stepConvenientService::RSpec::Matchers::Classes::Results::Base



216
217
218
219
220
# File 'lib/convenient_service/rspec/matchers/classes/results/base.rb', line 216

def without_step
  chain.step = nil

  self
end