我是测试新手。我正在尝试将 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/