我有下一个spec文件:
require 'rails_helper'
describe Order do
it "calculates the total price of the order" do
item1 = create(:item)
item2 = create(:item, price: 20)
order = create(:order)
order.items << item1
order.items << item2
order.calculate_total
expect(order.total).to eq(30)
end
it "raises exception if order has no items in it" do
expect { create(:order) }.to raise_exception
end
end
我想从16行开始运行测试(不是整个测试),所以我输入:
rspec spec/models/orders_spec.rb -l16
而不是得到运行测试,我得到下一个错误:
invalid option: -l18
如何从某一行运行测试?
3条答案
按热度按时间tvz2xvvm1#
您将需要使用
rspec path/to/spec.rb:line_no
。(即)
rspec spec/models/orders_spec.rb:16
如果您想了解更多阅读内容,这里有一个RelishApp的链接(RSpec文档的最佳位置)。
vohkndzv2#
使用行号的问题是,在调试过程中,当您在行号之前添加或删除行时,行号可能会发生更改。
使用rspec更可预测的方法是使用
-e <example name>
。在这种情况下:rspec -e "raises exception if order has no items in it"
35g0bw713#
如果你需要在一个特定的行号运行RSpec,你可以使用冒号
在这里,RSpec将只运行第20行上的测试:
对于多个测试,请使用多个冒号
在这里,RSpec只运行第20、26、37行的测试