Skip to content

Commit 9af32c6

Browse files
committed
Minor cleanup of #define_method specs
1 parent 6a05406 commit 9af32c6

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

spec/ruby/core/module/define_method_spec.rb

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -500,34 +500,31 @@ def foo
500500
}.should raise_error(TypeError, /can't bind singleton method to a different class/)
501501
end
502502

503-
it "defines the new method public when the definition frame self is different from the target" do
504-
foo_class = Class.new do
505-
private def bar
503+
it "defines a new method with public visibility when a Method passed and the class/module of the context isn't equal to the receiver of #define_method" do
504+
c = Class.new do
505+
private def foo
506506
"public"
507507
end
508508
end
509509

510-
foo = foo_class.new
511-
foo.singleton_class.define_method(:bar, foo.method(:bar))
510+
object = c.new
511+
object.singleton_class.define_method(:bar, object.method(:foo))
512512

513-
foo.bar.should == "public"
513+
object.bar.should == "public"
514514
end
515515

516-
it "defines the new method according to the scope when the definition context is the same" do
517-
FooWithOneBar = Class.new do
518-
def bar; end
516+
it "defines the new method according to the scope visibility when a Method passed and the class/module of the context is equal to the receiver of #define_method" do
517+
c = Class.new do
518+
def foo; end
519519
end
520520

521-
foo = FooWithOneBar.new
522-
523-
class << foo
521+
object = c.new
522+
object.singleton_class.class_eval do
524523
private
525-
define_method(:bar, FooWithOneBar.new.method(:bar))
524+
define_method(:bar, c.new.method(:foo))
526525
end
527526

528-
-> { foo.bar }.should raise_error(NoMethodError)
529-
530-
Object.class_eval { remove_const(:FooWithOneBar) }
527+
-> { object.bar }.should raise_error(NoMethodError)
531528
end
532529
end
533530

0 commit comments

Comments
 (0)