Class: APIMatchers::ResponseBody::Base
- Inherits:
-
Object
- Object
- APIMatchers::ResponseBody::Base
show all
- Defined in:
- lib/api_matchers/response_body/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
7
8
9
10
|
# File 'lib/api_matchers/response_body/base.rb', line 7
def initialize(options={})
@expected_node = options.fetch(:expected_node)
@setup = options.fetch(:setup)
end
|
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
4
5
6
|
# File 'lib/api_matchers/response_body/base.rb', line 4
def actual
@actual
end
|
#expected_node ⇒ Object
Returns the value of attribute expected_node.
4
5
6
|
# File 'lib/api_matchers/response_body/base.rb', line 4
def expected_node
@expected_node
end
|
#setup ⇒ Object
Returns the value of attribute setup.
4
5
6
|
# File 'lib/api_matchers/response_body/base.rb', line 4
def setup
@setup
end
|
Instance Method Details
#added_message ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/api_matchers/response_body/base.rb', line 46
def added_message
if @with_value
" with value: '#{@with_value}'"
elsif @expected_including_text
" including text: '#{@expected_including_text}'"
else
""
end
end
|
#failure_message ⇒ Object
Also known as:
failure_message_for_should
34
35
36
|
# File 'lib/api_matchers/response_body/base.rb', line 34
def failure_message
"expected to have node called: '#{@expected_node}'" << added_message << ". Got: '#{response_body}'"
end
|
#failure_message_when_negated ⇒ Object
Also known as:
failure_message_for_should_not
38
39
40
|
# File 'lib/api_matchers/response_body/base.rb', line 38
def failure_message_when_negated
"expected to NOT have node called: '#{@expected_node}'" << added_message << ". Got: '#{response_body}'"
end
|
#including_text(expected_including_text) ⇒ Object
21
22
23
24
|
# File 'lib/api_matchers/response_body/base.rb', line 21
def including_text(expected_including_text)
@expected_including_text = expected_including_text
self
end
|
#matches?(actual) ⇒ Boolean
12
13
14
|
# File 'lib/api_matchers/response_body/base.rb', line 12
def matches?(actual)
raise NotImplementedError, "not implemented on #{self}"
end
|
#response_body ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/api_matchers/response_body/base.rb', line 26
def response_body
if @setup.response_body_method.present?
@actual.send(@setup.response_body_method)
else
@actual
end
end
|
#with(expected_value) ⇒ Object
16
17
18
19
|
# File 'lib/api_matchers/response_body/base.rb', line 16
def with(expected_value)
@with_value = expected_value
self
end
|