Class: ShouldaRenderJsonObjectMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda_render_json_object_matcher.rb

Direct Known Subclasses

ShouldaRenderJsonArrayMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, options = {}) ⇒ ShouldaRenderJsonObjectMatcher

Returns a new instance of ShouldaRenderJsonObjectMatcher.



4
5
6
7
8
9
10
11
12
# File 'lib/shoulda_render_json_object_matcher.rb', line 4

def initialize(root, options = {})
  @options = options
  # Coercing types root: Symbol, keys: Array of Symbols
  @root = root.to_s
  @keys = {
    required: massage_options(:required),
    forbidden: massage_options(:forbidden),
  }
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



2
3
4
# File 'lib/shoulda_render_json_object_matcher.rb', line 2

def context
  @context
end

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



2
3
4
# File 'lib/shoulda_render_json_object_matcher.rb', line 2

def failure_message
  @failure_message
end

#keysObject (readonly)

Returns the value of attribute keys.



2
3
4
# File 'lib/shoulda_render_json_object_matcher.rb', line 2

def keys
  @keys
end

#negative_failure_messageObject (readonly)

Returns the value of attribute negative_failure_message.



2
3
4
# File 'lib/shoulda_render_json_object_matcher.rb', line 2

def negative_failure_message
  @negative_failure_message
end

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/shoulda_render_json_object_matcher.rb', line 2

def options
  @options
end

#responseObject (readonly)

Returns the value of attribute response.



2
3
4
# File 'lib/shoulda_render_json_object_matcher.rb', line 2

def response
  @response
end

#rootObject (readonly)

Returns the value of attribute root.



2
3
4
# File 'lib/shoulda_render_json_object_matcher.rb', line 2

def root
  @root
end

Instance Method Details

#descriptionObject



14
15
16
# File 'lib/shoulda_render_json_object_matcher.rb', line 14

def description
  "render JSON Hash/Object for #{@root}"
end

#matches?(controller) ⇒ Boolean

Returns:



18
19
20
21
22
23
24
# File 'lib/shoulda_render_json_object_matcher.rb', line 18

def matches?(controller)
  @response = controller.response
  matches_content_type? &&
    matches_root? &&
    has_required_keys? &&
    has_no_forbidden_keys?
end