spec/httparty_spec.rb in alexvollmer-httparty-0.3.1 vs spec/httparty_spec.rb in alexvollmer-httparty-0.4.3

- old
+ new

@@ -19,10 +19,16 @@ it 'should have writer' do @klass.base_uri('http://api.foobar.com') @klass.base_uri.should == 'http://api.foobar.com' end + + it 'should not modify the parameter during assignment' do + uri = 'http://api.foobar.com' + @klass.base_uri(uri) + uri.should == 'http://api.foobar.com' + end end describe "#normalize_base_uri" do it "should add http if not present for non ssl requests" do uri = HTTParty.normalize_base_uri('api.foobar.com') @@ -36,10 +42,16 @@ it "should not remove https for ssl requests" do uri = HTTParty.normalize_base_uri('https://api.foo.com/v1:443') uri.should == 'https://api.foo.com/v1:443' end + + it 'should not modify the parameter' do + uri = 'http://api.foobar.com' + HTTParty.normalize_base_uri(uri) + uri.should == 'http://api.foobar.com' + end end describe "headers" do it "should default to empty hash" do @klass.headers.should == {} @@ -149,15 +161,27 @@ it "should allow yaml" do @klass.format :yaml @klass.default_options[:format].should == :yaml end + it "should allow plain" do + @klass.format :plain + @klass.default_options[:format].should == :plain + end + it 'should not allow funky format' do lambda do @klass.format :foobar end.should raise_error(HTTParty::UnsupportedFormat) end + + it 'should only print each format once with an exception' do + lambda do + @klass.format :foobar + end.should raise_error(HTTParty::UnsupportedFormat, "Must be one of: json, plain, html, yaml, xml") + end + end describe "with multiple class definitions" do before(:each) do @klass.instance_eval do @@ -180,13 +204,11 @@ end describe "#get" do it "should be able to get html" do stub_http_response_with('google.html') - resp = HTTParty.get('http://www.google.com') - resp.should == file_fixture('google.html') - resp.body.should == file_fixture('google.html') + HTTParty.get('http://www.google.com').should == file_fixture('google.html') end it "should be able parse response type json automatically" do stub_http_response_with('twitter.json') tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.json') @@ -200,11 +222,10 @@ "screen_name" => "Pyk", "followers_count" => 1, "location" => "Opera Plaza, California", "profile_image_url" => "http://static.twitter.com/images/default_profile_normal.png" } - tweets.body.should == file_fixture('twitter.json') end it "should be able parse response type xml automatically" do stub_http_response_with('twitter.xml') tweets = HTTParty.get('http://twitter.com/statuses/public_timeline.xml') @@ -218,10 +239,9 @@ "screen_name" => "magic8bot", "followers_count" => "90", "profile_image_url" => "http://s3.amazonaws.com/twitter_production/profile_images/65565851/8ball_large_normal.jpg", "location" => nil } - tweets.body.should == file_fixture('twitter.xml') end it "should not get undefined method add_node for nil class for the following xml" do stub_http_response_with('undefined_method_add_node_for_nil.xml') result = HTTParty.get('http://foobar.com')