Skip to content

Instantly share code, notes, and snippets.

@cantremember
Created March 23, 2012 05:28
Show Gist options
  • Save cantremember/2167251 to your computer and use it in GitHub Desktop.
Save cantremember/2167251 to your computer and use it in GitHub Desktop.
mocking Twitter4R in RSpec
before(:each) do
Twitter::Client.send :public, :create_http_get_request
@client = Twitter::Client.new
@client_clone = Twitter::Client.new
end
it "produces a querystring with all the crazy stuff Twitter imagined" do
the_params = nil
@client.should_receive(:create_http_get_request).and_return {|uri, params|
the_params = params
@client_clone.create_http_get_request(uri, params)
}
@client.should_receive(:http_connect).and_return Net::HTTPNotFound.mock(:code => '404')
# pass through a few we can pick back out
# also, side-effect ... nil on invalid response
@client.search('query_value', :rpp => 3).should be_nil
the_params.should_not be_nil
the_params[:q].should eql('query_value')
the_params[:rpp].should eql(3)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment