Created
August 3, 2011 12:10
-
-
Save cemeng/1122488 to your computer and use it in GitHub Desktop.
unit test w/ webmock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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 :)
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
Can you check what Rack::Utils.build_nested_query( params ) prduces? Is "completed_at" not part of the produced string?