带Minitest的stripe-ruby-mock宝石

时间:2015-02-11 00:31:53

标签: ruby-on-rails unit-testing stripe-payments minitest

我是新手测试。我正在尝试使用带有minitest的stripe-ruby-mock gem。

在stripe-ruby-mock文档中,他们描述了Rspec中的一个虚拟示例,我试图将其转换为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

我对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

错误

NoMethodError: undefined method `describe' for SuccessfulPurchaseTest:Class

我咨询了最小的文档,以确保describe不是特定于Rspec,但事实证明它也用于minitest。我猜测实施工作没有做好。任何帮助表示赞赏。

3 个答案:

答案 0 :(得分:1)

您好我主要是Rspec的人,但我认为您的问题在于您在使用单元测试用例时正在使用和集成测试用例。请尝试以下

class SuccessfulCustomerCreationTest < MiniTest::Unit::TestCase

答案 1 :(得分:1)

我认为你在混合东西。查看单元测试规格部分的Minitest页面。 我认为您需要的是以下内容:

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

或者如果您想使用Spec语法。希望这有助于某人。

答案 2 :(得分:0)

您想要:

require 'spec_helper'

表示rspec示例。