Class: Shaf::Spec::PayloadUtils::Embedded

Inherits:
Object
  • Object
show all
Includes:
Minitest::Assertions, HttpMethodUtils, Shaf::Spec::PayloadUtils
Defined in:
lib/shaf/spec/payload_utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shaf::Spec::PayloadUtils

#assert_attribute, #assert_has_attribute, #assert_has_attributes, #assert_has_embedded, #assert_has_link, #assert_has_links, #assert_header, #assert_link, #assert_status, #attributes, #embedded, #embedded_each, #embedded_resources, #fill_form, #last_payload, #link_rels, #links, #refute_has_attribute, #refute_has_attributes, #refute_has_embedded, #refute_has_link, #refute_has_links, #set_payload

Methods included from HttpMethodUtils

#headers, #status

Constructor Details

#initialize(payload, context, block) ⇒ Embedded

Returns a new instance of Embedded.



17
18
19
20
21
22
# File 'lib/shaf/spec/payload_utils.rb', line 17

def initialize(payload, context, block)
  @payload = payload
  @context = context
  @block = block
  @assertions = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/shaf/spec/payload_utils.rb', line 28

def method_missing(method, *args, &block)
  if @context&.respond_to? method
    define_singleton_method(method) { |*a, &b| @context.public_send method, *a, &b }
    return public_send(method, *args, &block)
  end
  super
end

Instance Attribute Details

#assertionsObject

This is needed by Minitest::Assertions And we need that module to have all assert_/refute_ methods available in this class



15
16
17
# File 'lib/shaf/spec/payload_utils.rb', line 15

def assertions
  @assertions
end

Instance Method Details

#callObject



24
25
26
# File 'lib/shaf/spec/payload_utils.rb', line 24

def call
  instance_exec(&@block)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/shaf/spec/payload_utils.rb', line 36

def respond_to_missing?(method, include_private = false)
  return true if @context&.respond_to? method
  super
end