diff options
Diffstat (limited to 'spec/ruby/core/main')
| -rw-r--r-- | spec/ruby/core/main/define_method_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/core/main/fixtures/using.rb | 1 | ||||
| -rw-r--r-- | spec/ruby/core/main/fixtures/using_in_main.rb | 5 | ||||
| -rw-r--r-- | spec/ruby/core/main/fixtures/using_in_method.rb | 5 | ||||
| -rw-r--r-- | spec/ruby/core/main/include_spec.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/main/private_spec.rb | 24 | ||||
| -rw-r--r-- | spec/ruby/core/main/public_spec.rb | 25 | ||||
| -rw-r--r-- | spec/ruby/core/main/ruby2_keywords_spec.rb | 9 | ||||
| -rw-r--r-- | spec/ruby/core/main/using_spec.rb | 26 |
9 files changed, 70 insertions, 35 deletions
diff --git a/spec/ruby/core/main/define_method_spec.rb b/spec/ruby/core/main/define_method_spec.rb index d85c5e8119..5279d078c3 100644 --- a/spec/ruby/core/main/define_method_spec.rb +++ b/spec/ruby/core/main/define_method_spec.rb @@ -14,15 +14,15 @@ describe "main#define_method" do it 'creates a public method in TOPLEVEL_BINDING' do eval @code, TOPLEVEL_BINDING - Object.should have_method :boom + Object.should.respond_to? :boom end it 'creates a public method in script binding' do eval @code, script_binding - Object.should have_method :boom + Object.should.respond_to? :boom end it 'returns the method name as symbol' do - eval(@code, TOPLEVEL_BINDING).should equal :boom + eval(@code, TOPLEVEL_BINDING).should.equal? :boom end end diff --git a/spec/ruby/core/main/fixtures/using.rb b/spec/ruby/core/main/fixtures/using.rb new file mode 100644 index 0000000000..30713ef309 --- /dev/null +++ b/spec/ruby/core/main/fixtures/using.rb @@ -0,0 +1 @@ +using Module.new diff --git a/spec/ruby/core/main/fixtures/using_in_main.rb b/spec/ruby/core/main/fixtures/using_in_main.rb new file mode 100644 index 0000000000..a4a71c89cc --- /dev/null +++ b/spec/ruby/core/main/fixtures/using_in_main.rb @@ -0,0 +1,5 @@ +MAIN = self + +module X + MAIN.send(:using, Module.new) +end diff --git a/spec/ruby/core/main/fixtures/using_in_method.rb b/spec/ruby/core/main/fixtures/using_in_method.rb new file mode 100644 index 0000000000..d9ea2e9ef0 --- /dev/null +++ b/spec/ruby/core/main/fixtures/using_in_method.rb @@ -0,0 +1,5 @@ +def foo + using Module.new +end + +foo diff --git a/spec/ruby/core/main/include_spec.rb b/spec/ruby/core/main/include_spec.rb index 9f5a5f54ea..09f8d4d3b5 100644 --- a/spec/ruby/core/main/include_spec.rb +++ b/spec/ruby/core/main/include_spec.rb @@ -4,13 +4,13 @@ require_relative 'fixtures/classes' describe "main#include" do it "includes the given Module in Object" do eval "include MainSpecs::Module", TOPLEVEL_BINDING - Object.ancestors.should include(MainSpecs::Module) + Object.ancestors.should.include?(MainSpecs::Module) end context "in a file loaded with wrapping" do it "includes the given Module in the load wrapper" do load(File.expand_path("../fixtures/wrapped_include.rb", __FILE__), true) - Object.ancestors.should_not include(MainSpecs::WrapIncludeModule) + Object.ancestors.should_not.include?(MainSpecs::WrapIncludeModule) end end end diff --git a/spec/ruby/core/main/private_spec.rb b/spec/ruby/core/main/private_spec.rb index 78c5d287d4..56a39ae3c1 100644 --- a/spec/ruby/core/main/private_spec.rb +++ b/spec/ruby/core/main/private_spec.rb @@ -10,35 +10,33 @@ describe "main#private" do context "when single argument is passed and it is not an array" do it "sets the visibility of the given methods to private" do eval "private :main_public_method", TOPLEVEL_BINDING - Object.should have_private_method(:main_public_method) + Object.private_methods(true).should.include?(:main_public_method) end end context "when multiple arguments are passed" do it "sets the visibility of the given methods to private" do eval "private :main_public_method, :main_public_method2", TOPLEVEL_BINDING - Object.should have_private_method(:main_public_method) - Object.should have_private_method(:main_public_method2) + Object.private_methods(true).should.include?(:main_public_method) + Object.private_methods(true).should.include?(:main_public_method2) end end - ruby_version_is "3.0" do - context "when single argument is passed and is an array" do - it "sets the visibility of the given methods to private" do - eval "private [:main_public_method, :main_public_method2]", TOPLEVEL_BINDING - Object.should have_private_method(:main_public_method) - Object.should have_private_method(:main_public_method2) - end + context "when single argument is passed and is an array" do + it "sets the visibility of the given methods to private" do + eval "private [:main_public_method, :main_public_method2]", TOPLEVEL_BINDING + Object.private_methods(true).should.include?(:main_public_method) + Object.private_methods(true).should.include?(:main_public_method2) end end - it "returns Object" do - eval("private :main_public_method", TOPLEVEL_BINDING).should equal(Object) + it "returns argument" do + eval("private :main_public_method", TOPLEVEL_BINDING).should.equal?(:main_public_method) end it "raises a NameError when at least one of given method names is undefined" do -> do eval "private :main_public_method, :main_undefined_method", TOPLEVEL_BINDING - end.should raise_error(NameError) + end.should.raise(NameError) end end diff --git a/spec/ruby/core/main/public_spec.rb b/spec/ruby/core/main/public_spec.rb index bfc27a9e80..89368ebb0d 100644 --- a/spec/ruby/core/main/public_spec.rb +++ b/spec/ruby/core/main/public_spec.rb @@ -10,35 +10,34 @@ describe "main#public" do context "when single argument is passed and it is not an array" do it "sets the visibility of the given methods to public" do eval "public :main_private_method", TOPLEVEL_BINDING - Object.should_not have_private_method(:main_private_method) + Object.private_methods(true).should_not.include?(:main_private_method) end end context "when multiple arguments are passed" do it "sets the visibility of the given methods to public" do eval "public :main_private_method, :main_private_method2", TOPLEVEL_BINDING - Object.should_not have_private_method(:main_private_method) - Object.should_not have_private_method(:main_private_method2) + Object.private_methods(true).should_not.include?(:main_private_method) + Object.private_methods(true).should_not.include?(:main_private_method2) end end - ruby_version_is "3.0" do - context "when single argument is passed and is an array" do - it "sets the visibility of the given methods to public" do - eval "public [:main_private_method, :main_private_method2]", TOPLEVEL_BINDING - Object.should_not have_private_method(:main_private_method) - Object.should_not have_private_method(:main_private_method2) - end + context "when single argument is passed and is an array" do + it "sets the visibility of the given methods to public" do + eval "public [:main_private_method, :main_private_method2]", TOPLEVEL_BINDING + Object.private_methods(true).should_not.include?(:main_private_method) + Object.private_methods(true).should_not.include?(:main_private_method2) end end - it "returns Object" do - eval("public :main_private_method", TOPLEVEL_BINDING).should equal(Object) + it "returns argument" do + eval("public :main_private_method", TOPLEVEL_BINDING).should.equal?(:main_private_method) end + it "raises a NameError when given an undefined name" do -> do eval "public :main_undefined_method", TOPLEVEL_BINDING - end.should raise_error(NameError) + end.should.raise(NameError) end end diff --git a/spec/ruby/core/main/ruby2_keywords_spec.rb b/spec/ruby/core/main/ruby2_keywords_spec.rb new file mode 100644 index 0000000000..d12c0ed4e4 --- /dev/null +++ b/spec/ruby/core/main/ruby2_keywords_spec.rb @@ -0,0 +1,9 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +describe "main.ruby2_keywords" do + it "is the same as Object.ruby2_keywords" do + main = TOPLEVEL_BINDING.receiver + main.private_methods(false).should.include?(:ruby2_keywords) + end +end diff --git a/spec/ruby/core/main/using_spec.rb b/spec/ruby/core/main/using_spec.rb index f9f709f7dc..314a6be416 100644 --- a/spec/ruby/core/main/using_spec.rb +++ b/spec/ruby/core/main/using_spec.rb @@ -5,11 +5,11 @@ describe "main.using" do it "requires one Module argument" do -> do eval('using', TOPLEVEL_BINDING) - end.should raise_error(ArgumentError) + end.should.raise(ArgumentError) -> do eval('using "foo"', TOPLEVEL_BINDING) - end.should raise_error(TypeError) + end.should.raise(TypeError) end it "uses refinements from the given module only in the target file" do @@ -19,7 +19,7 @@ describe "main.using" do MainSpecs::DATA[:toplevel].should == 'foo' -> do 'hello'.foo - end.should raise_error(NoMethodError) + end.should.raise(NoMethodError) end it "uses refinements from the given module for method calls in the target file" do @@ -27,7 +27,7 @@ describe "main.using" do load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__) -> do 'hello'.foo - end.should raise_error(NoMethodError) + end.should.raise(NoMethodError) MainSpecs.call_foo('hello').should == 'foo' end @@ -129,4 +129,22 @@ describe "main.using" do x.call_bar(cls2.new).should == 'bar' end + + it "raises error when called from method in wrapped script" do + -> do + load File.expand_path('../fixtures/using_in_method.rb', __FILE__), true + end.should.raise(RuntimeError) + end + + it "raises error when called on toplevel from module" do + -> do + load File.expand_path('../fixtures/using_in_main.rb', __FILE__), true + end.should.raise(RuntimeError) + end + + it "does not raise error when wrapped with module" do + -> do + load File.expand_path('../fixtures/using.rb', __FILE__), true + end.should_not.raise + end end |
