我正在实施Stripe并进行集成测试。 Stripe提供了多个CC编号,我想迭代这些编号。类似的东西:
@stripe_success_cards = [
"4242424242424242", #Visa
"4012888888881881", #Visa
"4000056655665556", #Visa debit
"5555555555554444", #MC
"5200828282828210", #MC debit
"378282246310005", #AmEx
"371449635398431", #AmEx
"6011111111111117", #Discover
"6011000990139424", #Discover
"30569309025904", #Diner's club
"38520000023237", #Diner's club
"3530111333300000", #JCB
"3566002020360505" #JCB
]
@stripe_success_cards.each do |card_number|
describe "user fills out Stripe information"
before do
page.execute_script(%Q{ $('input#card_number').val('#{card_number}'); })
end
it "should successfully trigger charge" do
...
end
end
end
但由于Rspec集成测试中的变量限制,上述方法无效。我怎样才能做到这一点?只是试图保持测试DRY,因为真正的每个表单都有很多要填写,并且有很多例子可以通过。
谢谢!
答案 0 :(得分:0)
如果您使用局部变量而不是实例变量,这将起作用:
stripe_success_cards = [
"4242424242424242", #Visa
"4012888888881881", #Visa
"4000056655665556", #Visa debit
"5555555555554444", #MC
"5200828282828210", #MC debit
"378282246310005", #AmEx
"371449635398431", #AmEx
"6011111111111117", #Discover
"6011000990139424", #Discover
"30569309025904", #Diner's club
"38520000023237", #Diner's club
"3530111333300000", #JCB
"3566002020360505" #JCB
]
stripe_success_cards.each do |card_number|
describe "user fills out Stripe information"
before do
page.execute_script(%Q{ $('input#card_number').val('#{card_number}'); })
end
it "should successfully trigger charge" do
...
end
end
end