Skip to content

Commit

Permalink
refactor so we dont leak define_method into public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Apr 18, 2013
1 parent 5200ad6 commit 83ca533
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/rspec/core/memoized_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,16 @@ def self.module_for(example_group)
get_constant_or_yield(example_group, :LetDefinitions) do
mod = Module.new do
include Module.new {
public_class_method :define_method
example_group.const_set(:NamedSubjectPreventSuper, self)
public
def self.define_method *args
super
end
}

# Expose `define_method` as a public method, so we can
# easily use it below.
public_class_method :define_method
public
def self.define_method *args
super
end
end

example_group.__send__(:include, mod)
Expand Down
7 changes: 7 additions & 0 deletions spec/rspec/core/memoized_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -659,5 +659,12 @@ def define_and_run_group
end
end
end

describe 'Module#define_method' do
it 'is still a private method' do
a_module = Module.new
expect { a_module.define_method(:name) { "implementation" } }.to raise_error NoMethodError
end
end
end

0 comments on commit 83ca533

Please sign in to comment.