Skip to content

Instantly share code, notes, and snippets.

@cemeng
Created August 3, 2011 12:10
Show Gist options
  • Save cemeng/1122488 to your computer and use it in GitHub Desktop.
Save cemeng/1122488 to your computer and use it in GitHub Desktop.
unit test w/ webmock
require 'helper'
class TestDailymileRuby < Test::Unit::TestCase
def setup
WebMock.disable_net_connect!
end
should "be able to post a simple entry" do
# Stub setup
params = {
:message => "Totally awesome",
:oauth_token => "XXVTcIrfN2cIs43Yg3de56LIYGsWjTXmNiRmR6H4",
:completed_at => "2011-07-19 13:00"
}
stub_request(:post, "https://api.dailymile.com/entries.json").
with(
:body => Rack::Utils.build_nested_query( params ),
:headers => {
'Accept'=>'application/json',
'Authorization'=>'OAuth XXVTcIrfN2cIs43Yg3de56LIYGsWjTXmNiRmR6H4',
'Content-Type'=>'application/x-www-form-urlencoded',
'User-Agent'=>'dailymile-ruby/0.2.0'}
).
to_return(:status => 200, :body => "", :headers => {}
)
# Test
Dailymile::Client.set_client_credentials 'qnFYExIvAhpsBLY4DU7w4jJerrmtBTUOQ4zccS1e', 'uE2tbUVPAjzXftUVZySLGvISEQkyeGQrSuh3Jz1n'
client = Dailymile::Client.new 'XXVTcIrfN2cIs43Yg3de56LIYGsWjTXmNiRmR6H4'
entry = Dailymile::Entry.new :message => "Totally awesome"
client.post_entry(entry.entry)
end
end
@cemeng
Copy link
Author

cemeng commented Aug 3, 2011

You are right! I didn't set the completed_at for the actual API call that I was testing - but I set it up on stub_request.

So I removed the completed_at from the stub_request - and I got different error - but the error is totally unrelated to WebMock.

Thanks for helping me debugging this :)

@bblimke
Copy link

bblimke commented Aug 3, 2011

Happy to help :) Good luck with the other error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment