Search code examples
ruby-on-railsrubyruby-on-rails-4rspec

How do I run an RSpec test on a specific line?


I have next spec file:

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

And I want to run test from 16 line (not entire test), so I type:

rspec spec/models/orders_spec.rb -l16

Instead of get running test, i get next error:

invalid option: -l18

How to run test from a certain line?


Solution

  • You'll want to use the format rspec path/to/spec.rb:line_no.

    (i.e.) rspec spec/models/orders_spec.rb:16

    Here's a link to RelishApp (the best location for the RSpec documentation) if you'd like some more reading.