Skip to content

Commit

Permalink
Testing client on try update message and result http response status …
Browse files Browse the repository at this point in the history
…error
  • Loading branch information
tinogomes committed Apr 5, 2009
1 parent 4ba6e53 commit 3ab575d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/tuiter/client.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def update(status, in_reply_to_status_id = nil)
log("update() success: OK") log("update() success: OK")
return res # OK return res # OK
else else
log("update() error: #{res.error!}") log("update() error: #{res.to_s}")
res.error! res.error!
end end
end end
Expand Down
58 changes: 46 additions & 12 deletions test/unit/client_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,10 @@
require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../test_helper'


class ClientTest < Test::Unit::TestCase class ClientTest < Test::Unit::TestCase

def self.fake_web_post_on_update(message = "Ok", http_response_status = 200)
FakeWeb.register_uri(:post, "http://twitter.com/statuses/update.json", :string => message, :status => http_response_status.to_s)
end


context "A valid Tuiter client" do context "A valid Tuiter client" do


Expand All @@ -12,21 +16,51 @@ class ClientTest < Test::Unit::TestCase


context "posting data" do context "posting data" do
setup do setup do
@update_message = "I'm fine"
FakeWeb.register_uri(:post, "http://twitter.com/statuses/update.json", :string => @update_message, :status => "200")
end end


should "allow the user to post an update to Twitter" do context "successfully" do
# basic authentication and form data
Net::HTTP::Post.any_instance.expects(:basic_auth).with(@username, @password)
Net::HTTP::Post.any_instance.expects(:set_form_data).with('status' => @update_message, 'in_reply_to_status_id' => nil)


@response = @client.update(@update_message) setup do

@update_message = "I'm fine"
assert_instance_of Net::HTTPOK, @response FakeWeb.register_uri(:post, "http://twitter.com/statuses/update.json",
end :string => @update_message,
:status => "200")
end


end should "allow the user to post an update to Twitter" do
# basic authentication and form data
Net::HTTP::Post.any_instance.expects(:basic_auth).with(@username, @password)
Net::HTTP::Post.any_instance.expects(:set_form_data).with('status' => @update_message, 'in_reply_to_status_id' => nil)

@response = @client.update(@update_message)

assert_instance_of Net::HTTPOK, @response
end

end # context "successfully"

context "some error on request" do
setup do
@update_message = "I'm fine"
FakeWeb.register_uri(:post, "http://twitter.com/statuses/update.json",
:string => "503 Service unavailable",
:status => ["503", "Service unavailable"])
end

should "raise for http response status on 503" do
Net::HTTP::Post.any_instance.expects(:basic_auth).with(@username, @password)
Net::HTTP::Post.any_instance.expects(:set_form_data).with('status' => @update_message, 'in_reply_to_status_id' => nil)
assert_raises Net::HTTPFatalError do
@response = @client.update(@update_message)
end
# assert_instance_of Net::HTTPServiceUnavailable, @response
end

end # context "some error on request"


end # context "posting data"


end
end # context "A valid Tuiter client"
end end

0 comments on commit 3ab575d

Please sign in to comment.