rspec/rspec-core

Nested `skip` behaves weird, is this intended?

stillhart opened this issue · 1 comments

Subject of the issue

I run into the issue that my specs run when I didn't expect them to run. I would expect that if I set a block to be skipped, that all nested examples are skipped. This is not always true.

I could not find out if it is on purpose or not. I found it especially weird when I set skip to nil, which of course is falsy. I at least expected nil to take the parent's skip status, instead of disabling skip.

In my case skip was set to nil due to some meta programming. The solution would to remove the skip option in that case.

Your environment

  • Ruby version: 3.2.2
  • rspec-core version: 3.12.2

Steps to reproduce

RSpec.describe "skip" do
  describe "", skip: true do
    # I expect all examples to be skipped, no matter if skip is set or not.
    it "is skipped via describe" do
    end
    describe "describe group should be skipped due to parent being skipped" do
      it "is undefined" do end
      it "is nil", skip: nil do end
      it "is false", skip: false do end
      it "is true", skip: true do end
    end
  end
end

Expected behavior

I would expect all nested examples to be skipped

Actual behavior

Not all examples are skipped. Those with skip set to nil or false are run anyway.

**..*
Pending: (Failures listed here are expected and do not affect your suite's status)
  1) skip  is skipped via describe
     # No reason given
     # ./skip_spec.rb:3
  2) skip  describe group should be skipped due to parent being skipped is undefined
     # No reason given
     # ./skip_spec.rb:6
  3) skip  describe group should be skipped due to parent being skipped is true
     # No reason given
     # ./skip_spec.rb:9
5 examples, 0 failures, 3 pending

This is intended, group metadata is copied down to examples and they are processed at that level, so you've essentially overridden the metadata by setting it to falsey.