lib/json_matchers/rspec.rb in json_matchers-0.6.2 vs lib/json_matchers/rspec.rb in json_matchers-0.6.3
- old
+ new
@@ -1,6 +1,7 @@
require "json_matchers"
+require "json_matchers/payload"
module JsonMatchers
class RSpec < SimpleDelegator
attr_reader :schema_name
@@ -16,11 +17,11 @@
---
expected
-#{pretty_json(response.body)}
+#{pretty_json(response)}
to match schema "#{schema_name}":
#{pretty_json(schema_body)}
@@ -33,22 +34,24 @@
---
expected
-#{pretty_json(response.body)}
+#{pretty_json(response)}
not to match schema "#{schema_name}":
#{pretty_json(schema_body)}
FAIL
end
private
- def pretty_json(json_string)
- JSON.pretty_generate(JSON.parse(json_string.to_s))
+ def pretty_json(response)
+ payload = Payload.new(response).to_s
+
+ JSON.pretty_generate(JSON.parse(payload))
end
def schema_path
JsonMatchers.path_to_schema(schema_name)
end