Skip to content

Commit

Permalink
Use compensated-spec fixtures to test compensated-ruby and `compe…
Browse files Browse the repository at this point in the history
…nsated-proxy` (#83)

* 🐛Don't double dump the hash structures

See: #68

* `compensated` relies on `compensated-spec` for Stripe test fixtures

See: #68

* Rely on `compensated-spec` in `compensated-proxy` for event fixtures
  • Loading branch information
zspencer authored Jun 18, 2020
1 parent aa557f6 commit 35d5df4
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 905 deletions.
1 change: 1 addition & 0 deletions compensated-proxy/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ gemspec

gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
gem "compensated-spec", path: "../compensated-spec"
13 changes: 13 additions & 0 deletions compensated-proxy/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
PATH
remote: ../compensated-spec
specs:
compensated-spec (0.1.0)
compensated
jsonpath (~> 1.0)

PATH
remote: .
specs:
Expand All @@ -9,6 +16,10 @@ GEM
specs:
compensated (0.1.0.pre13)
diff-lcs (1.3)
jsonpath (1.0.5)
multi_json
to_regexp (~> 0.2.1)
multi_json (1.14.1)
rake (12.3.3)
rspec (3.9.0)
rspec-core (~> 3.9.0)
Expand All @@ -23,12 +34,14 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
to_regexp (0.2.1)

PLATFORMS
ruby

DEPENDENCIES
compensated-proxy!
compensated-spec!
rake (~> 12.0)
rspec (~> 3.0)

Expand Down
9 changes: 2 additions & 7 deletions compensated-proxy/spec/compensated/proxy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_relative '../../../compensated-ruby/spec/fixtures'

require 'compensated/stripe'
RSpec.describe Compensated::Proxy do
include Compensated::Spec::Helpers
Expand All @@ -10,11 +8,8 @@
expect(Compensated::Proxy::VERSION).not_to be nil
end

let(:interpolate) { {} }
# TODO: Maybe pull the spec helpers into a `compensated-spec` gem
# that will make it easier to leverage the fixtures when testing compensated.
let(:template_file_path) { fixture_path(Pathname.new(__dir__).join('..', '..', '..', 'compensated-ruby', 'spec', 'stripe'), fixture) }
let(:request) { fake_request(template_file_path, interpolate: interpolate) }
let(:overrides) { [] }
let(:request) { compensated_fake_request("stripe/#{fixture}", overrides: overrides) }
let(:fixture) { 'customer.subscription.updated.api-v2019-12-03.json' }

it 'forwards the standardized body without the raw body' do
Expand Down
1 change: 1 addition & 0 deletions compensated-proxy/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'compensated/spec'
require 'compensated/proxy'

RSpec.configure do |config|
Expand Down
2 changes: 2 additions & 0 deletions compensated-ruby/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ source "https://rubygems.org"

# Specify your gem's dependencies in compensated-ruby.gemspec
gemspec

gem "compensated-spec", path: "../compensated-spec"
1 change: 1 addition & 0 deletions compensated-ruby/compensated.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rack"
spec.add_development_dependency "cucumber"
spec.add_development_dependency "yard"
spec.add_development_dependency "pry"
end
70 changes: 0 additions & 70 deletions compensated-ruby/spec/fixtures.rb

This file was deleted.

3 changes: 2 additions & 1 deletion compensated-ruby/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "bundler/setup"
require "compensated"
require_relative 'fixtures'
require "compensated/spec"
require "pry"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down
17 changes: 10 additions & 7 deletions compensated-ruby/spec/stripe/event_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module Compensated
module Stripe
RSpec.describe EventParser do
include Compensated::Spec::Helpers
let(:interpolate) { {} }
let(:template_file_path) { fixture_path(__dir__, fixture) }
let(:request) { fake_request(template_file_path, interpolate: interpolate) }
let(:interpolate) { [] }
let(:request) { compensated_fake_request("stripe/#{fixture}", overrides: interpolate) }

it "Adds itself to the list of event parses available to compensated" do
expect(Compensated.event_parsers.find { |ep| ep.instance_of?(Stripe::EventParser) }).not_to be_nil
Expand Down Expand Up @@ -249,12 +248,12 @@ module Stripe
subject(:subscription) { product[:subscription] }
it { is_expected.to include(period: { start: Time.at(1586329200), end: Time.at(1588921200) }) }
context 'when the subscription does not have a canceled_at value set' do
let(:interpolate) { { data: { object: { canceled_at: nil } } } }
let(:interpolate) { [ {location: "$.data.object.canceled_at", value: nil }] }
it { is_expected.to include(status: :active) }
end

context 'when the subscription does have a canceled_at value set' do
let(:interpolate) { { data: { object: { canceled_at: 1234 } } } }
let(:interpolate) { [ {location: "$.data.object.canceled_at", value: 1234 }] }
it { is_expected.to include(status: :canceled) }
end

Expand Down Expand Up @@ -284,12 +283,16 @@ module Stripe
describe ":subscription" do
subject(:subscription) { product[:subscription] }
context 'when data.object.ended_at is nil and data.object.canceled_at is present' do
let(:interpolate) { { data: { object: { ended_at: nil, canceled_at: 12345 } } } }
let(:interpolate) { [{ location: "$.data.object.ended_at", value: nil },
{ location: "$.data.object.canceled_at", value: 12345 }] }
it { is_expected. to include(status: :canceled) }
end

context 'when data.object.ended_at is present and data.object.canceled_at is present' do
let(:interpolate) { { data: { object: { ended_at: 12345, canceled_at: 12345 } } } }
let(:interpolate) do
[{ location: "$.data.object.ended_at", value: 12345 }, { location: "$.data.object.canceled_at", value: 12345 }]
end

it { is_expected. to include(status: :ended) }
end
end
Expand Down

This file was deleted.

Loading

0 comments on commit 35d5df4

Please sign in to comment.