Skip to content

Commit

Permalink
add tests for post_to_url method
Browse files Browse the repository at this point in the history
  • Loading branch information
luaybs committed Jul 24, 2013
1 parent 967a8ce commit 38e8de3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'stripe_tester'
require "mocha/api"
require 'mocha/api'
require 'fakeweb'

RSpec.configure do |config|
config.order = "random"
Expand Down
27 changes: 26 additions & 1 deletion spec/stripe_tester_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,33 @@
expect(StripeTester.webhook_url).to eq(nil)
end

it "#post_to_url should send data to url" do
it "#post_to_url should return true when request is successful" do
data = StripeTester.load_template(:invoice_created)
url = "http://localhost:3000/transactions"
StripeTester.webhook_url = url

FakeWeb.register_uri(:post,
url,
body: data.to_json,
content_type: 'application/json')

response = StripeTester.post_to_url(data)

expect(response).to be(true)
end

it "#post_to_url should raise an error when request fails" do
data = StripeTester.load_template(:invoice_created)
url = "http://localhost:3000/"
StripeTester.webhook_url = url

FakeWeb.register_uri(:post,
url,
body: data.to_json,
content_type: 'application/json',
status: ["404", "Not Found"])

expect{ StripeTester.post_to_url(data) }.to raise_error('404 "Not Found"')
end

it "#post_to_url should raise an error if webhook URL is not set" do
Expand Down
1 change: 1 addition & 0 deletions stripe_tester.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "mocha"
spec.add_development_dependency "fakeweb", "~> 1.3"
end

0 comments on commit 38e8de3

Please sign in to comment.