Slide 1

Slide 1 text

Yudai Takada RubyKaigi 2023 After Party 2023.06.22 (Thu) The Labyrinth of How to Write RSpec Pending Reasons

Slide 2

Slide 2 text

ɾ Name: Yudai Takada ɾ GitHub: @ydah ɾ Twitter: @ydah_ ɾ Member of RuboCop RSpec team ɾ Software Engineer at ANDPAD, Inc. self.inspect

Slide 3

Slide 3 text

ݐஙɾݐઃۀʹಛԽͨ͠Ϋϥ΢υαʔϏε ఏڙ

Slide 4

Slide 4 text

⼤阪Ruby会議03 "Rubyで笑おう" 2023-09-09 (Sat) 2023-06-23 23:55 CFP締切

Slide 5

Slide 5 text

Today’s Talk

Slide 6

Slide 6 text

Today, I talk about another proposal

Slide 7

Slide 7 text

RSpec

Slide 8

Slide 8 text

About RSpec pending and skip

Slide 9

Slide 9 text

RSpec/PendingWithoutReason

Slide 10

Slide 10 text

About RSpec/ PendingWithoutReason 34QFD1FOEJOH8JUIPVU3FBTPOJTBDPQGPS 3VCP$PQ34QFD 
 
 5IJTDPQDIFDLTGPSQFOEJOHPSTLJQQFE FYBNQMFTXJUIPVUSFBTPO

Slide 11

Slide 11 text

About RSpec/ PendingWithoutReason # bad it 'does something' do skip end # good it 'does something' do skip 'reason' end

Slide 12

Slide 12 text

Result Foo does something (PENDING : No reason given) does something (PENDING : reason)

Slide 13

Slide 13 text

Is it surprisingly easy?

Slide 14

Slide 14 text

🙅

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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 🙆 🙅

Slide 17

Slide 17 text

Case 2 RSpec.describe Foo do it 'does something' do skip 'xxx' do # . .. end end end

Slide 18

Slide 18 text

Case 2 🙆 Foo does something (PENDING: xxx)

Slide 19

Slide 19 text

Case 3 RSpec.describe Foo do it 'does something' do pending 'xxx' do # . .. end end end

Slide 20

Slide 20 text

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.

Slide 21

Slide 21 text

Various ways to skip/pending still exist

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Skipping using metadata RSpec.describe "an example" do example "is skipped", :skip => true do end end

Slide 24

Slide 24 text

When implementing a RuboCop’s cop, there are additional considerations to take into account 😇

Slide 25

Slide 25 text

Cases to ignore in RuboCop FactoryBot.def i ne do factory :task do pending skip { true } end end

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

Writing reasons for pending or skip in RSpec was a labyrinth…

Slide 29

Slide 29 text

end