2015-02-11 83 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的例子。