Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

(refactor): Avoid calling superclass.method #2112

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rspec/core/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def initialize(example_group_class, description, user_metadata, example_block=ni

@metadata = Metadata::ExampleHash.create(
@example_group_class.metadata, user_metadata,
example_group_class.method(:next_runnable_index_for),
lambda { |file| example_group_class.next_runnable_index_for(file) },
description, example_block
)

Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def self.set_it_up(description, *args, &example_group_block)

@metadata = Metadata::ExampleGroupHash.create(
superclass_metadata, user_metadata,
superclass.method(:next_runnable_index_for),
lambda { |file| superclass.next_runnable_index_for(file) },
description, *args, &example_group_block
)
ExampleGroups.assign_const(self)
Expand Down
18 changes: 18 additions & 0 deletions spec/rspec/core/example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1912,5 +1912,23 @@ def group_ids group
expect(group.examples.length).to eq(0)
expect(original_ids).to_not eq(group_ids(group))
end

it 'allows extensions to add `method` to the DSL without causing problems' do
http_testing_extension = Module.new do
attr_reader :http_method
def method(meth); @http_method = meth; end
end

describe_successfully do
extend http_testing_extension
method :get

describe('group') do
it "allows `method` to specify the HTTP method" do
expect(self.class.http_method).to eq(:get)
end
end
end
end
end
end
16 changes: 16 additions & 0 deletions spec/rspec/core/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -797,4 +797,20 @@ def expect_pending_result(example)
expect(example.reporter).to be reporter
end
end

it 'allows extensions to add `method` to the DSL without causing problems' do
http_testing_extension = Module.new do
attr_reader :http_method
def method(meth); @http_method = meth; end
end

describe_successfully do
extend http_testing_extension
method :get

it "allows `method` to specify the HTTP method" do
expect(self.class.http_method).to eq(:get)
end
end
end
end