rspec-stripe 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +48 -0
- data/lib/rspec-stripe/configuration.rb +10 -0
- data/lib/rspec-stripe/factories/card.rb +29 -0
- data/lib/rspec-stripe/factories/customer.rb +15 -0
- data/lib/rspec-stripe/factories/plan.rb +20 -0
- data/lib/rspec-stripe/factories/subscription.rb +19 -0
- data/lib/rspec-stripe/runner.rb +45 -0
- data/lib/rspec-stripe/test_frameworks/rspec.rb +39 -0
- data/lib/rspec-stripe.rb +22 -0
- data/rspec-stripe.gemspec +18 -0
- data/spec/basic_rspec.rb +21 -0
- data/spec/spec_helper.rb +10 -0
- metadata +57 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: faa5490d004c1911a1fdbf4844935a8664b78525
         | 
| 4 | 
            +
              data.tar.gz: 8ea44304c4f8fcaf9123c5f489430a904eedd6fa
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 39e3817fe9e703b6d76ce4ecbd1e4934f1795acf60e167245e3ed0e20f764b73b0513ce9e16527999ca67c99a1da0ff2a1552579003e23e00a4a498637b28b78
         | 
| 7 | 
            +
              data.tar.gz: 6ed0e1da5161634d259584c1f1a23ebdcde557a83beaa752d3f343fe348d8c2d91542a529e9d5429c6c7cc152ffc9ce8e4e8bdf2f23500ee3a0712728961bd23
         | 
    
        data/.gitignore
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            .env
         | 
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            GIT
         | 
| 2 | 
            +
              remote: https://github.com/stripe/stripe-ruby
         | 
| 3 | 
            +
              revision: 2c6f4caa99916c33d3f9af57f66422ff5ea913cf
         | 
| 4 | 
            +
              specs:
         | 
| 5 | 
            +
                stripe (1.15.0)
         | 
| 6 | 
            +
                  json (~> 1.8.1)
         | 
| 7 | 
            +
                  mime-types (>= 1.25, < 3.0)
         | 
| 8 | 
            +
                  rest-client (~> 1.4)
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            PATH
         | 
| 11 | 
            +
              remote: .
         | 
| 12 | 
            +
              specs:
         | 
| 13 | 
            +
                rspec-stripe (0.0.1)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            GEM
         | 
| 16 | 
            +
              remote: https://rubygems.org/
         | 
| 17 | 
            +
              specs:
         | 
| 18 | 
            +
                diff-lcs (1.2.5)
         | 
| 19 | 
            +
                dotenv (0.11.1)
         | 
| 20 | 
            +
                  dotenv-deployment (~> 0.0.2)
         | 
| 21 | 
            +
                dotenv-deployment (0.0.2)
         | 
| 22 | 
            +
                json (1.8.1)
         | 
| 23 | 
            +
                mime-types (2.3)
         | 
| 24 | 
            +
                netrc (0.7.7)
         | 
| 25 | 
            +
                rest-client (1.7.2)
         | 
| 26 | 
            +
                  mime-types (>= 1.16, < 3.0)
         | 
| 27 | 
            +
                  netrc (~> 0.7)
         | 
| 28 | 
            +
                rspec (3.1.0)
         | 
| 29 | 
            +
                  rspec-core (~> 3.1.0)
         | 
| 30 | 
            +
                  rspec-expectations (~> 3.1.0)
         | 
| 31 | 
            +
                  rspec-mocks (~> 3.1.0)
         | 
| 32 | 
            +
                rspec-core (3.1.4)
         | 
| 33 | 
            +
                  rspec-support (~> 3.1.0)
         | 
| 34 | 
            +
                rspec-expectations (3.1.1)
         | 
| 35 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 36 | 
            +
                  rspec-support (~> 3.1.0)
         | 
| 37 | 
            +
                rspec-mocks (3.1.1)
         | 
| 38 | 
            +
                  rspec-support (~> 3.1.0)
         | 
| 39 | 
            +
                rspec-support (3.1.0)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            PLATFORMS
         | 
| 42 | 
            +
              ruby
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            DEPENDENCIES
         | 
| 45 | 
            +
              dotenv
         | 
| 46 | 
            +
              rspec (~> 3.1)
         | 
| 47 | 
            +
              rspec-stripe!
         | 
| 48 | 
            +
              stripe!
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            module RSpecStripe::Factory
         | 
| 2 | 
            +
              class Card
         | 
| 3 | 
            +
                attr_accessor :should_delete, :id, :customer
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(id, customer)
         | 
| 6 | 
            +
                  @id = id || :visa
         | 
| 7 | 
            +
                  @customer = customer
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def get
         | 
| 11 | 
            +
                  @id ||= :visa
         | 
| 12 | 
            +
                  @should_delete = true
         | 
| 13 | 
            +
                  customer.cards.create(card: recipes[id].merge(
         | 
| 14 | 
            +
                    exp_month: "01",
         | 
| 15 | 
            +
                    exp_year: "2025",
         | 
| 16 | 
            +
                    cvc: "111",
         | 
| 17 | 
            +
                    name: customer.id
         | 
| 18 | 
            +
                  ))
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def recipes
         | 
| 22 | 
            +
                  {
         | 
| 23 | 
            +
                    visa: {
         | 
| 24 | 
            +
                      number: "4242424242424242"
         | 
| 25 | 
            +
                    }
         | 
| 26 | 
            +
                  }
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
            end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            module RSpecStripe::Factory
         | 
| 2 | 
            +
              Customer = Struct.new(:id) do
         | 
| 3 | 
            +
                attr_accessor :should_delete
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def get
         | 
| 6 | 
            +
                  if id == :new || id == true
         | 
| 7 | 
            +
                    @should_delete = true
         | 
| 8 | 
            +
                    Stripe::Customer.create
         | 
| 9 | 
            +
                  else
         | 
| 10 | 
            +
                    @should_delete = false
         | 
| 11 | 
            +
                    Stripe::Customer.retrieve(id)
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            module RSpecStripe::Factory
         | 
| 2 | 
            +
              Plan = Struct.new(:id) do
         | 
| 3 | 
            +
                attr_accessor :should_delete
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def get
         | 
| 6 | 
            +
                  @should_delete = false
         | 
| 7 | 
            +
                  Stripe::Plan.retrieve(id)
         | 
| 8 | 
            +
                rescue Stripe::InvalidRequestError
         | 
| 9 | 
            +
                  @should_delete = true
         | 
| 10 | 
            +
                  # Lookup the plan's details and then create it
         | 
| 11 | 
            +
                  Stripe::Plan.create(
         | 
| 12 | 
            +
                    amount: 2000,
         | 
| 13 | 
            +
                    interval: 'month',
         | 
| 14 | 
            +
                    name: 'Amazing Gold Plan',
         | 
| 15 | 
            +
                    currency: 'usd',
         | 
| 16 | 
            +
                    id: id
         | 
| 17 | 
            +
                  )
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module RSpecStripe::Factory
         | 
| 2 | 
            +
              Subscription = Struct.new(:id, :customer) do
         | 
| 3 | 
            +
                attr_accessor :should_delete
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def get
         | 
| 6 | 
            +
                  @should_delete = true
         | 
| 7 | 
            +
                  cancel_subscriptions
         | 
| 8 | 
            +
                  customer.subscriptions.create(plan: id)
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                private
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def cancel_subscriptions
         | 
| 14 | 
            +
                  customer.subscriptions.all.each do |sub|
         | 
| 15 | 
            +
                    sub.delete
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            module RSpecStripe
         | 
| 2 | 
            +
              class Runner
         | 
| 3 | 
            +
                attr_accessor :recipes, :customer, :plan, :subscription, :card
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(recipes)
         | 
| 6 | 
            +
                  @recipes = recipes
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def call!
         | 
| 10 | 
            +
                  @customer = customer_factory.get if recipes[:customer]
         | 
| 11 | 
            +
                  @plan = plan_factory.get if recipes[:plan]
         | 
| 12 | 
            +
                  @card = card_factory.get if recipes[:card]
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  if recipes[:subscription]
         | 
| 15 | 
            +
                    @card ||= card_factory.get
         | 
| 16 | 
            +
                    @subscription = subscription_factory.get
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def cleanup!
         | 
| 21 | 
            +
                  subscription.delete if subscription_factory.should_delete
         | 
| 22 | 
            +
                  plan.delete if plan_factory.should_delete
         | 
| 23 | 
            +
                  card.delete if card_factory.should_delete
         | 
| 24 | 
            +
                  customer.delete if customer_factory.should_delete
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                private
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def customer_factory
         | 
| 30 | 
            +
                  @customer_factory ||= RSpecStripe::Factory::Customer.new(recipes[:customer])
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def plan_factory
         | 
| 34 | 
            +
                  @plan_factory ||= RSpecStripe::Factory::Plan.new(recipes[:plan])
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def subscription_factory
         | 
| 38 | 
            +
                  @subscription_factory ||= RSpecStripe::Factory::Subscription.new(recipes[:subscription], customer)
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                def card_factory
         | 
| 42 | 
            +
                  @card_factory ||= RSpecStripe::Factory::Card.new(recipes[:card], customer)
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            module RSpecStripe
         | 
| 2 | 
            +
              module RSpec
         | 
| 3 | 
            +
                module Metadata
         | 
| 4 | 
            +
                  extend self
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def configure!
         | 
| 7 | 
            +
                    ::RSpec.configure do |config|
         | 
| 8 | 
            +
                      when_tagged_with_stripe = { stripe: lambda { |val| !!val } }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                      config.before(:each, when_tagged_with_stripe) do |ex|
         | 
| 11 | 
            +
                        example = ex.respond_to?(:metadata) ? ex : ex.example
         | 
| 12 | 
            +
                        recipes = example.metadata[:stripe]
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                        @runner = RSpecStripe::Runner.new(recipes)
         | 
| 15 | 
            +
                        @runner.call!
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                        def stripe_customer
         | 
| 18 | 
            +
                          @stripe_customer ||= @runner.customer
         | 
| 19 | 
            +
                        end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                        def stripe_plan
         | 
| 22 | 
            +
                          @stripe_plan ||= @runner.plan
         | 
| 23 | 
            +
                        end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                        def stripe_subscription
         | 
| 26 | 
            +
                          @stripe_subscription ||= @runner.subscription
         | 
| 27 | 
            +
                        end
         | 
| 28 | 
            +
                      end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                      config.after(:each, when_tagged_with_stripe) do |ex|
         | 
| 31 | 
            +
                        example = ex.respond_to?(:metadata) ? ex : ex.example
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                        @runner.cleanup!
         | 
| 34 | 
            +
                      end
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
    
        data/lib/rspec-stripe.rb
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            require 'rspec-stripe/configuration'
         | 
| 2 | 
            +
            require 'rspec-stripe/runner'
         | 
| 3 | 
            +
            require 'rspec-stripe/factories/customer'
         | 
| 4 | 
            +
            require 'rspec-stripe/factories/plan'
         | 
| 5 | 
            +
            require 'rspec-stripe/factories/subscription'
         | 
| 6 | 
            +
            require 'rspec-stripe/factories/card'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            module RSpecStripe
         | 
| 9 | 
            +
              extend self
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              module RSpec
         | 
| 12 | 
            +
                autoload :Metadata, "rspec-stripe/test_frameworks/rspec"
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def configure
         | 
| 16 | 
            +
                yield configuration
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def configuration
         | 
| 20 | 
            +
                @configuration ||= Configuration.new
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            Gem::Specification.new do |s|
         | 
| 2 | 
            +
              s.name               = "rspec-stripe"
         | 
| 3 | 
            +
              s.license = "MIT"
         | 
| 4 | 
            +
              s.date = %q{2014-09-26}
         | 
| 5 | 
            +
              s.authors = ["Stephen Bussey"]
         | 
| 6 | 
            +
              s.email = %q{steve.bussey@salesloft.com}
         | 
| 7 | 
            +
              s.homepage = %q{https://github.com/sb8244/rspec-stripe}
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              s.summary = %q{Setup Stripe for specs easily and reliably}
         | 
| 10 | 
            +
              s.description = %q{Setup the Stripe World for your rspec tests}
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              s.require_paths = ["lib"]
         | 
| 13 | 
            +
              s.files = `git ls-files`.split("\n")
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              s.version            = "0.0.1"
         | 
| 16 | 
            +
              s.required_ruby_version = '>= 2.0.0'
         | 
| 17 | 
            +
              s.required_rubygems_version = '>= 1.6.2'
         | 
| 18 | 
            +
            end
         | 
    
        data/spec/basic_rspec.rb
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Stripe.api_key = ENV['STRIPE_TEST_KEY']
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            describe 'Basic' do
         | 
| 6 | 
            +
              it "gives me a customer", stripe: { customer: :new } do
         | 
| 7 | 
            +
                expect {
         | 
| 8 | 
            +
                  Stripe::Customer.retrieve(stripe_customer.id)
         | 
| 9 | 
            +
                }.not_to raise_error
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              it "gives a plan", stripe: { plan: "test" } do
         | 
| 13 | 
            +
                expect(stripe_plan).not_to eq(nil)
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              it "gives me a subscription", stripe: { customer: :new, plan: "test", subscription: "test" } do
         | 
| 17 | 
            +
                expect(stripe_customer).not_to eq(nil)
         | 
| 18 | 
            +
                expect(stripe_plan).not_to eq(nil)
         | 
| 19 | 
            +
                expect(stripe_subscription).not_to eq(nil)
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,57 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: rspec-stripe
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Stephen Bussey
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2014-09-26 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: Setup the Stripe World for your rspec tests
         | 
| 14 | 
            +
            email: steve.bussey@salesloft.com
         | 
| 15 | 
            +
            executables: []
         | 
| 16 | 
            +
            extensions: []
         | 
| 17 | 
            +
            extra_rdoc_files: []
         | 
| 18 | 
            +
            files:
         | 
| 19 | 
            +
            - ".gitignore"
         | 
| 20 | 
            +
            - Gemfile
         | 
| 21 | 
            +
            - Gemfile.lock
         | 
| 22 | 
            +
            - lib/rspec-stripe.rb
         | 
| 23 | 
            +
            - lib/rspec-stripe/configuration.rb
         | 
| 24 | 
            +
            - lib/rspec-stripe/factories/card.rb
         | 
| 25 | 
            +
            - lib/rspec-stripe/factories/customer.rb
         | 
| 26 | 
            +
            - lib/rspec-stripe/factories/plan.rb
         | 
| 27 | 
            +
            - lib/rspec-stripe/factories/subscription.rb
         | 
| 28 | 
            +
            - lib/rspec-stripe/runner.rb
         | 
| 29 | 
            +
            - lib/rspec-stripe/test_frameworks/rspec.rb
         | 
| 30 | 
            +
            - rspec-stripe.gemspec
         | 
| 31 | 
            +
            - spec/basic_rspec.rb
         | 
| 32 | 
            +
            - spec/spec_helper.rb
         | 
| 33 | 
            +
            homepage: https://github.com/sb8244/rspec-stripe
         | 
| 34 | 
            +
            licenses:
         | 
| 35 | 
            +
            - MIT
         | 
| 36 | 
            +
            metadata: {}
         | 
| 37 | 
            +
            post_install_message: 
         | 
| 38 | 
            +
            rdoc_options: []
         | 
| 39 | 
            +
            require_paths:
         | 
| 40 | 
            +
            - lib
         | 
| 41 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 42 | 
            +
              requirements:
         | 
| 43 | 
            +
              - - ">="
         | 
| 44 | 
            +
                - !ruby/object:Gem::Version
         | 
| 45 | 
            +
                  version: 2.0.0
         | 
| 46 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 47 | 
            +
              requirements:
         | 
| 48 | 
            +
              - - ">="
         | 
| 49 | 
            +
                - !ruby/object:Gem::Version
         | 
| 50 | 
            +
                  version: 1.6.2
         | 
| 51 | 
            +
            requirements: []
         | 
| 52 | 
            +
            rubyforge_project: 
         | 
| 53 | 
            +
            rubygems_version: 2.2.2
         | 
| 54 | 
            +
            signing_key: 
         | 
| 55 | 
            +
            specification_version: 4
         | 
| 56 | 
            +
            summary: Setup Stripe for specs easily and reliably
         | 
| 57 | 
            +
            test_files: []
         |