Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9255a39a8d1b
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6a1bb9ab2e07
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on May 11, 2016

  1. Copy the full SHA
    1ea5f75 View commit details
  2. Copy the full SHA
    6a1bb9a View commit details
Showing with 60 additions and 10 deletions.
  1. +51 −10 spec/ruby/core/module/define_method_spec.rb
  2. +7 −0 spec/ruby/core/module/fixtures/classes.rb
  3. +2 −0 spec/tags/ruby/core/module/define_method_tags.txt
61 changes: 51 additions & 10 deletions spec/ruby/core/module/define_method_spec.rb
Original file line number Diff line number Diff line change
@@ -73,19 +73,60 @@ def test_method

describe "Module#define_method when name is not a special private name" do
describe "given an UnboundMethod" do
it "sets the visibility of the method to the current visibility" do
m = Module.new do
def foo
describe "and called from the target module" do
it "sets the visibility of the method to the current visibility" do
klass = Class.new do
define_method(:bar, ModuleSpecs::EmptyFooMethod)
private
define_method(:baz, ModuleSpecs::EmptyFooMethod)
end
private :foo

klass.should have_public_instance_method(:bar)
klass.should have_private_instance_method(:baz)
end
klass = Class.new do
define_method(:bar, m.instance_method(:foo))
private
define_method(:baz, m.instance_method(:foo))
end

describe "and called from another module" do
it "sets the visibility of the method to public" do
klass = Class.new
Class.new do
klass.send(:define_method, :bar, ModuleSpecs::EmptyFooMethod)
private
klass.send(:define_method, :baz, ModuleSpecs::EmptyFooMethod)
end

klass.should have_public_instance_method(:bar)
klass.should have_public_instance_method(:baz)
end
end
end

describe "passed a block" do
describe "and called from the target module" do
it "sets the visibility of the method to the current visibility" do
klass = Class.new do
define_method(:bar) {}
private
define_method(:baz) {}
end

klass.should have_public_instance_method(:bar)
klass.should have_private_instance_method(:baz)
end
end

describe "and called from another module" do
it "sets the visibility of the method to public" do
klass = Class.new
Class.new do
klass.send(:define_method, :bar) {}
private
klass.send(:define_method, :baz) {}
end

klass.should have_public_instance_method(:bar)
klass.should have_public_instance_method(:baz)
end
klass.should have_public_instance_method(:bar)
klass.should have_private_instance_method(:baz)
end
end
end
7 changes: 7 additions & 0 deletions spec/ruby/core/module/fixtures/classes.rb
Original file line number Diff line number Diff line change
@@ -576,6 +576,13 @@ def self.===(*)
raise 'method contents are irrelevant to test'
end
end

m = Module.new do
def foo
end
private :foo
end
EmptyFooMethod = m.instance_method(:foo)
end

class Object
2 changes: 2 additions & 0 deletions spec/tags/ruby/core/module/define_method_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
fails:Module#define_method when name is :initialize passed a block sets visibility to private when method name is :initialize
fails:Module#define_method when name is :initialize given an UnboundMethod sets the visibility to private when method is named :initialize
fails:Module#define_method when name is not a special private name given an UnboundMethod and called from another module sets the visibility of the method to public
fails:Module#define_method when name is not a special private name passed a block and called from another module sets the visibility of the method to public