0

I have an rspec test defined like below. I know that I can run rspec -e "guessing" to run the full block of tests, but I want to run only specific contexts at a time. This way I can code the "correctly" tests first, and then later the "incorrectly" portion. Is there a command line way run the specified tests without naming them individually?

describe 'guessing' do
  context 'correctly' do
    it 'changes correct guess list' do

    end
    it 'returns true' do

    end
  end
  context 'incorrectly' do
    it 'changes wrong guess list' do

    end
    it 'returns true' do

    end
  end
end
Asif
  • 748
  • 3
  • 9
  • 32
  • 1
    You can reference each line number. `$ rspec file:3` runs the `'changes correct guess list'` example. – Sebastián Palma Aug 08 '18 at 00:49
  • Possible duplicate: https://stackoverflow.com/questions/6116668/rspec-how-to-run-a-single-test – Casper Aug 08 '18 at 00:54
  • Possible duplicate of [How do I run only specific tests in Rspec?](https://stackoverflow.com/questions/5069677/how-do-i-run-only-specific-tests-in-rspec) – Jagdeep Singh Aug 08 '18 at 06:55

1 Answers1

1

You can use -e to match any part of the description, so rspec -e incorrectly will run those two tests. (I don't know of a way to only match "correctly", as it's also a substring of "incorrectly".)

You can also use a line number reference to match a context block: rspec your_spec.rb:2 (given the above content exactly, with context 'correctly' do on line 2) will run that set of specs.

matthewd
  • 4,332
  • 15
  • 21
  • Assuming it is part of a larger string, to match "correctly" without matching "incorrectly", just add a preceding space: " correctly". – aridlehoover Aug 19 '18 at 23:04