1

I asked it in rspec-core repository (https://github.com/rspec/rspec-core/issues/2477) but after that I thought that it is not the proper place to ask questions.

Let's say I have this group:

it { should be_a Array }
it { should include :something }
it { should include :another }

Can I prevent rspec from running examples 2 and 3 if first one is failed? Yes, I know that I can join them in one to solve this, but still.

Sorry for my english

UPD. I want to add some explanation on this. I want this because I tired of getting 3 screens of same error messages from different examples if subject is bugged (or something like this). Even if you don't overuse should-oneliners like me you may face the same problem. In the end it will just speed up your tests in some cases

Nondv
  • 769
  • 6
  • 11
  • You're not interested in aborting if a __specific one test__ fails, are you? More like, you don't want to get 3 screens of error messages? – Sergio Tulentsev Nov 10 '17 at 12:11

1 Answers1

0

It goes against the purpose of the specs, so I wouldn't be surprised if there's no way to do that.

The specs are supposed to be self-sufficient and independent from others (this includes independence from execution order). If you really want/need to maintain order and abort at first failed assertion, make them one spec.

it do
  expect(subject).to be_an Array
  expect(subject).to include :something
  expect(subject).to include :another
end

RE: the question update

I want this because I tired of getting 3 screens of same error messages from different examples if subject is bugged (or something like this).

Ah, I see. In this case, you can use the "fail fast" mode.

https://relishapp.com/rspec/rspec-core/docs/command-line/fail-fast-option

Use the --fail-fast option to tell RSpec to stop running the test suite on the first failed test.

You may add a parameter to tell RSpec to stop running the test suite after N failed tests, for example: --fail-fast=3.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • Anyway. Even with multiline examples: if you have error in your subject, all examples in your group will fail with the same error (mb with a large inspect) – Nondv Nov 10 '17 at 11:47
  • @Nondv: "all examples in your group will fail" - but so will all examples in your case, if you have an error in _your_ subject. ¯\\_(ツ)_/¯ – Sergio Tulentsev Nov 10 '17 at 12:03
  • @Nondv: "Oneliners with should is a way more readable" - I tend to agree, but it's not always the case. Sometimes the setup is too expensive. Sometimes you want to maintain the order. – Sergio Tulentsev Nov 10 '17 at 12:05
  • `--fail-fast` is still not a solution (but thanks, I didnt know about this). – Nondv Nov 10 '17 at 12:34
  • "but so will all examples in your case". No if I am able to prevent other tests from running. First one fails (because of subject) and others are skipped. – Nondv Nov 10 '17 at 12:35
  • _Sidenote:_ all known to me good CI run examples in parallel. That said, **the order is undefined**. I doubt anybody would provide the specific code for people who run examples synchronously (for almost 15 years already.) – Aleksei Matiushkin Nov 10 '17 at 12:45
  • @Nondv: perhaps this should work better? https://stackoverflow.com/a/26164289/125816 – Sergio Tulentsev Nov 10 '17 at 13:16