spec/lib/curb-fu/request/base_spec.rb in curb-fu-0.6.0 vs spec/lib/curb-fu/request/base_spec.rb in curb-fu-0.6.1

- old
+ new

@@ -28,10 +28,13 @@ describe CurbFu::Request::Base do describe "build_url" do it "should return a string if a string parameter is given" do TestHarness.build_url("http://www.cliffsofinsanity.com").should == "http://www.cliffsofinsanity.com" end + it "should return a string if a :url paramter is given" do + TestHarness.build_url(:url => "http://www.cliffsofinsanity.com", :headers => { 'Content-Type' => 'cash/dollars' }).should == "http://www.cliffsofinsanity.com" + end it "should return a built url with just a hostname if only the hostname is given" do TestHarness.build_url(:host => "poisonedwine.com").should == "http://poisonedwine.com" end it "should return a built url with hostname and port if port is also given" do TestHarness.build_url(:host => "www2.giantthrowingrocks.com", :port => 8080). @@ -72,10 +75,19 @@ it "should append query parameters" do @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil, :http_get => nil) Curl::Easy.should_receive(:new).with(regex_for_url_with_params('http://www.google.com', 'search=MSU\+vs\+UNC', 'limit=200')).and_return(@mock_curb) TestHarness.get('http://www.google.com', { :search => 'MSU vs UNC', :limit => 200 }) end + it "should set cookies" do + the_cookies = "SekretAuth=123134234" + + @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil, :http_get => nil) + Curl::Easy.should_receive(:new).and_return(@mock_curb) + @mock_curb.should_receive(:cookies=).with(the_cookies) + + TestHarness.get("http://google.com", {}, the_cookies) + end describe "with_hash" do it "should get google from {:host => \"www.google.com\", :port => 80}" do @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil, :http_get => nil) Curl::Easy.should_receive(:new).with('http://www.google.com:80').and_return(@mock_curb) @@ -92,10 +104,23 @@ it "should append parameters to the url" do @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil, :http_get => nil) Curl::Easy.should_receive(:new).with(regex_for_url_with_params('http://www.google.com', 'search=MSU\+vs\+UNC', 'limit=200')).and_return(@mock_curb) TestHarness.get({ :host => 'www.google.com' }, { :search => 'MSU vs UNC', :limit => 200 }) end + it "should set cookies" do + the_cookies = "SekretAuth=123134234" + + @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil, :http_get => nil) + Curl::Easy.should_receive(:new).and_return(@mock_curb) + @mock_curb.should_receive(:cookies=).with(the_cookies) + + TestHarness.get({ + :host => "google.com", + :port => 80, + :cookies => the_cookies + }) + end end end describe "post" do before(:each) do @@ -154,17 +179,36 @@ @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil) Curl::Easy.stub!(:new).and_return(@mock_curb) end it "should send each parameter to Curb#http_put" do - Curl::Easy.should_receive(:new).with('http://google.com:80/search?q=derek&r=matt').and_return(@mock_curb) - @mock_curb.should_receive(:http_put) + @mock_q = Curl::PostField.content('q','derek') + @mock_r = Curl::PostField.content('r','matt') + TestHarness.stub!(:create_post_fields).and_return([@mock_q,@mock_r]) + @mock_curb.should_receive(:http_put).with(@mock_q,@mock_r) + response = TestHarness.put( {:host => "google.com", :port => 80, :path => "/search"}, { 'q' => 'derek', 'r' => 'matt' }) end end + + describe "delete" do + before(:each) do + @resource_link = 'http://example.com/resource/1' + @mock_curb = mock(Curl::Easy, :headers= => nil, :headers => {}, :header_str => "", :response_code => 200, :body_str => 'yeeeah', :timeout= => nil) + Curl::Easy.stub!(:new).and_return(@mock_curb) + end + + it "should send each parameter to Curb#http_delete" do + Curl::Easy.should_receive(:new).with(@resource_link).and_return(@mock_curb) + @mock_curb.should_receive(:http_delete) + + response = TestHarness.delete(@resource_link) + end + end + describe "create_post_fields" do it "should return the params if params is a string" do TestHarness.create_post_fields("my awesome data that I'm sending to you"). should == "my awesome data that I'm sending to you"