2015-02-11 60 views
3

我是新来的测试。我正在尝试用minitest使用条纹红宝石模拟宝石。条纹红宝石模拟宝石与MINITEST

在条纹红宝石模拟文档他们描述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: '[email protected]', 
     card: stripe_helper.generate_card_token 
    }) 
    expect(customer.email).to eq('[email protected]') 
    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: "[email protected]", 
             card: stripe_helper.generate_card_token 
            }) 
     assert_equal customer.email, "[email protected]" 
    end 
    end 
end 

错误

NoMethodError: undefined method `describe' for SuccessfulPurchaseTest:Class 

我查阅了minitest文档以确保describe不是特定于R规范,但事实证明,它也用于minitest。我猜测实施没有做好。任何帮助赞赏。

回答

1

嗨,我主要是一个RSpec的家伙,但我觉得你的问题是,你正在使用和集成测试情况下,你应该使用的单元测试用例。尝试以下代替

class SuccessfulCustomerCreationTest < MiniTest::Unit::TestCase 
1

我认为你是混合的东西。检查部分单元测试规格​​页。 我想你需要的是以下几点:

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: "[email protected]", 
             card: stripe_helper.generate_card_token 
             }) 
    assert_equal customer.email, "[email protected]" 
    end 
end 

或者,如果你想使用规格语法。希望这可以帮助某人。

0

你想要求:

require 'spec_helper' 

的RSpec的例子。