3

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: 'johnny@appleseed.com',
      card: stripe_helper.generate_card_token
    })
    expect(customer.email).to eq('johnny@appleseed.com')
  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: "koko@koko.com",
                                         card: stripe_helper.generate_card_token
                                     })
      assert_equal customer.email, "koko@koko.com"
    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.

softcode
  • 4,358
  • 12
  • 41
  • 68

3 Answers3

1

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
hraynaud
  • 681
  • 7
  • 15
1

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: "koko@koko.com",
                                       card: stripe_helper.generate_card_token
                                      })
    assert_equal customer.email, "koko@koko.com"
  end
end

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

jpbalarini
  • 1,082
  • 1
  • 17
  • 23
0

you want to require:

require 'spec_helper'

for rspec example.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146