require File.join(File.dirname(__FILE__), '..', 'spec_helper' ) describe "Itrigga::NetHelper::RestClient" do before do @mock_response = mock("Response", :to_str => "stuff") @client = mock("RestClient::Request") @client.stub!(:execute).and_return(@mock_response) RestClient::Request.stub!(:new).and_return(@client) end it "should raise error if no url" do lambda { Itrigga::NetHelper::RestClient.get }.should raise_error(ArgumentError,":url is required") end it "should call execute on new Request" do RestClient::Request.should_receive(:new).with(hash_including(:method => :get, :url => "abc", :param1 => "blart")).and_return(@client) Itrigga::NetHelper::RestClient.get :url => "abc", :param1 => "blart" end it "should return the correct value" do @mock_response.should_receive(:to_str).and_return("stuff") Itrigga::NetHelper::RestClient.get(:url => "abc").should == "stuff" end context "when given a :username" do it "should convert it to :user" do RestClient::Request.should_receive(:new).with(hash_including(:method => :get, :url => "abc", :user => "blart")).and_return(@client) Itrigga::NetHelper::RestClient.get :url => "abc", :username => "blart" end end end