RSpec testing a series of actions
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)开发者_Python百科
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
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)
精彩评论