summaryrefslogtreecommitdiff
path: root/spec/ruby/core
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core')
-rw-r--r--spec/ruby/core/kernel/eval_spec.rb1
-rw-r--r--spec/ruby/core/kernel/fixtures/singleton_methods.rb13
-rw-r--r--spec/ruby/core/kernel/singleton_methods_spec.rb14
-rw-r--r--spec/ruby/core/module/refine_spec.rb24
-rw-r--r--spec/ruby/core/signal/trap_spec.rb19
5 files changed, 70 insertions, 1 deletions
diff --git a/spec/ruby/core/kernel/eval_spec.rb b/spec/ruby/core/kernel/eval_spec.rb
index fbae8ff3c7..46158628a3 100644
--- a/spec/ruby/core/kernel/eval_spec.rb
+++ b/spec/ruby/core/kernel/eval_spec.rb
@@ -214,6 +214,7 @@ describe "Kernel#eval" do
ruby_exe(code).chomp.should == "a,b,c,e,LocalJumpError,f"
end
+ # See language/magic_comment_spec.rb for more magic comments specs
describe "with a magic encoding comment" do
it "uses the magic comment encoding for the encoding of literal strings" do
code = "# encoding: UTF-8\n'é'.encoding".b
diff --git a/spec/ruby/core/kernel/fixtures/singleton_methods.rb b/spec/ruby/core/kernel/fixtures/singleton_methods.rb
new file mode 100644
index 0000000000..32ea0adf89
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/singleton_methods.rb
@@ -0,0 +1,13 @@
+module SingletonMethodsSpecs
+ module Prepended
+ def mspec_test_kernel_singleton_methods
+ end
+ public :mspec_test_kernel_singleton_methods
+ end
+
+ ::Module.prepend Prepended
+
+ module SelfExtending
+ extend self
+ end
+end
diff --git a/spec/ruby/core/kernel/singleton_methods_spec.rb b/spec/ruby/core/kernel/singleton_methods_spec.rb
index 74fd4a9608..eb4cede110 100644
--- a/spec/ruby/core/kernel/singleton_methods_spec.rb
+++ b/spec/ruby/core/kernel/singleton_methods_spec.rb
@@ -36,6 +36,19 @@ describe :kernel_singleton_methods_modules, shared: true do
it "does not return any included methods for a class including a module" do
ReflectSpecs::D.singleton_methods(*@object).should include(:ds_pro, :ds_pub)
end
+
+ it "for a module does not return methods in a module prepended to Module itself" do
+ require_relative 'fixtures/singleton_methods'
+ mod = SingletonMethodsSpecs::SelfExtending
+ mod.method(:mspec_test_kernel_singleton_methods).owner.should == SingletonMethodsSpecs::Prepended
+
+ ancestors = mod.singleton_class.ancestors
+ ancestors[0...2].should == [ mod.singleton_class, mod ]
+ ancestors.should include(SingletonMethodsSpecs::Prepended)
+
+ # Do not search prepended modules of `Module`, as that's a non-singleton class
+ mod.singleton_methods.should == []
+ end
end
describe :kernel_singleton_methods_supers, shared: true do
@@ -145,7 +158,6 @@ describe "Kernel#singleton_methods" do
it_behaves_like :kernel_singleton_methods_supers, nil, true
it_behaves_like :kernel_singleton_methods_modules, nil, true
it_behaves_like :kernel_singleton_methods_private_supers, nil, true
-
end
describe "when passed false" do
diff --git a/spec/ruby/core/module/refine_spec.rb b/spec/ruby/core/module/refine_spec.rb
index e36b17cf15..287aa601a9 100644
--- a/spec/ruby/core/module/refine_spec.rb
+++ b/spec/ruby/core/module/refine_spec.rb
@@ -594,6 +594,30 @@ describe "Module#refine" do
end
end
+ it 'and alias aliases a method within a refinement module, but not outside it' do
+ Module.new do
+ using Module.new {
+ refine Array do
+ alias :orig_count :count
+ end
+ }
+ [1,2].orig_count.should == 2
+ end
+ lambda { [1,2].orig_count }.should raise_error(NoMethodError)
+ end
+
+ it 'and alias_method aliases a method within a refinement module, but not outside it' do
+ Module.new do
+ using Module.new {
+ refine Array do
+ alias_method :orig_count, :count
+ end
+ }
+ [1,2].orig_count.should == 2
+ end
+ lambda { [1,2].orig_count }.should raise_error(NoMethodError)
+ end
+
# Refinements are inherited by module inclusion.
# That is, using activates all refinements in the ancestors of the specified module.
# Refinements in a descendant have priority over refinements in an ancestor.
diff --git a/spec/ruby/core/signal/trap_spec.rb b/spec/ruby/core/signal/trap_spec.rb
index 867094d6dd..c11c900add 100644
--- a/spec/ruby/core/signal/trap_spec.rb
+++ b/spec/ruby/core/signal/trap_spec.rb
@@ -158,9 +158,28 @@ platform_is_not :windows do
$?.exitstatus.should == 0
end
+ it "returns 'DEFAULT' for the initial SIGINT handler" do
+ ruby_exe('print trap(:INT) { abort }').should == 'DEFAULT'
+ end
+
it "returns SYSTEM_DEFAULT if passed DEFAULT and no handler was ever set" do
Signal.trap("PROF", "DEFAULT").should == "SYSTEM_DEFAULT"
end
+
+ it "accepts 'SYSTEM_DEFAULT' and uses the OS handler for SIGPIPE" do
+ code = <<-RUBY
+ p Signal.trap('PIPE', 'SYSTEM_DEFAULT')
+ r, w = IO.pipe
+ r.close
+ loop { w.write("a"*1024) }
+ RUBY
+ out = ruby_exe(code)
+ status = $?
+ out.should == "nil\n"
+ status.signaled?.should == true
+ status.termsig.should be_kind_of(Integer)
+ Signal.signame(status.termsig).should == "PIPE"
+ end
end
end