lib/rspec/rabl/attribute_matcher.rb in rspec_rabl-0.0.3 vs lib/rspec/rabl/attribute_matcher.rb in rspec_rabl-0.0.4
- old
+ new
@@ -68,17 +68,25 @@
collection? ? parse_collection_object : parse_object
end
def parse_collection_object
data = parsed
- data = data[opts[:root]] if opts[:root]
+ if opts[:root]
+ data = data.fetch(opts[:root]){ raise ::RSpec::Rabl::Error.new("Missing Root #{opts[:root]}") }
+ end
data = data.first
- data = data[opts[:object_root]] if opts[:object_root]
+ if opts[:object_root]
+ data = data.fetch(opts[:object_root]){ raise ::RSpec::Rabl::Error.new("Missing Object Root #{opts[:object_root]}") }
+ end
data
end
def parse_object
- opts[:root] ? parsed[opts[:root]] : parsed
+ if opts[:root]
+ parsed.fetch(opts[:root]){ raise ::RSpec::Rabl::Error.new("Missing Object Root") }
+ else
+ parsed
+ end
end
def parsed
@parsed ||= JSON.parse(subject.render)
end