Skip to content

Commit

Permalink
Merge pull request #89 from Everapps/no-mock
Browse files Browse the repository at this point in the history
stop loading stripe-ruby-mock from the gemspec
  • Loading branch information
tansengming authored Aug 31, 2017
2 parents 64d1931 + 0d4a91f commit 91dd0ad
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 21 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ gem "rake"
gem 'tzinfo'
gem 'mocha'
gem 'pry'
gem 'responders', '~> 2.0' # to support Rails 4.2

group :test do
gem 'simplecov', require: false
# NOTE: tracking master temporarily until they
# release https://github.com/rebelidealist/stripe-ruby-mock/pull/433
gem 'stripe-ruby-mock', github: 'rebelidealist/stripe-ruby-mock'
gem 'poltergeist' # required for system tests
gem 'phantomjs' # ditto
gem 'puma' # ditto
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,22 @@ See the [complete listing of all stripe events][5], and the [webhook tutorial][6

## Unit testing

If you want to test your callbacks, you can use the `Stripe::Testing` module to send mocked Stripe events.
If you want to test your callbacks, you can use the `Stripe::Rails::Testing` module to send mocked Stripe events.

```ruby
require 'stripe/rails/testing'
test "my callback handles new subscription" do
Stripe::Testing.send_event "customer.subscription.created"
Stripe::Rails::Testing.send_event "customer.subscription.created"
# Assertions
end
```

You can also overwrite some event properties: ([More info](https://github.com/rebelidealist/stripe-ruby-mock#customizing-webhooks))

```ruby
require 'stripe/rails/testing'
test "my callback handles new subscription" do
Stripe::Testing.send_event "customer.subscription.created", {
Stripe::Rails::Testing.send_event "customer.subscription.created", {
:email => "[email protected]",
:account_balance => 40
}
Expand Down
3 changes: 1 addition & 2 deletions lib/stripe/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
require 'stripe/configuration_builder'
require 'stripe/plans'
require 'stripe/coupons'
require 'stripe/callbacks'
require 'stripe/testing'
require 'stripe/callbacks'
19 changes: 19 additions & 0 deletions lib/stripe/rails/testing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
begin
require 'stripe_mock'
rescue LoadError
warn %q{Please add "gem 'stripe-ruby-mock', group: 'test'"" to the Gemfile to use Stripe::Rails::Testing"}
exit
end
require 'stripe/callbacks'

module Stripe
module Rails
module Testing
def self.send_event(event, properties = {})
evt = StripeMock.mock_webhook_event(event, properties)
target = evt.data.object
::Stripe::Callbacks.run_callbacks(evt, target)
end
end
end
end
12 changes: 0 additions & 12 deletions lib/stripe/testing.rb

This file was deleted.

1 change: 0 additions & 1 deletion stripe-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ Gem::Specification.new do |gem|
gem.add_dependency 'rails', '>= 3'
gem.add_dependency 'stripe'
gem.add_dependency 'responders'
gem.add_dependency 'stripe-ruby-mock', '~> 2.4'
end
5 changes: 3 additions & 2 deletions test/testing_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'stripe/rails/testing'

describe "Testing" do
let(:observer) { Class.new }
Expand All @@ -20,7 +21,7 @@
end

describe '.send_event' do
subject { Stripe::Testing.send_event event_name }
subject { Stripe::Rails::Testing.send_event event_name }

describe 'when forwarding the event to the callback' do
let(:event_name) { "invoice.payment_succeeded" }
Expand All @@ -42,7 +43,7 @@
end

describe 'when overwriting event properties' do
subject { Stripe::Testing.send_event event_name, params }
subject { Stripe::Rails::Testing.send_event event_name, params }
let(:event_name) { "invoice.payment_succeeded" }
let(:params) { { subtotal: 500, total: 1000, currency: "eur" } }

Expand Down

0 comments on commit 91dd0ad

Please sign in to comment.