rspec / rspec-support

Common code needed by the other RSpec gems. Not intended for direct use.
https://rspec.info
MIT License
96 stars 104 forks source link

in_sub_process doesn't seem to work with around hook #498

Open nomasprime opened 3 years ago

nomasprime commented 3 years ago

Example passes with pseudo before hack:

    context "with empty block" do
      let(:before) { described_class.send(:configure) {} }

      describe ".configuration" do
        it "returns Configuration instance" do
          in_sub_process do
            before
            expect(described_class.send(:configuration)).to be_an_instance_of(described_class::Configuration)
          end
        end
      end

Example seems to be inappropriately marked pending with around hook:

    context "with empty block" do
      around(:each) do |example|
        in_sub_process do
          described_class.send(:configure) {}
          example.run
        end
      end

      describe ".configuration" do
        it "returns Configuration instance" do
            expect(described_class.send(:configuration)).to be_an_instance_of(described_class::Configuration)
        end
      end

Expect this to also pass.

Your environment

pirj commented 3 years ago

That confirms my experience, thanks for reporting. Do you think this can be fixed, @nomasprime ?

nomasprime commented 3 years ago

@pirj sure.

My RSpec internals knowledge isn't great but I'll try to have a look when I have more time.

Maybe one of the authors would have a better idea.

pirj commented 3 years ago

Just by glancing over, I'd suggest taking a look at run_around_example_hooks_for. Pending.mark_pending! might be an interesting place to peek at.

JonRowe commented 3 years ago

I can't replicate this atm to confirm (I get a different error) but this will be because of how hooks are run, you'll need to tell the parent process the example has been run.