spec/rapidash/response_spec.rb in rapidash-0.1.2 vs spec/rapidash/response_spec.rb in rapidash-0.2.0
- old
+ new
@@ -29,11 +29,31 @@
},
:body => body
})
end
+def valid_null_response_object
+ body = nil.to_json
+ OpenStruct.new({
+ :headers => {
+ "content-type" => "application/json"
+ },
+ :body => body
+ })
+end
+def valid_empty_response_object
+ body = ""
+ OpenStruct.new({
+ :headers => {
+ "content-type" => "application/json"
+ },
+ :body => body
+ })
+end
+
+
def valid_response_array
body = [{"foo" => "bar" }, {"baz" => "bra"}].to_json
OpenStruct.new({
:headers => {
"content-type" => "application/json"
@@ -82,9 +102,20 @@
it "should parse JSON Objects returned with html type" do
response = Rapidash::Response.new(valid_html_response_object)
response.foo.should eql("bar")
end
+
+ it "should parse a JSON null" do
+ response = Rapidash::Response.new(valid_null_response_object)
+ response.should eql(nil)
+ end
+
+ it "should parse an empty body" do
+ response = Rapidash::Response.new(valid_empty_response_object)
+ response.should eql(nil)
+ end
+
it "should parse JSON Arrays" do
response = Rapidash::Response.new(valid_response_array)
response[0].foo.should eql("bar")
response[1].baz.should eql("bra")