Skip to content

Commit

Permalink
Fix usage of example for when its redefined
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Oct 22, 2024
1 parent 14297a7 commit 692db5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rspec/its.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'rspec/its/version'
require 'rspec/core'

RSpec::Core::ExampleGroup.define_example_method :__its_example

module RSpec
module Its

Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/rspec/its_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 692db5f

Please sign in to comment.