ruby-on-rails - 带有 Minitest 的 stripe-ruby-mock gem

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

我是测试新手。我正在尝试将 stripe-ruby-mock gem 与 minitest 一起使用。

在 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

我查阅了 minitest 文档以确保 describe 不是特定于 Rspec,但事实证明它也用于 minitest。我猜实现没有正确完成。任何帮助表示赞赏。

最佳答案

您好,我主要是 Rspec 人员,但我认为您的问题是您在应该使用单元测试用例时使用了集成测试用例。请尝试以下操作

class SuccessfulCustomerCreationTest < MiniTest::Unit::TestCase

关于ruby-on-rails - 带有 Minitest 的 stripe-ruby-mock gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28444507/

相关文章:

ruby-on-rails - 在哪里使用 find_or_create_by 方法?

php - Web应用的瓶颈?

python - factoryboy pytest session 管理

javascript - 视觉 : How to mock Auth0 for testing with Vitest

python-2.7 - 测试期间无法禁用WTF CSRF保护

javascript - 如何在Stripe Js中将additional_owners设置为null?

payment - Stripe Payment支持自动循环付款吗?

ruby-on-rails - Rails enumerables : why would find_all{. ..}.count 返回的值与 count{...} 不同?

ruby-on-rails - 渲染json并返回

javascript - Stripe 支付表格不适用于 Django,无法检索 token