require 'net/http' require 'unfuddle_my_email' require 'test/unit' require 'flexmock/test_unit' require 'shoulda' class PosterTest < Test::Unit::TestCase include UnfuddleMyEmail context "a Poster class" do should "return a Net::HTTP instance when http called" do http = Poster.http('example.com') assert http.is_a?(Net::HTTP) end should "set SSL mode" do http = Poster.http('example.com', ssl = true) assert http.use_ssl? end should "post content" do post_i = flexmock('post_i') post_i.should_receive(:basic_auth).with(String, String) post_i.should_receive(:body=).with(String) post = flexmock('post') post.should_receive(:new).with(String).and_return(post_i) http_request = flexmock('request') http_request.should_receive(:request).and_return(Net::HTTPSuccess.new('','','')) http_lib = flexmock(Net::HTTP) http_lib.should_receive(:new).and_return(http_request) http_lib.should_receive(:post).and_return(post) assert Poster.post('example.com','/', false, 'user','password','test content') end end end