From 692db5fbac9f8f75071e8c7198260eb8d10f9d47 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 22 Oct 2024 22:34:11 +0100 Subject: [PATCH] Fix usage of example for when its redefined --- lib/rspec/its.rb | 4 +++- spec/rspec/its_spec.rb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/rspec/its.rb b/lib/rspec/its.rb index 4eb83ba..6d357a1 100644 --- a/lib/rspec/its.rb +++ b/lib/rspec/its.rb @@ -1,6 +1,8 @@ require 'rspec/its/version' require 'rspec/core' +RSpec::Core::ExampleGroup.define_example_method :__its_example + module RSpec module Its @@ -166,7 +168,7 @@ def should_not(matcher=nil, message=nil) options << {} unless options.last.kind_of?(Hash) options.last.merge!(:caller => its_caller) - example(nil, *options, &block) + __its_example(nil, *options, &block) end end diff --git a/spec/rspec/its_spec.rb b/spec/rspec/its_spec.rb index ebc59d5..239b2e4 100644 --- a/spec/rspec/its_spec.rb +++ b/spec/rspec/its_spec.rb @@ -9,6 +9,7 @@ module RSpec its([]) { expect(described_class).to be Its } end end + context "with explicit subject" do subject do Class.new do @@ -375,6 +376,20 @@ def terminator raise_error(ArgumentError, '`will_not` only supports block expectations') end end + + context "when example is redefined" do + subject do + Class.new do + def will_still_work; true; end + end.new + end + + def self.example(*_args) + raise + end + + its(:will_still_work) { is_expected.to be true } + end end end end