Ruby on rails 消除RSpec上下文中的重复代码
这是我的rspec文件。我有Ruby on rails 消除RSpec上下文中的重复代码,ruby-on-rails,rspec,Ruby On Rails,Rspec,这是我的rspec文件。我有PosRequest.authorization\u card(@payment\u detail)行3次。有没有更简单的方法来编写此上下文 context 'should get' do it 'error message' do PosRequest.authorize_card(@payment_detail) @payment_detail.errorMsg.should_not eql(:nil) end
PosRequest.authorization\u card(@payment\u detail)
行3次。有没有更简单的方法来编写此上下文
context 'should get' do
it 'error message' do
PosRequest.authorize_card(@payment_detail)
@payment_detail.errorMsg.should_not eql(:nil)
end
it 'bank message' do
PosRequest.authorize_card(@payment_detail)
@payment_detail.cardMsg.should_not eql(:nil)
end
it 'claim message' do
PosRequest.authorize_card(@payment_detail)
@payment_detail.bankMsg.should_not eql(:nil)
end
end
我编辑这篇文章是为了添加动词,以便您更清楚地了解每个规范的作用 在您的
上下文中
您可以使用已经建议的
before do
do_something
end
对于此上下文中的所有测试,它将只运行一次,或者您可以使用
before :each do
do_something
end
这将在这个上下文中为每个测试运行一次do\u something
,您可以选择更适合您需要的测试
before :each do
do_something
end