Read more

RSpec expects pending tests to fail

Arne Hartherz
January 18, 2018Software engineer at makandra GmbH

When flagging a spec that will be implemented later as pending, include a failing spec body or RSpec 3 will consider the pending test as failing.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

The reasoning is: If the spec is flagged as pending but passes, it should not be pending. So these will fail:

it 'does something' do
  pending
end

it 'does something else' do
  pending
  expect(1).to eq(1)
end

The first case may be unexpected, if you just wanted to write down that something should eventually happen that will be implemented later.

Instead, do not supply a spec body at all:

it 'does something'

Or, if your body contains something that you want to keep, you may add fail to cause an error. RSpec will then consider the spec pending.

it 'does something' do
  pending
  # This will be interesting. Contact Bob about details.
  fail
end

Another way to exlude specs is using RSpec filters with xit, xdescribe or the like.

Posted by Arne Hartherz to makandra dev (2018-01-18 12:01)