softcode
softcode

Reputation: 4638

stripe-ruby-mock gem with Minitest

I am new to testing. I am trying to use stripe-ruby-mock gem with minitest.

In the stripe-ruby-mock docs they describe a dummy example in Rspec that I am trying to translate to minitest:

require 'stripe_mock'

describe MyApp do
  let(:stripe_helper) { StripeMock.create_test_helper }
  before { StripeMock.start }
  after { StripeMock.stop }

  it "creates a stripe customer" do

    # This doesn't touch stripe's servers nor the internet!
    customer = Stripe::Customer.create({
      email: '[email protected]',
      card: stripe_helper.generate_card_token
    })
    expect(customer.email).to eq('[email protected]')
  end
end

My translation to minitest

require 'test_helper'
require 'stripe_mock'

class SuccessfulCustomerCreationTest < ActionDispatch::IntegrationTest
  describe 'create customer' do
    def stripe_helper
      StripeMock.create_test_helper
    end

    before do
      StripeMock.start
    end

    after do
      StripeMock.stop
    end

    test "creates a stripe customer" do
      customer = Stripe::Customer.create({
                                         email: "[email protected]",
                                         card: stripe_helper.generate_card_token
                                     })
      assert_equal customer.email, "[email protected]"
    end
  end
end

The error

NoMethodError: undefined method `describe' for SuccessfulPurchaseTest:Class

I consulted the minitest docs to make sure describe wasn't specific to Rspec but it turns out it is also used in minitest. I am guessing the implementation isn't done properly. Any help appreciated.

Upvotes: 4

Views: 1417

Answers (3)

parth bharadva
parth bharadva

Reputation: 1

you want to require:

require 'spec_helper'

for rspec example.

Upvotes: 0

jpbalarini
jpbalarini

Reputation: 1172

I think you are mixing things. Check Minitest page on sections Unit tests and Specs. I think what you need is the following:

require 'test_helper'
require 'stripe_mock'

class SuccessfulCustomerCreationTest < Minitest::Test
  def stripe_helper
    StripeMock.create_test_helper
  end

  def setup
    StripeMock.start
  end

  def teardown
    StripeMock.stop
  end

  test "creates a stripe customer" do
    customer = Stripe::Customer.create({
                                       email: "[email protected]",
                                       card: stripe_helper.generate_card_token
                                      })
    assert_equal customer.email, "[email protected]"
  end
end

Or if you want use the Spec syntax. Hope this helps someone.

Upvotes: 1

hraynaud
hraynaud

Reputation: 736

Hi I'm mostly an Rspec guy but I think you're issue is that you are using and integration test case when you should be using an unit test case. Try the following instead

class SuccessfulCustomerCreationTest < MiniTest::Unit::TestCase

Upvotes: 1

Related Questions