Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rspec pending results in falied test

it 'should be an array and not be empty' do
  pending
  expect(a.class).to be(Array)
  expect(a.empty?).to be(false)
  expect(a.first.class).to be(ExampleClass)
end

When I run rspec:

Failures:

  1) should be an array and not be empty FIXED
     Expected pending 'No reason given' to fail. No Error was raised.
     # ./spec/example_spec.rb:19

Any ideas why this is being listed as a failure?

like image 314
Eric Francis Avatar asked Jul 30 '14 16:07

Eric Francis


People also ask

What is pending in RSpec?

`pending` examples RSpec offers a number of different ways to indicate that an example is. disabled pending some action. `pending` any arbitrary reason with a failing example. `pending` any arbitrary reason with a passing example. `pending` for an example that is currently passing.

How do I skip a test in RSpec?

- In RSpec, it's also possible to skip over certain examples. We can do that by marking them as being pending, or by telling it that it ought to skip them.


2 Answers

As of Rspec 3.x, pending specs are actually run, and if they pass, it's considered a failure (because if it passes, then Rspec thinks it shouldn't be pending).

You can use skip instead of pending to make sure your spec doesn't actually run.

More info: https://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#changes-to-pending-semantics-and-introduction-of-skip

like image 155
Dylan Markow Avatar answered Oct 05 '22 00:10

Dylan Markow


Here's your clue:

should be an array and not be empty FIXED

Things that pass will cause a pending test to fail. Check the docs for examples [1], [2].

  1. RSpec 2
  2. RSpec 3
like image 30
Nick Veys Avatar answered Oct 05 '22 01:10

Nick Veys