lib/rspec-api/dsl/request.rb in rspec-api-0.1.1 vs lib/rspec-api/dsl/request.rb in rspec-api-0.1.2
- old
+ new
@@ -10,11 +10,11 @@
# To be overriden by more specific modules
OpenStruct.new # body: nil, status: nil, headers: {}
end
def response_body
- JSON response.body
+ JSON response_body_without_callbacks
rescue JSON::ParserError, JSON::GeneratorError
nil
end
def response_headers
@@ -55,8 +55,17 @@
end
def success?(status_code)
has_entity_body?(status_code) && status_code < 400
end
+ end
+
+ private
+
+ def response_body_without_callbacks
+ body = response.body
+ # TODO: extract the 'a_callback' constant
+ callback_pattern = %r[a_callback\((.*?)\)]
+ body =~ callback_pattern ? body.match(callback_pattern)[1] : body
end
end
end
\ No newline at end of file