Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Labyrinth of How to Write RSpec Pending Rea...

ydah
June 22, 2023

The Labyrinth of How to Write RSpec Pending Reasons

MNTSQの!RubyKaigi 2023 AfterParty!「The Labyrinth of How to Write RSpec Pending Reasons」のスライド
https://techplay.jp/event/907561 #rubykaigiafterparty

ydah

June 22, 2023
Tweet

More Decks by ydah

Other Decks in Technology

Transcript

  1. ɾ Name: Yudai Takada ɾ GitHub: @ydah ɾ Twitter: @ydah_

    ɾ Member of RuboCop RSpec team ɾ Software Engineer at ANDPAD, Inc. self.inspect
  2. About RSpec/ PendingWithoutReason # bad it 'does something' do skip

    end # good it 'does something' do skip 'reason' end
  3. Case 1 RSpec.describe Foo do it 'does something' do skip

    'xxx' end it 'does something' do pending 'xxx' raise 'should not get here' end end RSpec.describe Foo do pending 'xxx' do # ... end skip 'xxx' do # ... end end
  4. Case 1 RSpec.describe Foo do it 'does something' do skip

    'xxx' end it 'does something' do pending 'xxx' raise 'should not get here' end end RSpec.describe Foo do pending 'xxx' do # ... end skip 'xxx' do # ... end end 🙆 🙅
  5. Case 3 🥺 ArgumentError: The semantics of `RSpec::Core::Pending#pending` have changed

    in RSpec 3. In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the rest of the example is still run but is expected to fail, and will be marked as a failure (rather than as pending) if the example passes. Passing a block within an example is now deprecated. Marking the example as pending provides the same behavior in RSpec 3 which was provided only by the block in RSpec 2.x. Move the code in the block provided to `pending` into the rest of the example body.
  6. Temporarily skipping by prefixing example with an x RSpec.describe "an

    example" do xit "is skipped using xit" do end xspecify "is skipped using xspecify" do end xexample "is skipped using xexample" do end end
  7. Cases to ignore in RuboCop FactoryBot.def i ne do factory

    :task do pending skip { true } end end
  8. Cases to ignore in RuboCop RSpec.describe Foo do it 'does

    something' do Foo.pending Foo.skip end end
  9. Cases to ignore in RuboCop RSpec.describe Foo do it 'does

    something' do expect('foo').to eq(pending) foo(bar, pending, skip) foo(bar, pending: pending, skip: skip) is_expected.to match_array([foo, pending, skip]) list = [skip, pending] end end
  10. end