RSpec测试一系列动作
我有一个复杂的交易流程,我想使用 RSpec 进行测试。我想在每个步骤之后进行一些检查。我只知道如何在单独的操作中测试它们。因此,在每个步骤中,我必须添加在前面的步骤中已指定的操作,如下所示:
it "should add money to account A through deposit"
a.deposit(10)
a.balance.should == 10
end
it "should subtract money from A through transfer"
a.deposit(10)
a.transfer b, 5
a.balance.should == 5
b.balance.should == 5
end
it "should reverse transaction through reverse"
a.deposit(10)
a.transfer b, 5
a.reserve b, 5
a.balance.should == 10
b. balance.should == 10
end
我想要做的是:
it "should perform a series of actions successfully"
a.deposit(10)
# checking here
a.transfer b, 5
# checking here
a.reserve b, 5
# checking here
end
可以这样做吗?
谢谢
I have a complex transaction process I want to test using RSpec. I would like to have some checking after each step. I only know how to test them in separate actions. So in each step, I have to add actions I already specified in previous steps as follow:
it "should add money to account A through deposit"
a.deposit(10)
a.balance.should == 10
end
it "should subtract money from A through transfer"
a.deposit(10)
a.transfer b, 5
a.balance.should == 5
b.balance.should == 5
end
it "should reverse transaction through reverse"
a.deposit(10)
a.transfer b, 5
a.reserve b, 5
a.balance.should == 10
b. balance.should == 10
end
What I want to do is:
it "should perform a series of actions successfully"
a.deposit(10)
# checking here
a.transfer b, 5
# checking here
a.reserve b, 5
# checking here
end
Is it possible to do?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您最初的测试实际上更好,因为如果失败,您将更好地了解问题出在哪里。如果您想减少每个测试之间的重复,请使用 before(:each)
Your original tests are actually better, because if one fails you'll have a better understanding of where the problem was. If you want to reduce the duplication between each test, use before(:each)