Module: Rester::Utils::RSpec
- Defined in:
- lib/rester/utils/rspec.rb
Class Method Summary collapse
- ._length_error(response, stub, accessors = []) ⇒ Object
- ._match_error(response, stub, accessors = []) ⇒ Object
- ._pretty_print_accessors(accessors = []) ⇒ Object
- ._type_error(response, stub, accessors = []) ⇒ Object
- .assert_deep_include(response, stub, accessors = []) ⇒ Object
Class Method Details
._length_error(response, stub, accessors = []) ⇒ Object
35 36 37 38 |
# File 'lib/rester/utils/rspec.rb', line 35 def _length_error(response, stub, accessors=[]) accessors_str = _pretty_print_accessors(accessors) fail Errors::StubError, "Stub#{accessors_str} length: #{stub.length} doesn't match Response#{accessors_str} length: #{response.length}" end |
._match_error(response, stub, accessors = []) ⇒ Object
30 31 32 33 |
# File 'lib/rester/utils/rspec.rb', line 30 def _match_error(response, stub, accessors=[]) accessors_str = _pretty_print_accessors(accessors) fail Errors::StubError, "Stub#{accessors_str}=#{stub.inspect} doesn't match Response#{accessors_str}=#{response.inspect}" end |
._pretty_print_accessors(accessors = []) ⇒ Object
45 46 47 |
# File 'lib/rester/utils/rspec.rb', line 45 def _pretty_print_accessors(accessors=[]) accessors.map { |a| "[#{a.inspect}]" }.join end |
._type_error(response, stub, accessors = []) ⇒ Object
40 41 42 43 |
# File 'lib/rester/utils/rspec.rb', line 40 def _type_error(response, stub, accessors=[]) accessors_str = _pretty_print_accessors(accessors) fail Errors::StubError, "Stub#{accessors_str} type: #{stub.class} doesn't match Response#{accessors_str} type: #{response.class}" end |
.assert_deep_include(response, stub, accessors = []) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rester/utils/rspec.rb', line 5 def assert_deep_include(response, stub, accessors=[]) case stub when Hash _type_error(response, stub, accessors) unless response.is_a?(Hash) stub.all? { |k,v| assert_deep_include(response[k], v, accessors + [k]) } when Array unless response.is_a?(Array) _type_error(response, stub, accessors) end unless response.length == stub.length _length_error(response, stub, accessors) end stub.each_with_index.all? { |e,i| assert_deep_include(response[i], e, accessors + [i]) } else unless stub == response || (stub.is_a?(Regexp) && stub =~ response) _match_error(response, stub, accessors) end true end end |