繁体   English   中英

带Minitest的stripe-ruby-mock宝石

[英]stripe-ruby-mock gem with 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。 我猜测实施没有做好。 任何帮助赞赏。

嗨,我主要是一个Rspec人,但我认为你的问题是,当你应该使用单元测试用例时,你正在使用和集成测试用例。 请尝试以下方法

class SuccessfulCustomerCreationTest < MiniTest::Unit::TestCase

我觉得你在混合东西。 检查单元测试规格部分的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语法。 希望这有助于某人。

你想要:

require 'spec_helper'

对于rspec示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM