Permalink
Browse files

Return a response object after posting

  • Loading branch information...
1 parent a2c2f44 commit 7cb21f35c75792b4165f7c2d885f772dc39c145c @alloy alloy committed Jul 30, 2010
Showing with 32 additions and 9 deletions.
  1. +9 −1 lib/mollie/sms.rb
  2. +23 −8 spec/sms_spec.rb
View
@@ -42,7 +42,15 @@ def request_params
end
def deliver
- Net::HTTP.post_form(GATEWAY_URI, request_params)
+ Response.new(Net::HTTP.post_form(GATEWAY_URI, request_params))
+ end
+
+ class Response
+ attr_reader :response
+
+ def initialize(response)
+ @response = response
+ end
end
end
end
View
@@ -73,20 +73,28 @@
module Net
class HTTP
- def self.reset!
- @posted = {}
- end
+ class << self
+ attr_accessor :stubbed_response
- def self.post_form(url, params)
- @posted = { 'url' => url, 'params' => params }
- end
+ def reset!
+ @posted = {}
+ end
- def self.posted
- @posted ||= {}
+ def post_form(url, params)
+ @posted = { 'url' => url, 'params' => params }
+ @stubbed_response
+ end
+
+ def posted
+ @posted ||= {}
+ end
end
end
end
+class ResponseStub
+end
+
describe "When sending a Mollie::SMS message" do
before do
@sms = Mollie::SMS.new
@@ -105,4 +113,11 @@ def self.posted
'params' => @sms.request_params
}
end
+
+ it "returns a Mollie::SMS::Response object, with the Net::HTTP response" do
+ Net::HTTP.stubbed_response = ResponseStub.new
+ response = @sms.deliver
+ response.should.be.instance_of Mollie::SMS::Response
+ response.response.should == Net::HTTP.stubbed_response
+ end
end

0 comments on commit 7cb21f3

Please sign in to comment.