mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@6f38a82
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b864bd05bf
commit
4fbb9aa3cb
145 changed files with 2847 additions and 2596 deletions
|
@ -1,135 +1,132 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'fixtures/classes'
|
||||
|
||||
ruby_version_is "2.0.0" do
|
||||
require_relative 'fixtures/classes'
|
||||
describe "main.using" do
|
||||
it "requires one Module argument" do
|
||||
lambda do
|
||||
eval('using', TOPLEVEL_BINDING)
|
||||
end.should raise_error(ArgumentError)
|
||||
|
||||
describe "main.using" do
|
||||
it "requires one Module argument" do
|
||||
lambda do
|
||||
eval('using', TOPLEVEL_BINDING)
|
||||
end.should raise_error(ArgumentError)
|
||||
lambda do
|
||||
eval('using "foo"', TOPLEVEL_BINDING)
|
||||
end.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
lambda do
|
||||
eval('using "foo"', TOPLEVEL_BINDING)
|
||||
end.should raise_error(TypeError)
|
||||
end
|
||||
it "uses refinements from the given module only in the target file" do
|
||||
require_relative 'fixtures/string_refinement'
|
||||
load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__)
|
||||
MainSpecs::DATA[:in_module].should == 'foo'
|
||||
MainSpecs::DATA[:toplevel].should == 'foo'
|
||||
lambda do
|
||||
'hello'.foo
|
||||
end.should raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
it "uses refinements from the given module only in the target file" do
|
||||
require_relative 'fixtures/string_refinement'
|
||||
load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__)
|
||||
MainSpecs::DATA[:in_module].should == 'foo'
|
||||
MainSpecs::DATA[:toplevel].should == 'foo'
|
||||
lambda do
|
||||
'hello'.foo
|
||||
end.should raise_error(NoMethodError)
|
||||
end
|
||||
it "uses refinements from the given module for method calls in the target file" do
|
||||
require_relative 'fixtures/string_refinement'
|
||||
load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__)
|
||||
lambda do
|
||||
'hello'.foo
|
||||
end.should raise_error(NoMethodError)
|
||||
MainSpecs.call_foo('hello').should == 'foo'
|
||||
end
|
||||
|
||||
it "uses refinements from the given module for method calls in the target file" do
|
||||
require_relative 'fixtures/string_refinement'
|
||||
load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__)
|
||||
lambda do
|
||||
'hello'.foo
|
||||
end.should raise_error(NoMethodError)
|
||||
MainSpecs.call_foo('hello').should == 'foo'
|
||||
end
|
||||
|
||||
it "uses refinements from the given module in the eval string" do
|
||||
cls = MainSpecs::DATA[:cls] = Class.new {def foo; 'foo'; end}
|
||||
MainSpecs::DATA[:mod] = Module.new do
|
||||
refine(cls) do
|
||||
def foo; 'bar'; end
|
||||
end
|
||||
it "uses refinements from the given module in the eval string" do
|
||||
cls = MainSpecs::DATA[:cls] = Class.new {def foo; 'foo'; end}
|
||||
MainSpecs::DATA[:mod] = Module.new do
|
||||
refine(cls) do
|
||||
def foo; 'bar'; end
|
||||
end
|
||||
end
|
||||
eval(<<-EOS, TOPLEVEL_BINDING).should == 'bar'
|
||||
using MainSpecs::DATA[:mod]
|
||||
MainSpecs::DATA[:cls].new.foo
|
||||
EOS
|
||||
end
|
||||
|
||||
it "does not affect methods defined before it is called" do
|
||||
cls = Class.new {def foo; 'foo'; end}
|
||||
MainSpecs::DATA[:mod] = Module.new do
|
||||
refine(cls) do
|
||||
def foo; 'bar'; end
|
||||
end
|
||||
end
|
||||
x = MainSpecs::DATA[:x] = Object.new
|
||||
eval <<-EOS, TOPLEVEL_BINDING
|
||||
x = MainSpecs::DATA[:x]
|
||||
def x.before_using(obj)
|
||||
obj.foo
|
||||
end
|
||||
using MainSpecs::DATA[:mod]
|
||||
def x.after_using(obj)
|
||||
obj.foo
|
||||
end
|
||||
EOS
|
||||
|
||||
obj = cls.new
|
||||
x.before_using(obj).should == 'foo'
|
||||
x.after_using(obj).should == 'bar'
|
||||
end
|
||||
|
||||
it "propagates refinements added to existing modules after it is called" do
|
||||
cls = Class.new {def foo; 'foo'; end}
|
||||
mod = MainSpecs::DATA[:mod] = Module.new do
|
||||
refine(cls) do
|
||||
def foo; 'quux'; end
|
||||
end
|
||||
end
|
||||
x = MainSpecs::DATA[:x] = Object.new
|
||||
eval <<-EOS, TOPLEVEL_BINDING
|
||||
using MainSpecs::DATA[:mod]
|
||||
x = MainSpecs::DATA[:x]
|
||||
def x.call_foo(obj)
|
||||
obj.foo
|
||||
end
|
||||
def x.call_bar(obj)
|
||||
obj.bar
|
||||
end
|
||||
EOS
|
||||
|
||||
obj = cls.new
|
||||
x.call_foo(obj).should == 'quux'
|
||||
|
||||
mod.module_eval do
|
||||
refine(cls) do
|
||||
def bar; 'quux'; end
|
||||
end
|
||||
eval(<<-EOS, TOPLEVEL_BINDING).should == 'bar'
|
||||
using MainSpecs::DATA[:mod]
|
||||
MainSpecs::DATA[:cls].new.foo
|
||||
EOS
|
||||
end
|
||||
|
||||
it "does not affect methods defined before it is called" do
|
||||
cls = Class.new {def foo; 'foo'; end}
|
||||
MainSpecs::DATA[:mod] = Module.new do
|
||||
refine(cls) do
|
||||
def foo; 'bar'; end
|
||||
end
|
||||
end
|
||||
x = MainSpecs::DATA[:x] = Object.new
|
||||
eval <<-EOS, TOPLEVEL_BINDING
|
||||
x = MainSpecs::DATA[:x]
|
||||
def x.before_using(obj)
|
||||
obj.foo
|
||||
end
|
||||
using MainSpecs::DATA[:mod]
|
||||
def x.after_using(obj)
|
||||
obj.foo
|
||||
end
|
||||
EOS
|
||||
x.call_bar(obj).should == 'quux'
|
||||
end
|
||||
|
||||
obj = cls.new
|
||||
x.before_using(obj).should == 'foo'
|
||||
x.after_using(obj).should == 'bar'
|
||||
it "does not propagate refinements of new modules added after it is called" do
|
||||
cls = Class.new {def foo; 'foo'; end}
|
||||
cls2 = Class.new {def bar; 'bar'; end}
|
||||
mod = MainSpecs::DATA[:mod] = Module.new do
|
||||
refine(cls) do
|
||||
def foo; 'quux'; end
|
||||
end
|
||||
end
|
||||
x = MainSpecs::DATA[:x] = Object.new
|
||||
eval <<-EOS, TOPLEVEL_BINDING
|
||||
using MainSpecs::DATA[:mod]
|
||||
x = MainSpecs::DATA[:x]
|
||||
def x.call_foo(obj)
|
||||
obj.foo
|
||||
end
|
||||
def x.call_bar(obj)
|
||||
obj.bar
|
||||
end
|
||||
EOS
|
||||
|
||||
x.call_foo(cls.new).should == 'quux'
|
||||
|
||||
mod.module_eval do
|
||||
refine(cls2) do
|
||||
def bar; 'quux'; end
|
||||
end
|
||||
end
|
||||
|
||||
it "propagates refinements added to existing modules after it is called" do
|
||||
cls = Class.new {def foo; 'foo'; end}
|
||||
mod = MainSpecs::DATA[:mod] = Module.new do
|
||||
refine(cls) do
|
||||
def foo; 'quux'; end
|
||||
end
|
||||
end
|
||||
x = MainSpecs::DATA[:x] = Object.new
|
||||
eval <<-EOS, TOPLEVEL_BINDING
|
||||
using MainSpecs::DATA[:mod]
|
||||
x = MainSpecs::DATA[:x]
|
||||
def x.call_foo(obj)
|
||||
obj.foo
|
||||
end
|
||||
def x.call_bar(obj)
|
||||
obj.bar
|
||||
end
|
||||
EOS
|
||||
|
||||
obj = cls.new
|
||||
x.call_foo(obj).should == 'quux'
|
||||
|
||||
mod.module_eval do
|
||||
refine(cls) do
|
||||
def bar; 'quux'; end
|
||||
end
|
||||
end
|
||||
|
||||
x.call_bar(obj).should == 'quux'
|
||||
end
|
||||
|
||||
it "does not propagate refinements of new modules added after it is called" do
|
||||
cls = Class.new {def foo; 'foo'; end}
|
||||
cls2 = Class.new {def bar; 'bar'; end}
|
||||
mod = MainSpecs::DATA[:mod] = Module.new do
|
||||
refine(cls) do
|
||||
def foo; 'quux'; end
|
||||
end
|
||||
end
|
||||
x = MainSpecs::DATA[:x] = Object.new
|
||||
eval <<-EOS, TOPLEVEL_BINDING
|
||||
using MainSpecs::DATA[:mod]
|
||||
x = MainSpecs::DATA[:x]
|
||||
def x.call_foo(obj)
|
||||
obj.foo
|
||||
end
|
||||
def x.call_bar(obj)
|
||||
obj.bar
|
||||
end
|
||||
EOS
|
||||
|
||||
x.call_foo(cls.new).should == 'quux'
|
||||
|
||||
mod.module_eval do
|
||||
refine(cls2) do
|
||||
def bar; 'quux'; end
|
||||
end
|
||||
end
|
||||
|
||||
x.call_bar(cls2.new).should == 'bar'
|
||||
end
|
||||
x.call_bar(cls2.new).should == 'bar'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue