简体   繁体   中英

Running rspec tests for specific contexts

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM