summaryrefslogtreecommitdiff
path: root/spec/rubyspec/core
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-29 14:35:37 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-29 14:35:37 +0000
commit5b593e388931490c1e2246d0347c892440167b2c (patch)
tree70d928d35c01b51bb9a6cdc44af4bd7cc05a669b /spec/rubyspec/core
parent6a4aa4838cc53a520044b86deb4ecddb57bca876 (diff)
Update to ruby/spec@abf1700
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/core')
-rw-r--r--spec/rubyspec/core/argf/binmode_spec.rb23
-rw-r--r--spec/rubyspec/core/argf/fixtures/encoding.rb5
-rw-r--r--spec/rubyspec/core/argf/set_encoding_spec.rb31
-rw-r--r--spec/rubyspec/core/array/element_set_spec.rb23
-rw-r--r--spec/rubyspec/core/array/shared/inspect.rb40
-rw-r--r--spec/rubyspec/core/basicobject/equal_spec.rb4
-rw-r--r--spec/rubyspec/core/bignum/bignum_spec.rb12
-rw-r--r--spec/rubyspec/core/enumerable/sum_spec.rb30
-rw-r--r--spec/rubyspec/core/enumerable/uniq_spec.rb29
-rw-r--r--spec/rubyspec/core/enumerator/inspect_spec.rb14
-rw-r--r--spec/rubyspec/core/enumerator/lazy/grep_spec.rb2
-rw-r--r--spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb2
-rw-r--r--spec/rubyspec/core/enumerator/lazy/uniq_spec.rb39
-rw-r--r--spec/rubyspec/core/false/falseclass_spec.rb15
-rw-r--r--spec/rubyspec/core/fixnum/bit_and_spec.rb6
-rw-r--r--spec/rubyspec/core/fixnum/fixnum_spec.rb12
-rw-r--r--spec/rubyspec/core/float/float_spec.rb12
-rw-r--r--spec/rubyspec/core/float/shared/modulo.rb6
-rw-r--r--spec/rubyspec/core/hash/shared/to_s.rb42
-rw-r--r--spec/rubyspec/core/io/output_spec.rb6
-rw-r--r--spec/rubyspec/core/io/popen_spec.rb29
-rw-r--r--spec/rubyspec/core/kernel/autoload_spec.rb3
-rw-r--r--spec/rubyspec/core/kernel/caller_spec.rb6
-rw-r--r--spec/rubyspec/core/kernel/chomp_spec.rb2
-rw-r--r--spec/rubyspec/core/kernel/chop_spec.rb2
-rw-r--r--spec/rubyspec/core/kernel/clone_spec.rb10
-rw-r--r--spec/rubyspec/core/kernel/fixtures/classes.rb34
-rw-r--r--spec/rubyspec/core/kernel/public_method_spec.rb4
-rw-r--r--spec/rubyspec/core/kernel/singleton_method_spec.rb41
-rw-r--r--spec/rubyspec/core/marshal/dump_spec.rb9
-rw-r--r--spec/rubyspec/core/matchdata/named_captures_spec.rb13
-rw-r--r--spec/rubyspec/core/matchdata/values_at_spec.rb10
-rw-r--r--spec/rubyspec/core/module/autoload_spec.rb2
-rw-r--r--spec/rubyspec/core/module/module_function_spec.rb88
-rw-r--r--spec/rubyspec/core/module/shared/set_visibility.rb86
-rw-r--r--spec/rubyspec/core/nil/nilclass_spec.rb15
-rw-r--r--spec/rubyspec/core/numeric/shared/step.rb12
-rw-r--r--spec/rubyspec/core/process/fixtures/common.rb20
-rw-r--r--spec/rubyspec/core/process/fixtures/env.rb1
-rw-r--r--spec/rubyspec/core/process/fixtures/print.rb1
-rw-r--r--spec/rubyspec/core/process/kill_spec.rb48
-rw-r--r--spec/rubyspec/core/process/spawn_spec.rb84
-rw-r--r--spec/rubyspec/core/process/wait_spec.rb3
-rw-r--r--spec/rubyspec/core/regexp/encoding_spec.rb2
-rw-r--r--spec/rubyspec/core/string/encoding_spec.rb2
-rw-r--r--spec/rubyspec/core/symbol/symbol_spec.rb12
-rw-r--r--spec/rubyspec/core/time/dup_spec.rb7
-rw-r--r--spec/rubyspec/core/time/localtime_spec.rb14
-rw-r--r--spec/rubyspec/core/time/shared/gmtime.rb25
-rw-r--r--spec/rubyspec/core/true/trueclass_spec.rb15
50 files changed, 695 insertions, 258 deletions
diff --git a/spec/rubyspec/core/argf/binmode_spec.rb b/spec/rubyspec/core/argf/binmode_spec.rb
index 3daf4f4345..62202360e3 100644
--- a/spec/rubyspec/core/argf/binmode_spec.rb
+++ b/spec/rubyspec/core/argf/binmode_spec.rb
@@ -8,7 +8,9 @@ describe "ARGF.binmode" do
end
it "returns self" do
- ruby_exe("puts(ARGF.binmode == ARGF)", args: @bin_file).chomp.should == 'true'
+ argf [@bin_file] do
+ @argf.binmode.should equal @argf
+ end
end
platform_is :windows do
@@ -29,18 +31,13 @@ describe "ARGF.binmode" do
end
end
- platform_is_not :windows do
- # This does nothing on Unix but it should not raise any errors.
- it "does not raise an error" do
- ruby_exe("ARGF.binmode", args: @bin_file)
- $?.should be_kind_of(Process::Status)
- $?.to_i.should == 0
- end
- end
-
it "sets the file's encoding to ASCII-8BIT" do
- script = fixture __FILE__, "encoding.rb"
- output = "true\n#{Encoding::ASCII_8BIT}\n#{Encoding::ASCII_8BIT}\n"
- ruby_exe(script, args: [@bin_file, @file1]).should == output
+ argf [@bin_file, @file1] do
+ @argf.binmode
+ @argf.binmode?.should == true
+ @argf.gets.encoding.should == Encoding::ASCII_8BIT
+ @argf.skip
+ @argf.read.encoding.should == Encoding::ASCII_8BIT
+ end
end
end
diff --git a/spec/rubyspec/core/argf/fixtures/encoding.rb b/spec/rubyspec/core/argf/fixtures/encoding.rb
deleted file mode 100644
index 6e87e64346..0000000000
--- a/spec/rubyspec/core/argf/fixtures/encoding.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-ARGF.binmode
-puts ARGF.binmode?
-puts ARGF.gets.encoding
-ARGF.skip
-puts ARGF.read.encoding
diff --git a/spec/rubyspec/core/argf/set_encoding_spec.rb b/spec/rubyspec/core/argf/set_encoding_spec.rb
index 16d49a8c44..f6ec74ded1 100644
--- a/spec/rubyspec/core/argf/set_encoding_spec.rb
+++ b/spec/rubyspec/core/argf/set_encoding_spec.rb
@@ -1,28 +1,41 @@
require File.expand_path('../../../spec_helper', __FILE__)
-# These specs need to be run to a separate process as there is no way to reset ARGF encoding
describe "ARGF.set_encoding" do
before :each do
@file = fixture __FILE__, "file1.txt"
end
it "sets the external encoding when passed an encoding instance" do
- enc = ruby_exe('ARGF.set_encoding(Encoding::UTF_8); print ARGF.gets.encoding', args: [@file])
- enc.should == "UTF-8"
+ argf [@file] do
+ @argf.set_encoding(Encoding::US_ASCII)
+ @argf.external_encoding.should == Encoding::US_ASCII
+ @argf.gets.encoding.should == Encoding::US_ASCII
+ end
end
it "sets the external encoding when passed an encoding name" do
- enc = ruby_exe('ARGF.set_encoding("utf-8"); print ARGF.gets.encoding', args: [@file])
- enc.should == "UTF-8"
+ argf [@file] do
+ @argf.set_encoding("us-ascii")
+ @argf.external_encoding.should == Encoding::US_ASCII
+ @argf.gets.encoding.should == Encoding::US_ASCII
+ end
end
it "sets the external, internal encoding when passed two encoding instances" do
- enc = ruby_exe('ARGF.set_encoding(Encoding::UTF_8, Encoding::EUC_JP); print ARGF.gets.encoding', args: [@file])
- enc.should == "EUC-JP"
+ argf [@file] do
+ @argf.set_encoding(Encoding::US_ASCII, Encoding::EUC_JP)
+ @argf.external_encoding.should == Encoding::US_ASCII
+ @argf.internal_encoding.should == Encoding::EUC_JP
+ @argf.gets.encoding.should == Encoding::EUC_JP
+ end
end
it "sets the external, internal encoding when passed 'ext:int' String" do
- enc = ruby_exe('ARGF.set_encoding("utf-8:euc-jp"); print ARGF.gets.encoding', args: [@file])
- enc.should == "EUC-JP"
+ argf [@file] do
+ @argf.set_encoding("us-ascii:euc-jp")
+ @argf.external_encoding.should == Encoding::US_ASCII
+ @argf.internal_encoding.should == Encoding::EUC_JP
+ @argf.gets.encoding.should == Encoding::EUC_JP
+ end
end
end
diff --git a/spec/rubyspec/core/array/element_set_spec.rb b/spec/rubyspec/core/array/element_set_spec.rb
index 280b507fc4..6544ad9b6f 100644
--- a/spec/rubyspec/core/array/element_set_spec.rb
+++ b/spec/rubyspec/core/array/element_set_spec.rb
@@ -258,12 +258,12 @@ describe "Array#[]= with [index]" do
end
it "sets the value of the element at index" do
- a = [1, 2, 3, 4]
- a[2] = 5
- a[-1] = 6
- a[5] = 3
- a.should == [1, 2, 5, 6, nil, 3]
- end
+ a = [1, 2, 3, 4]
+ a[2] = 5
+ a[-1] = 6
+ a[5] = 3
+ a.should == [1, 2, 5, 6, nil, 3]
+ end
it "sets the value of the element if it is right beyond the array boundary" do
a = [1, 2, 3, 4]
@@ -370,11 +370,11 @@ describe "Array#[]= with [m..n]" do
end
it "replaces the section defined by range" do
- a = [6, 5, 4, 3, 2, 1]
- a[1...2] = 9
- a[3..6] = [6, 6, 6]
- a.should == [6, 9, 4, 6, 6, 6]
- end
+ a = [6, 5, 4, 3, 2, 1]
+ a[1...2] = 9
+ a[3..6] = [6, 6, 6]
+ a.should == [6, 9, 4, 6, 6, 6]
+ end
it "replaces the section if m and n < 0" do
a = [1, 2, 3, 4, 5]
@@ -415,4 +415,3 @@ describe "Array#[] after a shift" do
a.should == [3,4]
end
end
-
diff --git a/spec/rubyspec/core/array/shared/inspect.rb b/spec/rubyspec/core/array/shared/inspect.rb
index 823dd40e7e..6a60781b45 100644
--- a/spec/rubyspec/core/array/shared/inspect.rb
+++ b/spec/rubyspec/core/array/shared/inspect.rb
@@ -18,6 +18,46 @@ describe :array_inspect, shared: true do
items.send(@method).should == "[0, 1, 2]"
end
+ it "does not call #to_s on a String returned from #inspect" do
+ str = "abc"
+ str.should_not_receive(:to_s)
+
+ [str].send(@method).should == '["abc"]'
+ end
+
+ it "calls #to_s on the object returned from #inspect if the Object isn't a String" do
+ obj = mock("Array#inspect/to_s calls #to_s")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_return("abc")
+
+ [obj].send(@method).should == "[abc]"
+ end
+
+ it "does not call #to_str on the object returned from #inspect when it is not a String" do
+ obj = mock("Array#inspect/to_s does not call #to_str")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_not_receive(:to_str)
+
+ [obj].send(@method).should =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/
+ end
+
+ it "does not call #to_str on the object returned from #to_s when it is not a String" do
+ obj = mock("Array#inspect/to_s does not call #to_str on #to_s result")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_return(obj)
+ obj.should_not_receive(:to_str)
+
+ [obj].send(@method).should =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/
+ end
+
+ it "does not swallow exceptions raised by #to_s" do
+ obj = mock("Array#inspect/to_s does not swallow #to_s exceptions")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_raise(Exception)
+
+ lambda { [obj].send(@method) }.should raise_error(Exception)
+ end
+
it "represents a recursive element with '[...]'" do
ArraySpecs.recursive_array.send(@method).should == "[1, \"two\", 3.0, [...], [...], [...], [...], [...]]"
ArraySpecs.head_recursive_array.send(@method).should == "[[...], [...], [...], [...], [...], 1, \"two\", 3.0]"
diff --git a/spec/rubyspec/core/basicobject/equal_spec.rb b/spec/rubyspec/core/basicobject/equal_spec.rb
index 8142efa6bd..8120df836f 100644
--- a/spec/rubyspec/core/basicobject/equal_spec.rb
+++ b/spec/rubyspec/core/basicobject/equal_spec.rb
@@ -10,9 +10,9 @@ describe "BasicObject#equal?" do
it "is unaffected by overriding __id__" do
o1 = mock("object")
- o1.stub!(:__id__).and_return(10)
o2 = mock("object")
- o2.stub!(:__id__).and_return(10)
+ def o1.__id__; 10; end
+ def o2.__id__; 10; end
o1.equal?(o2).should be_false
end
diff --git a/spec/rubyspec/core/bignum/bignum_spec.rb b/spec/rubyspec/core/bignum/bignum_spec.rb
index b723718f69..cf99bb4937 100644
--- a/spec/rubyspec/core/bignum/bignum_spec.rb
+++ b/spec/rubyspec/core/bignum/bignum_spec.rb
@@ -4,4 +4,16 @@ describe "Bignum" do
it "includes Comparable" do
Bignum.include?(Comparable).should == true
end
+
+ it ".allocate raises a TypeError" do
+ lambda do
+ Bignum.allocate
+ end.should raise_error(TypeError)
+ end
+
+ it ".new is undefined" do
+ lambda do
+ Bignum.new
+ end.should raise_error(NoMethodError)
+ end
end
diff --git a/spec/rubyspec/core/enumerable/sum_spec.rb b/spec/rubyspec/core/enumerable/sum_spec.rb
new file mode 100644
index 0000000000..4881039a8d
--- /dev/null
+++ b/spec/rubyspec/core/enumerable/sum_spec.rb
@@ -0,0 +1,30 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+
+ruby_version_is '2.4' do
+ describe 'Enumerable#sum' do
+ before :each do
+ @enum = Object.new.to_enum
+ class << @enum
+ def each
+ yield 0
+ yield(-1)
+ yield 2
+ yield 2/3r
+ end
+ end
+ end
+
+ it 'returns amount of the elements with taking an argument as the initial value' do
+ @enum.sum(10).should == 35/3r
+ end
+
+ it 'gives 0 as a default argument' do
+ @enum.sum.should == 5/3r
+ end
+
+ it 'takes a block to transform the elements' do
+ @enum.sum { |element| element * 2 }.should == 10/3r
+ end
+ end
+end
diff --git a/spec/rubyspec/core/enumerable/uniq_spec.rb b/spec/rubyspec/core/enumerable/uniq_spec.rb
new file mode 100644
index 0000000000..0ede0170ce
--- /dev/null
+++ b/spec/rubyspec/core/enumerable/uniq_spec.rb
@@ -0,0 +1,29 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+
+ruby_version_is '2.4' do
+ describe 'Enumerable#uniq' do
+ it 'returns an array that contains only unique elements' do
+ [0, 1, 2, 3].to_enum.uniq { |n| n.even? }.should == [0, 1]
+ end
+
+ context 'when yielded with multiple arguments' do
+ before :each do
+ @enum = Object.new.to_enum
+ class << @enum
+ def each
+ yield 0, 'foo'
+ yield 1, 'FOO'
+ yield 2, 'bar'
+ end
+ end
+ end
+
+ ruby_bug '#13669', ''...'2.5' do
+ it 'returns all yield arguments as an array' do
+ @enum.uniq { |_, label| label.downcase }.should == [[0, 'foo'], [2, 'bar']]
+ end
+ end
+ end
+ end
+end
diff --git a/spec/rubyspec/core/enumerator/inspect_spec.rb b/spec/rubyspec/core/enumerator/inspect_spec.rb
index e89d3b7f3a..b708256247 100644
--- a/spec/rubyspec/core/enumerator/inspect_spec.rb
+++ b/spec/rubyspec/core/enumerator/inspect_spec.rb
@@ -1,5 +1,17 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Enumerator#inspect" do
- it "needs to be reviewed for spec completeness"
+ describe "shows a representation of the Enumerator" do
+ it "including receiver and method" do
+ (1..3).each.inspect.should == "#<Enumerator: 1..3:each>"
+ end
+
+ it "including receiver and method and arguments" do
+ (1..3).each_slice(2).inspect.should == "#<Enumerator: 1..3:each_slice(2)>"
+ end
+
+ it "including the nested Enumerator" do
+ (1..3).each.each_slice(2).inspect.should == "#<Enumerator: #<Enumerator: 1..3:each>:each_slice(2)>"
+ end
+ end
end
diff --git a/spec/rubyspec/core/enumerator/lazy/grep_spec.rb b/spec/rubyspec/core/enumerator/lazy/grep_spec.rb
index c5fbfcf1dd..372be80d61 100644
--- a/spec/rubyspec/core/enumerator/lazy/grep_spec.rb
+++ b/spec/rubyspec/core/enumerator/lazy/grep_spec.rb
@@ -64,7 +64,7 @@ describe "Enumerator::Lazy#grep" do
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times when not given a block" do
+ it "stops after specified times when not given a block" do
(0..Float::INFINITY).lazy.grep(Integer).grep(Object).first(3).should == [0, 1, 2]
@eventsmixed.grep(BasicObject).grep(Object).first(1)
diff --git a/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb b/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb
index 06dd42213c..123cbae58c 100644
--- a/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb
+++ b/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb
@@ -63,7 +63,7 @@ ruby_version_is "2.3" do
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times when not given a block" do
+ it "stops after specified times when not given a block" do
(0..Float::INFINITY).lazy.grep_v(3..5).grep_v(6..10).first(3).should == [0, 1, 2]
@eventsmixed.grep_v(Symbol).grep_v(String).first(1)
diff --git a/spec/rubyspec/core/enumerator/lazy/uniq_spec.rb b/spec/rubyspec/core/enumerator/lazy/uniq_spec.rb
new file mode 100644
index 0000000000..6220c7ba34
--- /dev/null
+++ b/spec/rubyspec/core/enumerator/lazy/uniq_spec.rb
@@ -0,0 +1,39 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+
+ruby_version_is '2.4' do
+ describe 'Enumerator::Lazy#uniq' do
+ context 'when yielded with an argument' do
+ before :each do
+ @lazy = [0, 1, 2, 3].to_enum.lazy.uniq(&:even?)
+ end
+
+ it 'returns a lazy enumerator' do
+ @lazy.should be_an_instance_of(Enumerator::Lazy)
+ @lazy.force.should == [0, 1]
+ end
+
+ it 'sets the size to nil' do
+ @lazy.size.should == nil
+ end
+ end
+
+ context 'when yielded with multiple arguments' do
+ before :each do
+ enum = Object.new.to_enum
+ class << enum
+ def each
+ yield 0, 'foo'
+ yield 1, 'FOO'
+ yield 2, 'bar'
+ end
+ end
+ @lazy = enum.lazy
+ end
+
+ it 'returns all yield arguments as an array' do
+ @lazy.uniq { |_, label| label.downcase }.force.should == [[0, 'foo'], [2, 'bar']]
+ end
+ end
+ end
+end
diff --git a/spec/rubyspec/core/false/falseclass_spec.rb b/spec/rubyspec/core/false/falseclass_spec.rb
new file mode 100644
index 0000000000..e91682c94c
--- /dev/null
+++ b/spec/rubyspec/core/false/falseclass_spec.rb
@@ -0,0 +1,15 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "FalseClass" do
+ it ".allocate raises a TypeError" do
+ lambda do
+ FalseClass.allocate
+ end.should raise_error(TypeError)
+ end
+
+ it ".new is undefined" do
+ lambda do
+ FalseClass.new
+ end.should raise_error(NoMethodError)
+ end
+end
diff --git a/spec/rubyspec/core/fixnum/bit_and_spec.rb b/spec/rubyspec/core/fixnum/bit_and_spec.rb
index ff0e597a52..9586075039 100644
--- a/spec/rubyspec/core/fixnum/bit_and_spec.rb
+++ b/spec/rubyspec/core/fixnum/bit_and_spec.rb
@@ -27,6 +27,12 @@ describe "Fixnum#&" do
(-1 & 2**64).should == 18446744073709551616
end
+ it "coerces the rhs and calls #coerce" do
+ obj = mock("fixnum bit and")
+ obj.should_receive(:coerce).with(6).and_return([3, 6])
+ (6 & obj).should == 2
+ end
+
it "raises a TypeError when passed a Float" do
lambda { (3 & 3.4) }.should raise_error(TypeError)
end
diff --git a/spec/rubyspec/core/fixnum/fixnum_spec.rb b/spec/rubyspec/core/fixnum/fixnum_spec.rb
index d0af975c59..8a050fd25e 100644
--- a/spec/rubyspec/core/fixnum/fixnum_spec.rb
+++ b/spec/rubyspec/core/fixnum/fixnum_spec.rb
@@ -4,4 +4,16 @@ describe "Fixnum" do
it "includes Comparable" do
Fixnum.include?(Comparable).should == true
end
+
+ it ".allocate raises a TypeError" do
+ lambda do
+ Fixnum.allocate
+ end.should raise_error(TypeError)
+ end
+
+ it ".new is undefined" do
+ lambda do
+ Fixnum.new
+ end.should raise_error(NoMethodError)
+ end
end
diff --git a/spec/rubyspec/core/float/float_spec.rb b/spec/rubyspec/core/float/float_spec.rb
index e26e082a55..f2931d184c 100644
--- a/spec/rubyspec/core/float/float_spec.rb
+++ b/spec/rubyspec/core/float/float_spec.rb
@@ -4,4 +4,16 @@ describe "Float" do
it "includes Comparable" do
Float.include?(Comparable).should == true
end
+
+ it ".allocate raises a TypeError" do
+ lambda do
+ Float.allocate
+ end.should raise_error(TypeError)
+ end
+
+ it ".new is undefined" do
+ lambda do
+ Float.new
+ end.should raise_error(NoMethodError)
+ end
end
diff --git a/spec/rubyspec/core/float/shared/modulo.rb b/spec/rubyspec/core/float/shared/modulo.rb
index 9ac967389c..6c423a3a28 100644
--- a/spec/rubyspec/core/float/shared/modulo.rb
+++ b/spec/rubyspec/core/float/shared/modulo.rb
@@ -35,6 +35,12 @@ describe :float_modulo, shared: true do
(1/r).should < 0
end
+ it "tries to coerce the modulus" do
+ obj = mock("modulus")
+ obj.should_receive(:coerce).with(1.25).and_return([1.25, 0.5])
+ (1.25 % obj).should == 0.25
+ end
+
it "raises a ZeroDivisionError if other is zero" do
lambda { 1.0.send(@method, 0) }.should raise_error(ZeroDivisionError)
lambda { 1.0.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
diff --git a/spec/rubyspec/core/hash/shared/to_s.rb b/spec/rubyspec/core/hash/shared/to_s.rb
index 7ef2c207d4..0afe605826 100644
--- a/spec/rubyspec/core/hash/shared/to_s.rb
+++ b/spec/rubyspec/core/hash/shared/to_s.rb
@@ -15,7 +15,7 @@ describe :hash_to_s, shared: true do
h.send(@method).should == str
end
- it "calls inspect on keys and values" do
+ it "calls #inspect on keys and values" do
key = mock('key')
val = mock('val')
key.should_receive(:inspect).and_return('key')
@@ -24,6 +24,46 @@ describe :hash_to_s, shared: true do
{ key => val }.send(@method).should == '{key=>val}'
end
+ it "does not call #to_s on a String returned from #inspect" do
+ str = "abc"
+ str.should_not_receive(:to_s)
+
+ { a: str }.send(@method).should == '{:a=>"abc"}'
+ end
+
+ it "calls #to_s on the object returned from #inspect if the Object isn't a String" do
+ obj = mock("Hash#inspect/to_s calls #to_s")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_return("abc")
+
+ { a: obj }.send(@method).should == "{:a=>abc}"
+ end
+
+ it "does not call #to_str on the object returned from #inspect when it is not a String" do
+ obj = mock("Hash#inspect/to_s does not call #to_str")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_not_receive(:to_str)
+
+ { a: obj }.send(@method).should =~ /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
+ end
+
+ it "does not call #to_str on the object returned from #to_s when it is not a String" do
+ obj = mock("Hash#inspect/to_s does not call #to_str on #to_s result")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_return(obj)
+ obj.should_not_receive(:to_str)
+
+ { a: obj }.send(@method).should =~ /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
+ end
+
+ it "does not swallow exceptions raised by #to_s" do
+ obj = mock("Hash#inspect/to_s does not swallow #to_s exceptions")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_raise(Exception)
+
+ lambda { { a: obj }.send(@method) }.should raise_error(Exception)
+ end
+
it "handles hashes with recursive values" do
x = {}
x[0] = x
diff --git a/spec/rubyspec/core/io/output_spec.rb b/spec/rubyspec/core/io/output_spec.rb
index ac3e781cee..2d52315430 100644
--- a/spec/rubyspec/core/io/output_spec.rb
+++ b/spec/rubyspec/core/io/output_spec.rb
@@ -9,10 +9,10 @@ describe "IO#<<" do
end
it "calls #to_s on the object to print it" do
- lambda {
- $stderr << 1337
+ lambda {
+ $stderr << 1337
}.should output_to_fd("1337", $stderr)
- end
+ end
it "raises an error if the stream is closed" do
io = IOSpecs.closed_io
diff --git a/spec/rubyspec/core/io/popen_spec.rb b/spec/rubyspec/core/io/popen_spec.rb
index f24e61032f..45bb0e2cab 100644
--- a/spec/rubyspec/core/io/popen_spec.rb
+++ b/spec/rubyspec/core/io/popen_spec.rb
@@ -74,10 +74,7 @@ describe "IO.popen" do
end
it "does not throw an exception if child exited and has been waited for" do
- # Avoid the /bin/sh subshell using :options and :args to sleep.
- # We don't want to kill only the subshell and leave "ruby -e sleep"
- # running indefinitely
- @io = IO.popen(ruby_cmd(nil, :options => '-e', :args => 'sleep'))
+ @io = IO.popen([*ruby_exe, '-e', 'sleep'])
pid = @io.pid
Process.kill "KILL", pid
@io.close
@@ -201,28 +198,28 @@ describe "IO.popen" do
end
it "accepts an Array of command and arguments" do
- exe, *args = ruby_cmd(nil).split
+ exe, *args = ruby_exe
IO.popen({"FOO" => "bar"}, [[exe, "specfu"], *args, "-e", "puts ENV['FOO']"]) do |io|
io.read.should == "bar\n"
end
end
it "accepts an Array of command and arguments, and an IO mode" do
- exe, *args = ruby_cmd(nil).split
+ exe, *args = ruby_exe
IO.popen({"FOO" => "bar"}, [[exe, "specfu"], *args, "-e", "puts ENV['FOO']"], "r") do |io|
io.read.should == "bar\n"
end
end
it "accepts an Array command with a separate trailing Hash of Process.exec options" do
- IO.popen({"FOO" => "bar"}, [*ruby_cmd(nil).split, "-e", "STDERR.puts ENV['FOO']"],
+ IO.popen({"FOO" => "bar"}, [*ruby_exe, "-e", "STDERR.puts ENV['FOO']"],
err: [:child, :out]) do |io|
io.read.should == "bar\n"
end
end
it "accepts an Array command with a separate trailing Hash of Process.exec options, and an IO mode" do
- IO.popen({"FOO" => "bar"}, [*ruby_cmd(nil).split, "-e", "STDERR.puts ENV['FOO']"],
+ IO.popen({"FOO" => "bar"}, [*ruby_exe, "-e", "STDERR.puts ENV['FOO']"],
"r", err: [:child, :out]) do |io|
io.read.should == "bar\n"
end
@@ -231,45 +228,45 @@ describe "IO.popen" do
context "with a leading Array argument" do
it "uses the Array as command plus args for the child process" do
- IO.popen([*ruby_cmd(nil).split, "-e", "puts 'hello'"]) do |io|
+ IO.popen([*ruby_exe, "-e", "puts 'hello'"]) do |io|
io.read.should == "hello\n"
end
end
it "accepts a leading ENV Hash" do
- IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "puts ENV['FOO']"]) do |io|
+ IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "puts ENV['FOO']"]) do |io|
io.read.should == "bar\n"
end
end
it "accepts a trailing Hash of Process.exec options" do
- IO.popen([*ruby_cmd(nil).split, "does_not_exist", {err: [:child, :out]}]) do |io|
+ IO.popen([*ruby_exe, "does_not_exist", {err: [:child, :out]}]) do |io|
io.read.should =~ /LoadError/
end
end
it "accepts an IO mode argument following the Array" do
- IO.popen([*ruby_cmd(nil).split, "does_not_exist", {err: [:child, :out]}], "r") do |io|
+ IO.popen([*ruby_exe, "does_not_exist", {err: [:child, :out]}], "r") do |io|
io.read.should =~ /LoadError/
end
end
it "accepts [env, command, arg1, arg2, ..., exec options]" do
- IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "STDERR.puts ENV[:FOO.to_s]",
+ IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "STDERR.puts ENV[:FOO.to_s]",
err: [:child, :out]]) do |io|
io.read.should == "bar\n"
end
end
it "accepts '[env, command, arg1, arg2, ..., exec options], mode'" do
- IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "STDERR.puts ENV[:FOO.to_s]",
+ IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "STDERR.puts ENV[:FOO.to_s]",
err: [:child, :out]], "r") do |io|
io.read.should == "bar\n"
end
end
it "accepts '[env, command, arg1, arg2, ..., exec options], mode, IO options'" do
- IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "STDERR.puts ENV[:FOO.to_s]",
+ IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "STDERR.puts ENV[:FOO.to_s]",
err: [:child, :out]], "r",
internal_encoding: Encoding::EUC_JP) do |io|
io.read.should == "bar\n"
@@ -278,7 +275,7 @@ describe "IO.popen" do
end
it "accepts '[env, command, arg1, arg2, ...], mode, IO + exec options'" do
- IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "STDERR.puts ENV[:FOO.to_s]"], "r",
+ IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "STDERR.puts ENV[:FOO.to_s]"], "r",
err: [:child, :out], internal_encoding: Encoding::EUC_JP) do |io|
io.read.should == "bar\n"
io.internal_encoding.should == Encoding::EUC_JP
diff --git a/spec/rubyspec/core/kernel/autoload_spec.rb b/spec/rubyspec/core/kernel/autoload_spec.rb
index 082903e92d..e2741de74c 100644
--- a/spec/rubyspec/core/kernel/autoload_spec.rb
+++ b/spec/rubyspec/core/kernel/autoload_spec.rb
@@ -49,8 +49,7 @@ describe "Kernel#autoload" do
end
it "can autoload in instance_eval" do
- instance_eval do
- # this instance_eval is not needed because specs are run in instance_eval
+ Object.new.instance_eval do
autoload :KSAutoloadD, fixture(__FILE__, "autoload_d.rb")
KSAutoloadD.loaded.should == :ksautoload_d
end
diff --git a/spec/rubyspec/core/kernel/caller_spec.rb b/spec/rubyspec/core/kernel/caller_spec.rb
index 94fbe3ab7e..d9be29a8db 100644
--- a/spec/rubyspec/core/kernel/caller_spec.rb
+++ b/spec/rubyspec/core/kernel/caller_spec.rb
@@ -22,6 +22,12 @@ describe 'Kernel#caller' do
locations.length.should == 1
end
+ it 'returns an Array of caller locations using a range' do
+ locations = KernelSpecs::CallerTest.locations(1..1)
+
+ locations.length.should == 1
+ end
+
it 'returns the locations as String instances' do
locations = KernelSpecs::CallerTest.locations
line = __LINE__ - 1
diff --git a/spec/rubyspec/core/kernel/chomp_spec.rb b/spec/rubyspec/core/kernel/chomp_spec.rb
index 4b34784169..524a4c8b1d 100644
--- a/spec/rubyspec/core/kernel/chomp_spec.rb
+++ b/spec/rubyspec/core/kernel/chomp_spec.rb
@@ -53,7 +53,7 @@ with_feature :encoding do
it "removes the final carriage return, newline from a multi-byte $_" do
script = fixture __FILE__, "#{@method}.rb"
- KernelSpecs.encoded_chomp(script).should == "あれ"
+ KernelSpecs.run_with_dash_n(script).should == "あれ"
end
end
diff --git a/spec/rubyspec/core/kernel/chop_spec.rb b/spec/rubyspec/core/kernel/chop_spec.rb
index 53b6e47cd1..5106fefee8 100644
--- a/spec/rubyspec/core/kernel/chop_spec.rb
+++ b/spec/rubyspec/core/kernel/chop_spec.rb
@@ -41,7 +41,7 @@ with_feature :encoding do
it "removes the final multi-byte character from $_" do
script = fixture __FILE__, "#{@method}.rb"
- KernelSpecs.encoded_chop(script).should == "あ"
+ KernelSpecs.run_with_dash_n(script).should == "あ"
end
end
diff --git a/spec/rubyspec/core/kernel/clone_spec.rb b/spec/rubyspec/core/kernel/clone_spec.rb
index 0e8216d434..48b3c24c7f 100644
--- a/spec/rubyspec/core/kernel/clone_spec.rb
+++ b/spec/rubyspec/core/kernel/clone_spec.rb
@@ -37,6 +37,16 @@ describe "Kernel#clone" do
o3.frozen?.should == true
end
+ ruby_version_is '2.4' do
+ it 'takes an option to copy freeze state or not' do
+ @obj.clone(freeze: true).frozen?.should == false
+ @obj.clone(freeze: false).frozen?.should == false
+ @obj.freeze
+ @obj.clone(freeze: true).frozen?.should == true
+ @obj.clone(freeze: false).frozen?.should == false
+ end
+ end
+
it "copies instance variables" do
clone = @obj.clone
clone.one.should == 1
diff --git a/spec/rubyspec/core/kernel/fixtures/classes.rb b/spec/rubyspec/core/kernel/fixtures/classes.rb
index c4a4d00485..afa2bec12f 100644
--- a/spec/rubyspec/core/kernel/fixtures/classes.rb
+++ b/spec/rubyspec/core/kernel/fixtures/classes.rb
@@ -32,26 +32,36 @@ module KernelSpecs
end
def self.has_private_method(name)
- cmd = %[| #{ruby_cmd(nil)} -n -e "print Kernel.private_method_defined?('#{name}')"]
- ruby_exe("puts", args: cmd) == "true"
+ IO.popen([*ruby_exe, "-n", "-e", "print Kernel.private_method_defined?(#{name.inspect})"], "r+") do |io|
+ io.puts
+ io.close_write
+ io.read
+ end == "true"
end
def self.chop(str, method)
- cmd = "| #{ruby_cmd(nil)} -n -e '$_ = #{str.inspect}; #{method}; print $_'"
- ruby_exe "puts", args: cmd
- end
-
- def self.encoded_chop(file)
- ruby_exe "puts", args: "| #{ruby_cmd(nil)} -n #{file}"
+ IO.popen([*ruby_exe, "-n", "-e", "$_ = #{str.inspect}; #{method}; print $_"], "r+") do |io|
+ io.puts
+ io.close_write
+ io.read
+ end
end
def self.chomp(str, method, sep="\n")
- cmd = "| #{ruby_cmd(nil)} -n -e '$_ = #{str.inspect}; $/ = #{sep.inspect}; #{method}; print $_'"
- ruby_exe "puts", args: cmd
+ code = "$_ = #{str.inspect}; $/ = #{sep.inspect}; #{method}; print $_"
+ IO.popen([*ruby_exe, "-n", "-e", code], "r+") do |io|
+ io.puts
+ io.close_write
+ io.read
+ end
end
- def self.encoded_chomp(file)
- ruby_exe "puts", args: "| #{ruby_cmd(nil)} -n #{file}"
+ def self.run_with_dash_n(file)
+ IO.popen([*ruby_exe, "-n", file], "r+") do |io|
+ io.puts
+ io.close_write
+ io.read
+ end
end
# kind_of?, is_a?, instance_of?
diff --git a/spec/rubyspec/core/kernel/public_method_spec.rb b/spec/rubyspec/core/kernel/public_method_spec.rb
index c4a29d9192..f1cc168420 100644
--- a/spec/rubyspec/core/kernel/public_method_spec.rb
+++ b/spec/rubyspec/core/kernel/public_method_spec.rb
@@ -18,9 +18,9 @@ describe "Kernel#public_method" do
it "raises a NameError when called on a protected method" do
@obj.send(:protected_method).should == :protected_method
- lambda do
+ lambda {
@obj.public_method(:protected_method)
- end.should raise_error(NameError)
+ }.should raise_error(NameError)
end
it "raises a NameError if we only repond_to_missing? method, true" do
diff --git a/spec/rubyspec/core/kernel/singleton_method_spec.rb b/spec/rubyspec/core/kernel/singleton_method_spec.rb
new file mode 100644
index 0000000000..77022b40c2
--- /dev/null
+++ b/spec/rubyspec/core/kernel/singleton_method_spec.rb
@@ -0,0 +1,41 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Kernel#singleton_method" do
+ it "find a method defined on the singleton class" do
+ obj = Object.new
+ def obj.foo; end
+ obj.singleton_method(:foo).should be_an_instance_of(Method)
+ end
+
+ it "returns a Method which can be called" do
+ obj = Object.new
+ def obj.foo; 42; end
+ obj.singleton_method(:foo).call.should == 42
+ end
+
+ it "only looks at singleton methods and not at methods in the class" do
+ klass = Class.new do
+ def foo
+ 42
+ end
+ end
+ obj = klass.new
+ obj.foo.should == 42
+ -> {
+ obj.singleton_method(:foo)
+ }.should raise_error(NameError) { |e|
+ # a NameError and not a NoMethodError
+ e.class.should == NameError
+ }
+ end
+
+ it "raises a NameError if there is no such method" do
+ obj = Object.new
+ -> {
+ obj.singleton_method(:not_existing)
+ }.should raise_error(NameError) { |e|
+ # a NameError and not a NoMethodError
+ e.class.should == NameError
+ }
+ end
+end
diff --git a/spec/rubyspec/core/marshal/dump_spec.rb b/spec/rubyspec/core/marshal/dump_spec.rb
index 6b369f9bb0..393b8a93f4 100644
--- a/spec/rubyspec/core/marshal/dump_spec.rb
+++ b/spec/rubyspec/core/marshal/dump_spec.rb
@@ -415,6 +415,15 @@ describe "Marshal.dump" do
load = Marshal.load(dump)
load.should == (1...2)
end
+
+ it "dumps a Range with extra instance variables" do
+ range = (1...3)
+ range.instance_variable_set :@foo, 42
+ dump = Marshal.dump(range)
+ load = Marshal.load(dump)
+ load.should == range
+ load.instance_variable_get(:@foo).should == 42
+ end
end
describe "with a Time" do
diff --git a/spec/rubyspec/core/matchdata/named_captures_spec.rb b/spec/rubyspec/core/matchdata/named_captures_spec.rb
new file mode 100644
index 0000000000..1ab3152262
--- /dev/null
+++ b/spec/rubyspec/core/matchdata/named_captures_spec.rb
@@ -0,0 +1,13 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+ruby_version_is '2.4' do
+ describe 'MatchData#named_captures' do
+ it 'returns a Hash that has captured name and the matched string pairs' do
+ /(?<a>.)(?<b>.)?/.match('0').named_captures.should == { 'a' => '0', 'b' => nil }
+ end
+
+ it 'prefers later captures' do
+ /\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)\z/.match('0123').named_captures.should == { 'a' => '3', 'b' => '2' }
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/rubyspec/core/matchdata/values_at_spec.rb b/spec/rubyspec/core/matchdata/values_at_spec.rb
index 8d786246f9..0b2727e001 100644
--- a/spec/rubyspec/core/matchdata/values_at_spec.rb
+++ b/spec/rubyspec/core/matchdata/values_at_spec.rb
@@ -10,4 +10,14 @@ describe "MatchData#values_at" do
/(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(2..4, 0..1).should == ["X", "113", "8", "HX1138", "H"]
end
end
+
+ ruby_version_is '2.4' do
+ it 'slices captures with the given names' do
+ /(?<a>.)(?<b>.)(?<c>.)/.match('012').values_at(:c, :a).should == ['2', '0']
+ end
+
+ it 'takes names and indices' do
+ /\A(?<a>.)(?<b>.)\z/.match('01').values_at(0, 1, 2, :a, :b).should == ['01', '0', '1', '0', '1']
+ end
+ end
end
diff --git a/spec/rubyspec/core/module/autoload_spec.rb b/spec/rubyspec/core/module/autoload_spec.rb
index b479d049bb..9116ddf0a9 100644
--- a/spec/rubyspec/core/module/autoload_spec.rb
+++ b/spec/rubyspec/core/module/autoload_spec.rb
@@ -414,7 +414,7 @@ describe "Module#autoload" do
mod_names = []
mod_count.times do |i|
mod_name = :"Mod#{i}"
- autoload mod_name, autoload_path
+ Object.autoload mod_name, autoload_path
mod_names << mod_name
end
diff --git a/spec/rubyspec/core/module/module_function_spec.rb b/spec/rubyspec/core/module/module_function_spec.rb
index 8ced48c505..61509c8d03 100644
--- a/spec/rubyspec/core/module/module_function_spec.rb
+++ b/spec/rubyspec/core/module/module_function_spec.rb
@@ -151,10 +151,10 @@ end
describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "makes any subsequently defined methods module functions with the normal semantics" do
m = Module.new {
- module_function
- def test1() end
- def test2() end
- }
+ module_function
+ def test1() end
+ def test2() end
+ }
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@@ -172,12 +172,12 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "stops creating module functions if the body encounters another toggle " \
"like public/protected/private without arguments" do
m = Module.new {
- module_function
- def test1() end
- def test2() end
- public
- def test3() end
- }
+ module_function
+ def test1() end
+ def test2() end
+ public
+ def test3() end
+ }
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@@ -187,16 +187,13 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "does not stop creating module functions if the body encounters " \
"public/protected/private WITH arguments" do
m = Module.new {
- def foo() end
-
- module_function
- def test1() end
- def test2() end
-
- public :foo
-
- def test3() end
- }
+ def foo() end
+ module_function
+ def test1() end
+ def test2() end
+ public :foo
+ def test3() end
+ }
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@@ -205,11 +202,10 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "does not affect module_evaled method definitions also if outside the eval itself" do
m = Module.new {
- module_function
-
- module_eval { def test1() end }
- module_eval " def test2() end "
- }
+ module_function
+ module_eval { def test1() end }
+ module_eval " def test2() end "
+ }
m.respond_to?(:test1).should == false
m.respond_to?(:test2).should == false
@@ -217,11 +213,10 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "has no effect if inside a module_eval if the definitions are outside of it" do
m = Module.new {
- module_eval { module_function }
-
- def test1() end
- def test2() end
- }
+ module_eval { module_function }
+ def test1() end
+ def test2() end
+ }
m.respond_to?(:test1).should == false
m.respond_to?(:test2).should == false
@@ -229,13 +224,12 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "functions normally if both toggle and definitions inside a module_eval" do
m = Module.new {
- module_eval {
- module_function
-
- def test1() end
- def test2() end
- }
- }
+ module_eval {
+ module_function
+ def test1() end
+ def test2() end
+ }
+ }
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@@ -243,10 +237,9 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "affects evaled method definitions also even when outside the eval itself" do
m = Module.new {
- module_function
-
- eval "def test1() end"
- }
+ module_function
+ eval "def test1() end"
+ }
m.respond_to?(:test1).should == true
end
@@ -254,7 +247,6 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "doesn't affect definitions when inside an eval even if the definitions are outside of it" do
m = Module.new {
eval "module_function"
-
def test1() end
}
@@ -263,13 +255,13 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "functions normally if both toggle and definitions inside a eval" do
m = Module.new {
- eval <<-CODE
- module_function
+ eval <<-CODE
+ module_function
- def test1() end
- def test2() end
- CODE
- }
+ def test1() end
+ def test2() end
+ CODE
+ }
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
diff --git a/spec/rubyspec/core/module/shared/set_visibility.rb b/spec/rubyspec/core/module/shared/set_visibility.rb
index 45eedc13fa..c39d59e05d 100644
--- a/spec/rubyspec/core/module/shared/set_visibility.rb
+++ b/spec/rubyspec/core/module/shared/set_visibility.rb
@@ -9,11 +9,11 @@ describe :set_visibility, shared: true do
it "sets visibility to following method definitions" do
visibility = @method
mod = Module.new {
- send visibility
+ send visibility
- def test1() end
- def test2() end
- }
+ def test1() end
+ def test2() end
+ }
mod.should send(:"have_#{@method}_instance_method", :test1, false)
mod.should send(:"have_#{@method}_instance_method", :test2, false)
@@ -23,11 +23,11 @@ describe :set_visibility, shared: true do
visibility = @method
new_visibility = nil
mod = Module.new {
- send visibility
- new_visibility = [:protected, :private].find {|vis| vis != visibility }
- send new_visibility
- def test1() end
- }
+ send visibility
+ new_visibility = [:protected, :private].find {|vis| vis != visibility }
+ send new_visibility
+ def test1() end
+ }
mod.should send(:"have_#{new_visibility}_instance_method", :test1, false)
end
@@ -35,11 +35,11 @@ describe :set_visibility, shared: true do
it "continues setting visibility if the body encounters other visibility setters with arguments" do
visibility = @method
mod = Module.new {
- send visibility
- def test1() end
- send([:protected, :private].find {|vis| vis != visibility }, :test1)
- def test2() end
- }
+ send visibility
+ def test1() end
+ send([:protected, :private].find {|vis| vis != visibility }, :test1)
+ def test2() end
+ }
mod.should send(:"have_#{@method}_instance_method", :test2, false)
end
@@ -47,11 +47,11 @@ describe :set_visibility, shared: true do
it "does not affect module_evaled method definitions when itself is outside the eval" do
visibility = @method
mod = Module.new {
- send visibility
+ send visibility
- module_eval { def test1() end }
- module_eval " def test2() end "
- }
+ module_eval { def test1() end }
+ module_eval " def test2() end "
+ }
mod.should have_public_instance_method(:test1, false)
mod.should have_public_instance_method(:test2, false)
@@ -60,10 +60,10 @@ describe :set_visibility, shared: true do
it "does not affect outside method definitions when itself is inside a module_eval" do
visibility = @method
mod = Module.new {
- module_eval { send visibility }
+ module_eval { send visibility }
- def test1() end
- }
+ def test1() end
+ }
mod.should have_public_instance_method(:test1, false)
end
@@ -71,12 +71,12 @@ describe :set_visibility, shared: true do
it "affects normally if itself and method definitions are inside a module_eval" do
visibility = @method
mod = Module.new {
- module_eval {
- send visibility
+ module_eval {
+ send visibility
- def test1() end
- }
- }
+ def test1() end
+ }
+ }
mod.should send(:"have_#{@method}_instance_method", :test1, false)
end
@@ -85,11 +85,11 @@ describe :set_visibility, shared: true do
visibility = @method
initialized_visibility = [:public, :protected, :private].find {|sym| sym != visibility }
mod = Module.new {
- send initialized_visibility
- eval visibility.to_s
+ send initialized_visibility
+ eval visibility.to_s
- def test1() end
- }
+ def test1() end
+ }
mod.should send(:"have_#{initialized_visibility}_instance_method", :test1, false)
end
@@ -97,10 +97,10 @@ describe :set_visibility, shared: true do
it "affects evaled method definitions when itself is outside the eval" do
visibility = @method
mod = Module.new {
- send visibility
+ send visibility
- eval "def test1() end"
- }
+ eval "def test1() end"
+ }
mod.should send(:"have_#{@method}_instance_method", :test1, false)
end
@@ -108,12 +108,12 @@ describe :set_visibility, shared: true do
it "affects normally if itself and following method definitions are inside a eval" do
visibility = @method
mod = Module.new {
- eval <<-CODE
- #{visibility}
+ eval <<-CODE
+ #{visibility}
- def test1() end
- CODE
- }
+ def test1() end
+ CODE
+ }
mod.should send(:"have_#{@method}_instance_method", :test1, false)
end
@@ -122,11 +122,11 @@ describe :set_visibility, shared: true do
it "sets the visibility outside the closure" do
visibility = @method
mod = Module.new {
- 1.times {
- send visibility
- }
- def test1() end
- }
+ 1.times {
+ send visibility
+ }
+ def test1() end
+ }
mod.should send(:"have_#{@method}_instance_method", :test1, false)
end
diff --git a/spec/rubyspec/core/nil/nilclass_spec.rb b/spec/rubyspec/core/nil/nilclass_spec.rb
new file mode 100644
index 0000000000..3f28cde0bd
--- /dev/null
+++ b/spec/rubyspec/core/nil/nilclass_spec.rb
@@ -0,0 +1,15 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "NilClass" do
+ it ".allocate raises a TypeError" do
+ lambda do
+ NilClass.allocate
+ end.should raise_error(TypeError)
+ end
+
+ it ".new is undefined" do
+ lambda do
+ NilClass.new
+ end.should raise_error(NoMethodError)
+ end
+end
diff --git a/spec/rubyspec/core/numeric/shared/step.rb b/spec/rubyspec/core/numeric/shared/step.rb
index 6898a9ff3c..3072830534 100644
--- a/spec/rubyspec/core/numeric/shared/step.rb
+++ b/spec/rubyspec/core/numeric/shared/step.rb
@@ -407,6 +407,18 @@ describe :numeric_step, :shared => true do
end
end
end
+
+ describe "when stop is not passed" do
+ it "returns infinity_value" do
+ 1.send(@method, *@step_args.call()).size.should == infinity_value
+ end
+ end
+
+ describe "when stop is nil" do
+ it "returns infinity_value" do
+ 1.send(@method, *@step_args.call(nil, 5)).size.should == infinity_value
+ end
+ end
end
end
end
diff --git a/spec/rubyspec/core/process/fixtures/common.rb b/spec/rubyspec/core/process/fixtures/common.rb
index 046efa5396..bdbf1e654b 100644
--- a/spec/rubyspec/core/process/fixtures/common.rb
+++ b/spec/rubyspec/core/process/fixtures/common.rb
@@ -1,4 +1,17 @@
module ProcessSpecs
+ def self.use_system_ruby(context)
+ if defined?(MSpecScript::SYSTEM_RUBY)
+ context.send(:before, :all) do
+ @ruby = ::RUBY_EXE
+ Object.const_set(:RUBY_EXE, MSpecScript::SYSTEM_RUBY)
+ end
+
+ context.send(:after, :all) do
+ Object.const_set(:RUBY_EXE, @ruby)
+ end
+ end
+ end
+
class Daemonizer
attr_reader :input, :data
@@ -55,13 +68,6 @@ module ProcessSpecs
end
def wait_on_result
- # Ensure the process exits
- begin
- Process.kill :TERM, pid if pid
- rescue Errno::ESRCH
- # Ignore the process not existing
- end
-
@thread.join
end
diff --git a/spec/rubyspec/core/process/fixtures/env.rb b/spec/rubyspec/core/process/fixtures/env.rb
deleted file mode 100644
index 2d626caf26..0000000000
--- a/spec/rubyspec/core/process/fixtures/env.rb
+++ /dev/null
@@ -1 +0,0 @@
-File.write ARGV[0], ENV["FOO"]
diff --git a/spec/rubyspec/core/process/fixtures/print.rb b/spec/rubyspec/core/process/fixtures/print.rb
deleted file mode 100644
index 3697f7dc93..0000000000
--- a/spec/rubyspec/core/process/fixtures/print.rb
+++ /dev/null
@@ -1 +0,0 @@
-print :glark
diff --git a/spec/rubyspec/core/process/kill_spec.rb b/spec/rubyspec/core/process/kill_spec.rb
index c7b0e2a129..4316daf374 100644
--- a/spec/rubyspec/core/process/kill_spec.rb
+++ b/spec/rubyspec/core/process/kill_spec.rb
@@ -2,6 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/common', __FILE__)
describe "Process.kill" do
+ ProcessSpecs.use_system_ruby(self)
+
before :each do
@pid = Process.pid
end
@@ -22,7 +24,7 @@ describe "Process.kill" do
end
it "raises Errno::ESRCH if the process does not exist" do
- pid = Process.spawn(ruby_cmd("sleep 10"))
+ pid = Process.spawn(*ruby_exe, "-e", "sleep 10")
Process.kill("SIGKILL", pid)
Process.wait(pid)
lambda {
@@ -33,6 +35,8 @@ end
platform_is_not :windows do
describe "Process.kill" do
+ ProcessSpecs.use_system_ruby(self)
+
before :each do
@sp = ProcessSpecs::Signalizer.new
end
@@ -73,6 +77,8 @@ platform_is_not :windows do
end
describe "Process.kill" do
+ ProcessSpecs.use_system_ruby(self)
+
before :each do
@sp1 = ProcessSpecs::Signalizer.new
@sp2 = ProcessSpecs::Signalizer.new
@@ -95,57 +101,27 @@ platform_is_not :windows do
end
describe "Process.kill" do
- before :each do
- @sp = ProcessSpecs::Signalizer.new "self"
- end
-
after :each do
- @sp.cleanup
+ @sp.cleanup if @sp
end
it "signals the process group if the PID is zero" do
+ @sp = ProcessSpecs::Signalizer.new "self"
@sp.result.should == "signaled"
end
- end
-
- describe "Process.kill" do
- before :each do
- @sp = ProcessSpecs::Signalizer.new "group_numeric"
- end
-
- after :each do
- @sp.cleanup
- end
it "signals the process group if the signal number is negative" do
+ @sp = ProcessSpecs::Signalizer.new "group_numeric"
@sp.result.should == "signaled"
end
- end
-
- describe "Process.kill" do
- before :each do
- @sp = ProcessSpecs::Signalizer.new "group_short_string"
- end
-
- after :each do
- @sp.cleanup
- end
it "signals the process group if the short signal name starts with a minus sign" do
+ @sp = ProcessSpecs::Signalizer.new "group_short_string"
@sp.result.should == "signaled"
end
- end
-
- describe "Process.kill" do
- before :each do
- @sp = ProcessSpecs::Signalizer.new "group_full_string"
- end
-
- after :each do
- @sp.cleanup
- end
it "signals the process group if the full signal name starts with a minus sign" do
+ @sp = ProcessSpecs::Signalizer.new "group_full_string"
@sp.result.should == "signaled"
end
end
diff --git a/spec/rubyspec/core/process/spawn_spec.rb b/spec/rubyspec/core/process/spawn_spec.rb
index 66b5c5e402..330ec8fcd8 100644
--- a/spec/rubyspec/core/process/spawn_spec.rb
+++ b/spec/rubyspec/core/process/spawn_spec.rb
@@ -1,4 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/common', __FILE__)
newline = "\n"
platform_is :windows do
@@ -31,8 +32,14 @@ describe :process_spawn_does_not_close_std_streams, shared: true do
end
describe "Process.spawn" do
+ ProcessSpecs.use_system_ruby(self)
+
before :each do
@name = tmp("process_spawn.txt")
+ @var = "$FOO"
+ platform_is :windows do
+ @var = "%FOO%"
+ end
end
after :each do
@@ -44,14 +51,14 @@ describe "Process.spawn" do
end
it "returns the process ID of the new process as a Fixnum" do
- pid = Process.spawn(ruby_cmd("exit"))
+ pid = Process.spawn(*ruby_exe, "-e", "exit")
Process.wait pid
pid.should be_an_instance_of(Fixnum)
end
it "returns immediately" do
start = Time.now
- pid = Process.spawn(ruby_cmd("sleep 10"))
+ pid = Process.spawn(*ruby_exe, "-e", "sleep 10")
(Time.now - start).should < 5
Process.kill :KILL, pid
Process.wait pid
@@ -196,52 +203,57 @@ describe "Process.spawn" do
end
it "sets environment variables in the child environment" do
- Process.wait Process.spawn({"FOO" => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == "BAR"
+ Process.wait Process.spawn({"FOO" => "BAR"}, "echo #{@var}>#{@name}")
+ File.read(@name).should == "BAR\n"
end
it "unsets environment variables whose value is nil" do
ENV["FOO"] = "BAR"
- Process.wait Process.spawn({"FOO" => nil}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == ""
+ Process.wait Process.spawn({"FOO" => nil}, "echo #{@var}>#{@name}")
+ expected = "\n"
+ platform_is :windows do
+ # Windows does not expand the variable if it is unset
+ expected = "#{@var}\n"
+ end
+ File.read(@name).should == expected
end
it "calls #to_hash to convert the environment" do
o = mock("to_hash")
o.should_receive(:to_hash).and_return({"FOO" => "BAR"})
- Process.wait Process.spawn(o, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == "BAR"
+ Process.wait Process.spawn(o, "echo #{@var}>#{@name}")
+ File.read(@name).should == "BAR\n"
end
it "calls #to_str to convert the environment keys" do
o = mock("to_str")
o.should_receive(:to_str).and_return("FOO")
- Process.wait Process.spawn({o => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == "BAR"
+ Process.wait Process.spawn({o => "BAR"}, "echo #{@var}>#{@name}")
+ File.read(@name).should == "BAR\n"
end
it "calls #to_str to convert the environment values" do
o = mock("to_str")
o.should_receive(:to_str).and_return("BAR")
- Process.wait Process.spawn({"FOO" => o}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == "BAR"
+ Process.wait Process.spawn({"FOO" => o}, "echo #{@var}>#{@name}")
+ File.read(@name).should == "BAR\n"
end
it "raises an ArgumentError if an environment key includes an equals sign" do
lambda do
- Process.spawn({"FOO=" => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
+ Process.spawn({"FOO=" => "BAR"}, "echo #{@var}>#{@name}")
end.should raise_error(ArgumentError)
end
it "raises an ArgumentError if an environment key includes a null byte" do
lambda do
- Process.spawn({"\000" => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
+ Process.spawn({"\000" => "BAR"}, "echo #{@var}>#{@name}")
end.should raise_error(ArgumentError)
end
it "raises an ArgumentError if an environment value includes a null byte" do
lambda do
- Process.spawn({"FOO" => "\000"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
+ Process.spawn({"FOO" => "\000"}, "echo #{@var}>#{@name}")
end.should raise_error(ArgumentError)
end
@@ -252,7 +264,7 @@ describe "Process.spawn" do
"PATH" => ENV["PATH"],
"HOME" => ENV["HOME"]
}
- @common_env_spawn_args = [@minimal_env, ruby_cmd(fixture(__FILE__, "env.rb"), options: "--disable-gems", args: @name)]
+ @common_env_spawn_args = [@minimal_env, "echo #{@var}>#{@name}"]
end
platform_is_not :windows do
@@ -260,7 +272,7 @@ describe "Process.spawn" do
ENV["FOO"] = "BAR"
Process.wait Process.spawn(*@common_env_spawn_args, unsetenv_others: true)
$?.success?.should be_true
- File.read(@name).should == ""
+ File.read(@name).should == "\n"
end
end
@@ -268,15 +280,15 @@ describe "Process.spawn" do
ENV["FOO"] = "BAR"
Process.wait Process.spawn(*@common_env_spawn_args, unsetenv_others: false)
$?.success?.should be_true
- File.read(@name).should == "BAR"
+ File.read(@name).should == "BAR\n"
end
platform_is_not :windows do
it "does not unset environment variables included in the environment hash" do
env = @minimal_env.merge({"FOO" => "BAR"})
- Process.wait Process.spawn(env, ruby_cmd(fixture(__FILE__, "env.rb"), options: "--disable-gems", args: @name), unsetenv_others: true)
+ Process.wait Process.spawn(env, "echo #{@var}>#{@name}", unsetenv_others: true)
$?.success?.should be_true
- File.read(@name).should == "BAR"
+ File.read(@name).should == "BAR\n"
end
end
@@ -400,55 +412,55 @@ describe "Process.spawn" do
it "redirects STDOUT to the given file descriptior if out: Fixnum" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: file.fileno)
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark", out: file.fileno)
+ end.should output_to_fd("glark\n", file)
end
end
it "redirects STDOUT to the given file if out: IO" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: file)
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark", out: file)
+ end.should output_to_fd("glark\n", file)
end
end
it "redirects STDOUT to the given file if out: String" do
- Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: @name)
- File.read(@name).should == "glark"
+ Process.wait Process.spawn("echo glark", out: @name)
+ File.read(@name).should == "glark\n"
end
it "redirects STDOUT to the given file if out: [String name, String mode]" do
- Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: [@name, 'w'])
- File.read(@name).should == "glark"
+ Process.wait Process.spawn("echo glark", out: [@name, 'w'])
+ File.read(@name).should == "glark\n"
end
it "redirects STDERR to the given file descriptior if err: Fixnum" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), err: file.fileno)
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark>&2", err: file.fileno)
+ end.should output_to_fd("glark\n", file)
end
end
it "redirects STDERR to the given file descriptor if err: IO" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), err: file)
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark>&2", err: file)
+ end.should output_to_fd("glark\n", file)
end
end
it "redirects STDERR to the given file if err: String" do
- Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), err: @name)
- File.read(@name).should == "glark"
+ Process.wait Process.spawn("echo glark>&2", err: @name)
+ File.read(@name).should == "glark\n"
end
it "redirects STDERR to child STDOUT if :err => [:child, :out]" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), :out => file, :err => [:child, :out])
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark>&2", :out => file, :err => [:child, :out])
+ end.should output_to_fd("glark\n", file)
end
end
diff --git a/spec/rubyspec/core/process/wait_spec.rb b/spec/rubyspec/core/process/wait_spec.rb
index dca43140fd..8111621695 100644
--- a/spec/rubyspec/core/process/wait_spec.rb
+++ b/spec/rubyspec/core/process/wait_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/common', __FILE__)
describe "Process.wait" do
+ ProcessSpecs.use_system_ruby(self)
+
before :all do
begin
leaked = Process.waitall
diff --git a/spec/rubyspec/core/regexp/encoding_spec.rb b/spec/rubyspec/core/regexp/encoding_spec.rb
index 6ce1ada337..c30519c9d7 100644
--- a/spec/rubyspec/core/regexp/encoding_spec.rb
+++ b/spec/rubyspec/core/regexp/encoding_spec.rb
@@ -15,7 +15,7 @@ describe "Regexp#encoding" do
end
it "returns ASCII-8BIT if the 'n' modifier is supplied and non-US-ASCII characters are present" do
- /#{}\xc2\xa1/n.encoding.should == Encoding::ASCII_8BIT
+ /\xc2\xa1/n.encoding.should == Encoding::ASCII_8BIT
end
it "defaults to UTF-8 if \\u escapes appear" do
diff --git a/spec/rubyspec/core/string/encoding_spec.rb b/spec/rubyspec/core/string/encoding_spec.rb
index a07032b041..9c655757a8 100644
--- a/spec/rubyspec/core/string/encoding_spec.rb
+++ b/spec/rubyspec/core/string/encoding_spec.rb
@@ -133,7 +133,7 @@ with_feature :encoding do
str += [0xDF].pack('C')
str.ascii_only?.should be_false
str.encoding.should == Encoding::ASCII_8BIT
- end
+ end
# TODO: Deal with case when the byte in question isn't valid in the source
# encoding?
diff --git a/spec/rubyspec/core/symbol/symbol_spec.rb b/spec/rubyspec/core/symbol/symbol_spec.rb
index bb95211ba0..af6b46fed3 100644
--- a/spec/rubyspec/core/symbol/symbol_spec.rb
+++ b/spec/rubyspec/core/symbol/symbol_spec.rb
@@ -4,4 +4,16 @@ describe "Symbol" do
it "includes Comparable" do
Symbol.include?(Comparable).should == true
end
+
+ it ".allocate raises a TypeError" do
+ lambda do
+ Symbol.allocate
+ end.should raise_error(TypeError)
+ end
+
+ it ".new is undefined" do
+ lambda do
+ Symbol.new
+ end.should raise_error(NoMethodError)
+ end
end
diff --git a/spec/rubyspec/core/time/dup_spec.rb b/spec/rubyspec/core/time/dup_spec.rb
index 16aab04200..b32ce96d44 100644
--- a/spec/rubyspec/core/time/dup_spec.rb
+++ b/spec/rubyspec/core/time/dup_spec.rb
@@ -36,4 +36,11 @@ describe "Time#dup" do
t.dup.should be_an_instance_of(c)
t.dup.should_not be_an_instance_of(Time)
end
+
+ it "does not copy frozen status from the original" do
+ t = Time.now
+ t.freeze
+ t2 = t.dup
+ t2.frozen?.should be_false
+ end
end
diff --git a/spec/rubyspec/core/time/localtime_spec.rb b/spec/rubyspec/core/time/localtime_spec.rb
index 8144fd67e6..6f682b0b34 100644
--- a/spec/rubyspec/core/time/localtime_spec.rb
+++ b/spec/rubyspec/core/time/localtime_spec.rb
@@ -22,6 +22,20 @@ describe "Time#localtime" do
t.utc_offset.should == 3630
end
+ describe "on a frozen time" do
+ it "does not raise an error if already in the right time zone" do
+ time = Time.now
+ time.freeze
+ time.localtime.should equal(time)
+ end
+
+ it "raises a RuntimeError if the time has a different time zone" do
+ time = Time.gm(2007, 1, 9, 12, 0, 0)
+ time.freeze
+ lambda { time.localtime }.should raise_error(RuntimeError)
+ end
+ end
+
describe "with an argument that responds to #to_int" do
it "coerces using #to_int" do
o = mock('integer')
diff --git a/spec/rubyspec/core/time/shared/gmtime.rb b/spec/rubyspec/core/time/shared/gmtime.rb
index a1b4b88418..e684a1fd95 100644
--- a/spec/rubyspec/core/time/shared/gmtime.rb
+++ b/spec/rubyspec/core/time/shared/gmtime.rb
@@ -1,5 +1,5 @@
describe :time_gmtime, shared: true do
- it "returns the utc representation of time" do
+ it "converts self to UTC, modifying the receiver" do
# Testing with America/Regina here because it doesn't have DST.
with_timezone("CST", -6) do
t = Time.local(2007, 1, 9, 6, 0, 0)
@@ -7,4 +7,27 @@ describe :time_gmtime, shared: true do
t.should == Time.gm(2007, 1, 9, 12, 0, 0)
end
end
+
+ it "returns self" do
+ with_timezone("CST", -6) do
+ t = Time.local(2007, 1, 9, 12, 0, 0)
+ t.send(@method).should equal(t)
+ end
+ end
+
+ describe "on a frozen time" do
+ it "does not raise an error if already in UTC" do
+ time = Time.gm(2007, 1, 9, 12, 0, 0)
+ time.freeze
+ time.send(@method).should equal(time)
+ end
+
+ it "raises a RuntimeError if the time is not UTC" do
+ with_timezone("CST", -6) do
+ time = Time.now
+ time.freeze
+ lambda { time.send(@method) }.should raise_error(RuntimeError)
+ end
+ end
+ end
end
diff --git a/spec/rubyspec/core/true/trueclass_spec.rb b/spec/rubyspec/core/true/trueclass_spec.rb
new file mode 100644
index 0000000000..8837117d71
--- /dev/null
+++ b/spec/rubyspec/core/true/trueclass_spec.rb
@@ -0,0 +1,15 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "TrueClass" do
+ it ".allocate raises a TypeError" do
+ lambda do
+ TrueClass.allocate
+ end.should raise_error(TypeError)
+ end
+
+ it ".new is undefined" do
+ lambda do
+ TrueClass.new
+ end.should raise_error(NoMethodError)
+ end
+end