diff --git a/spec/ruby/core/basicobject/method_missing_spec.rb b/spec/ruby/core/basicobject/method_missing_spec.rb index 540723a630..244c0d83dc 100644 --- a/spec/ruby/core/basicobject/method_missing_spec.rb +++ b/spec/ruby/core/basicobject/method_missing_spec.rb @@ -1,7 +1,9 @@ require File.expand_path('../../../shared/kernel/method_missing', __FILE__) describe "BasicObject#method_missing" do - it_behaves_like :method_missing, nil, BasicObject + it "is a private method" do + BasicObject.should have_private_instance_method(:method_missing) + end end describe "BasicObject#method_missing" do diff --git a/spec/ruby/core/kernel/caller_spec.rb b/spec/ruby/core/kernel/caller_spec.rb index 2db9719bce..cc14b1c88b 100644 --- a/spec/ruby/core/kernel/caller_spec.rb +++ b/spec/ruby/core/kernel/caller_spec.rb @@ -1,115 +1,7 @@ require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) -# DO NOT PUT ANYTHING ABOVE THIS describe "Kernel#caller" do - before :each do - def a(skip) - caller(skip) - end - def b(skip) - a(skip) - end - def c(skip) - b(skip) - end - end - it "is a private method" do Kernel.should have_private_instance_method(:caller) end - - it "returns the current call stack" do - stack = c 0 - stack[0].should =~ /caller_spec.rb.*?8.*?`a'/ - stack[1].should =~ /caller_spec.rb.*?11.*?`b'/ - stack[2].should =~ /caller_spec.rb.*?14.*?`c'/ - end - - it "omits a number of frames corresponding to the parameter" do - c(0)[1..-1].should == c(1) - c(0)[2..-1].should == c(2) - c(0)[3..-1].should == c(3) - end - - it "defaults to omitting one frame" do - caller.should == caller(1) - end - - # The contents of the array returned by #caller depends on whether - # the call is made from an instance_eval block or a #call. - # We purposely do not spec what happens if you request to omit - # more entries than exist in the array returned. -end - -describe "Kernel#caller in a Proc or eval" do - it "returns the definition trace of a block when evaluated in a Proc binding" do - stack = CallerFixture.caller_of(CallerFixture.block) - stack[0].should =~ /caller_fixture1\.rb:4:in `'/ - stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/ - stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/ - stack[3].should =~ /caller_spec\.rb:95:in `block \(3 levels\) in '/ - end - - it "returns the definition trace of a Proc" do - stack = CallerFixture.caller_of(CallerFixture.example_proc) - stack[0].should =~ /caller_fixture1\.rb:14:in `example_proc'/ - stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/ - stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/ - stack[3].should =~ /caller_spec\.rb:103:in `block \(3 levels\) in '/ - end - - it "returns the correct caller line from a called Proc" do - stack = CallerFixture.entry_point.call - stack[0].should =~ /caller_fixture1\.rb:31:in `block in third'/ - stack[1].should =~ /caller_spec\.rb:111:in `call'/ - stack[2].should =~ /caller_spec\.rb:111:in `block \(3 levels\) in '/ - end - - # On 1.8 this expectation is marred by bug #146. I don't understand 1.9's - # output to ascertain whether the same bug occurs here, and if so what is - # the correct behaviour - it "returns the correct definition line for a complex Proc trace" do - stack = CallerFixture.caller_of(CallerFixture.entry_point) - stack[0].should =~ /caller_fixture1\.rb:29:in `third'/ - stack[1].should =~ /caller_fixture2\.rb:18:in `eval'/ - stack[2].should =~ /caller_fixture2\.rb:18:in `caller_of'/ - stack[3].should =~ /caller_spec.rb:121:in `block \(3 levels\) in '/ - end - - it "begins with (eval) for caller(0) in eval" do - stack = CallerFixture.eval_caller(0) - stack[0].should == "(eval):1:in `eval_caller'" - stack[1].should =~ /caller_fixture2\.rb:23:in `eval'/ - stack[2].should =~ /caller_fixture2\.rb:23:in `eval_caller'/ - stack[3].should =~ /caller_spec\.rb:129:in `block \(3 levels\) in '/ - end - - it "shows the current line in the calling block twice when evaled" do - stack = CallerFixture.eval_caller(0); line = __LINE__ - stack[0].should == "(eval):1:in `eval_caller'" - stack[1].should =~/caller_fixture2\.rb:23:in `eval'/ - stack[2].should =~/caller_fixture2\.rb:23:in `eval_caller'/ - stack[3].should =~/caller_spec\.rb:#{line}:in `block \(3 levels\) in / - end - - it "begins with the eval's sender's sender for caller(4) in eval" do - stack = CallerFixture.eval_caller(4) - stack[0].should =~ /\.rb:\d+:in `instance_eval'/ # mspec.rb - end - - it "returns one frame for new and one frame for initialize when creating objects" do - stack = CallerFixture::InitializeRecorder.new(0).caller_on_initialize - stack[0].should =~ /initialize/ - stack[1].should =~ /new/ - end -end - -describe "Kernel.caller" do - # redmine:3011 - it "returns one entry per call, even for recursive methods" do - two = CallerSpecs::recurse(2) - three = CallerSpecs::recurse(3) - (three.size - two.size).should == 1 - end end diff --git a/spec/ruby/core/kernel/fixtures/caller_fixture1.rb b/spec/ruby/core/kernel/fixtures/caller_fixture1.rb deleted file mode 100644 index 8f7b46f99b..0000000000 --- a/spec/ruby/core/kernel/fixtures/caller_fixture1.rb +++ /dev/null @@ -1,42 +0,0 @@ -require File.expand_path('../caller_fixture2', __FILE__) -2 + 2 -3 + 3 -CallerFixture.capture do - 5 + 5 - 6 + 6 - :seven - 8 + 8 -end - -module CallerFixture - module_function - def example_proc - Proc.new do - 1 + 1 - 2 + 2 - end - end - - def entry_point - second - end - - def second - third - end - - def third - b = fourth do - 1 + 1 - caller(0) - end - 2 + 2 - 3 + 3 - return b - end - - def fourth(&block) - return block - end -end - diff --git a/spec/ruby/core/kernel/fixtures/caller_fixture2.rb b/spec/ruby/core/kernel/fixtures/caller_fixture2.rb deleted file mode 100644 index c47b02bc4b..0000000000 --- a/spec/ruby/core/kernel/fixtures/caller_fixture2.rb +++ /dev/null @@ -1,33 +0,0 @@ -module CallerFixture - def block - @block - end - module_function :block - - def block=(block) - @block = block - end - module_function :block= - - def capture(&block) - @block = block - end - module_function :capture - - def caller_of(block) - eval("caller(0)", block.binding) - end - module_function :caller_of - - def eval_caller(depth) - eval("caller(#{depth})") - end - module_function :eval_caller - - class InitializeRecorder - attr_reader :caller_on_initialize - def initialize(level) - @caller_on_initialize = caller(level) - end - end -end diff --git a/spec/ruby/core/kernel/fixtures/classes.rb b/spec/ruby/core/kernel/fixtures/classes.rb index c2a853c06e..0dde1929cf 100644 --- a/spec/ruby/core/kernel/fixtures/classes.rb +++ b/spec/ruby/core/kernel/fixtures/classes.rb @@ -1,5 +1,3 @@ -require File.expand_path('../caller_fixture1', __FILE__) - module KernelSpecs def self.Array_function(arg) Array(arg) @@ -439,13 +437,6 @@ def self.call_eval end end -module CallerSpecs - def self.recurse(n) - return caller if n <= 0 - recurse(n-1) - end -end - # for Kernel#sleep to have Channel in it's specs # TODO: switch directly to queue for both Kernel#sleep and Thread specs? unless defined? Channel diff --git a/spec/ruby/core/kernel/method_missing_spec.rb b/spec/ruby/core/kernel/method_missing_spec.rb index 04416ef83b..10e700efda 100644 --- a/spec/ruby/core/kernel/method_missing_spec.rb +++ b/spec/ruby/core/kernel/method_missing_spec.rb @@ -1,9 +1,5 @@ require File.expand_path('../../../shared/kernel/method_missing', __FILE__) -describe "Kernel#method_missing" do - it_behaves_like :method_missing, nil, Kernel -end - describe "Kernel#method_missing" do it_behaves_like :method_missing_defined_module, nil, KernelSpecs::ModuleMM end diff --git a/spec/ruby/core/kernel/to_enum_spec.rb b/spec/ruby/core/kernel/to_enum_spec.rb index a29ecdcf95..9fb228f318 100644 --- a/spec/ruby/core/kernel/to_enum_spec.rb +++ b/spec/ruby/core/kernel/to_enum_spec.rb @@ -1,7 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Kernel#to_enum" do - it "needs to be reviewed for spec completeness" - end +describe "Kernel#to_enum" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/core/main/define_method_spec.rb b/spec/ruby/core/main/define_method_spec.rb index b4190fea44..741e0624f8 100644 --- a/spec/ruby/core/main/define_method_spec.rb +++ b/spec/ruby/core/main/define_method_spec.rb @@ -22,15 +22,7 @@ Object.should have_method :boom end - ruby_version_is '2.0'...'2.1' do - it 'returns a Proc' do - eval(@code, TOPLEVEL_BINDING).is_a?(Proc).should be_true - end - end - - ruby_version_is '2.1' do - it 'returns the method name as symbol' do - eval(@code, TOPLEVEL_BINDING).should equal :boom - end + it 'returns the method name as symbol' do + eval(@code, TOPLEVEL_BINDING).should equal :boom end end diff --git a/spec/ruby/core/matchdata/begin_spec.rb b/spec/ruby/core/matchdata/begin_spec.rb index 53e7ab5ee3..b1968d5da9 100644 --- a/spec/ruby/core/matchdata/begin_spec.rb +++ b/spec/ruby/core/matchdata/begin_spec.rb @@ -14,32 +14,15 @@ match_data.begin(1).should be_nil end - ruby_version_is ""..."1.9" do - it "returns the offset for multi byte strings" do - match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.") - match_data.begin(0).should == 2 - match_data.begin(2).should == 3 - end - - it "returns the offset for multi byte strings with unicode regexp" do - match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.") - match_data.begin(0).should == 1 - match_data.begin(2).should == 3 - end + it "returns the offset for multi byte strings" do + match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.") + match_data.begin(0).should == 1 + match_data.begin(2).should == 2 end - ruby_version_is "1.9" do - it "returns the offset for multi byte strings" do - match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.") - match_data.begin(0).should == 1 - match_data.begin(2).should == 2 - end - - it "returns the offset for multi byte strings with unicode regexp" do - match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.") - match_data.begin(0).should == 1 - match_data.begin(2).should == 2 - end + it "returns the offset for multi byte strings with unicode regexp" do + match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.") + match_data.begin(0).should == 1 + match_data.begin(2).should == 2 end - end diff --git a/spec/ruby/core/matchdata/element_reference_spec.rb b/spec/ruby/core/matchdata/element_reference_spec.rb index 893a2fb97b..1407f3d77a 100644 --- a/spec/ruby/core/matchdata/element_reference_spec.rb +++ b/spec/ruby/core/matchdata/element_reference_spec.rb @@ -17,6 +17,66 @@ end end -ruby_version_is "1.9" do - require File.expand_path("../versions/element_reference_1.9", __FILE__) +describe "MatchData#[Symbol]" do + it "returns the corresponding named match when given a Symbol" do + md = 'haystack'.match(/(?t(?ack))/) + md[:a].should == 'ack' + md[:t].should == 'tack' + end + + it "returns the corresponding named match when given a String" do + md = 'haystack'.match(/(?t(?ack))/) + md['a'].should == 'ack' + md['t'].should == 'tack' + end + + it "returns the matching version of multiple corresponding named match" do + regexp = /(?: + A(?\w+) + | + B(?\w+) + )/x + md_a = regexp.match("Afoo") + md_b = regexp.match("Bfoo") + + md_a[:word].should == "foo" + md_b[:word].should == "foo" + + md_a['word'].should == "foo" + md_b['word'].should == "foo" + end + + it "returns the last match when multiple named matches exist with the same name" do + md = /(?hay)(?stack)/.match('haystack') + md[:word].should == "stack" + md['word'].should == "stack" + end + + it "returns nil on non-matching named matches" do + regexp = /(?foo )?(?bar)/ + full_match = regexp.match("foo bar") + partial_match = regexp.match("bar") + + full_match[:foo].should == "foo " + partial_match[:foo].should == nil + + full_match['foo'].should == "foo " + partial_match['foo'].should == nil + end + + it "raises an IndexError if there is no named match corresponding to the Symbol" do + md = 'haystack'.match(/(?t(?ack))/) + lambda { md[:baz] }.should raise_error(IndexError, /baz/) + end + + it "raises an IndexError if there is no named match corresponding to the String" do + md = 'haystack'.match(/(?t(?ack))/) + lambda { md['baz'] }.should raise_error(IndexError, /baz/) + end + + it "returns matches in the String's encoding" do + rex = /(?t(?ack))/u + md = 'haystack'.force_encoding('euc-jp').match(rex) + md[:t].encoding.should == Encoding::EUC_JP + end end diff --git a/spec/ruby/core/matchdata/end_spec.rb b/spec/ruby/core/matchdata/end_spec.rb index ecfa809fa6..e2c69cefde 100644 --- a/spec/ruby/core/matchdata/end_spec.rb +++ b/spec/ruby/core/matchdata/end_spec.rb @@ -14,31 +14,15 @@ match_data.end(1).should be_nil end - ruby_version_is ""..."1.9" do - it "returns the offset for multi byte strings" do - match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.") - match_data.end(0).should == 8 - match_data.end(2).should == 4 - end - - it "returns the offset for multi byte strings with unicode regexp" do - match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.") - match_data.end(0).should == 8 - match_data.end(2).should == 4 - end + it "returns the offset for multi byte strings" do + match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.") + match_data.end(0).should == 7 + match_data.end(2).should == 3 end - ruby_version_is "1.9" do - it "returns the offset for multi byte strings" do - match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.") - match_data.end(0).should == 7 - match_data.end(2).should == 3 - end - - it "returns the offset for multi byte strings with unicode regexp" do - match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.") - match_data.end(0).should == 7 - match_data.end(2).should == 3 - end + it "returns the offset for multi byte strings with unicode regexp" do + match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.") + match_data.end(0).should == 7 + match_data.end(2).should == 3 end end diff --git a/spec/ruby/core/matchdata/eql_spec.rb b/spec/ruby/core/matchdata/eql_spec.rb index 77192f5eaa..192acbcd13 100644 --- a/spec/ruby/core/matchdata/eql_spec.rb +++ b/spec/ruby/core/matchdata/eql_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/eql', __FILE__) -ruby_version_is "1.9" do - describe "MatchData#eql?" do - it_behaves_like(:matchdata_eql, :eql?) - end +describe "MatchData#eql?" do + it_behaves_like(:matchdata_eql, :eql?) end diff --git a/spec/ruby/core/matchdata/equal_value_spec.rb b/spec/ruby/core/matchdata/equal_value_spec.rb index e4def48855..0d33d0acf2 100644 --- a/spec/ruby/core/matchdata/equal_value_spec.rb +++ b/spec/ruby/core/matchdata/equal_value_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/eql', __FILE__) -ruby_version_is "1.9" do - describe "MatchData#==" do - it_behaves_like(:matchdata_eql, :==) - end +describe "MatchData#==" do + it_behaves_like(:matchdata_eql, :==) end diff --git a/spec/ruby/core/matchdata/hash_spec.rb b/spec/ruby/core/matchdata/hash_spec.rb index 65c1aa8144..1d5c8a203f 100644 --- a/spec/ruby/core/matchdata/hash_spec.rb +++ b/spec/ruby/core/matchdata/hash_spec.rb @@ -1,7 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "MatchData#hash" do - it "needs to be reviewed for spec completeness" - end +describe "MatchData#hash" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/core/matchdata/inspect_spec.rb b/spec/ruby/core/matchdata/inspect_spec.rb index 9e2d0653e6..3cf968b6f5 100644 --- a/spec/ruby/core/matchdata/inspect_spec.rb +++ b/spec/ruby/core/matchdata/inspect_spec.rb @@ -9,11 +9,9 @@ @match_data.inspect.should be_kind_of(String) end - ruby_version_is '1.8.7' do - it "returns a human readable representation that contains entire matched string and the captures" do - # yeah, hardcoding the inspect output is not ideal, but in this case - # it makes perfect sense. See JRUBY-4558 for example. - @match_data.inspect.should == '#' - end + it "returns a human readable representation that contains entire matched string and the captures" do + # yeah, hardcoding the inspect output is not ideal, but in this case + # it makes perfect sense. See JRUBY-4558 for example. + @match_data.inspect.should == '#' end end diff --git a/spec/ruby/core/matchdata/names_spec.rb b/spec/ruby/core/matchdata/names_spec.rb index 4e85066b5b..e298c85593 100644 --- a/spec/ruby/core/matchdata/names_spec.rb +++ b/spec/ruby/core/matchdata/names_spec.rb @@ -1,5 +1,33 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - require File.expand_path("../versions/names_1.9", __FILE__) +describe "MatchData#names" do + it "returns an Array" do + md = 'haystack'.match(/(?hay)/) + md.names.should be_an_instance_of(Array) + end + + it "sets each element to a String" do + 'haystack'.match(/(?hay)/).names.all? do |e| + e.should be_an_instance_of(String) + end + end + + it "returns the names of the named capture groups" do + md = 'haystack'.match(/(?hay).(?tack)/) + md.names.should == ['yellow', 'pin'] + end + + it "returns [] if there were no named captures" do + 'haystack'.match(/(hay).(tack)/).names.should == [] + end + + it "returns each name only once" do + md = 'haystack'.match(/(?hay)(?.)(?tack)/) + md.names.should == ['hay', 'dot'] + end + + it "equals Regexp#names" do + r = /(?hay)(?.)(?tack)/ + 'haystack'.match(r).names.should == r.names + end end diff --git a/spec/ruby/core/matchdata/offset_spec.rb b/spec/ruby/core/matchdata/offset_spec.rb index c2ff6c750b..9319e07f26 100644 --- a/spec/ruby/core/matchdata/offset_spec.rb +++ b/spec/ruby/core/matchdata/offset_spec.rb @@ -14,32 +14,15 @@ match_data.offset(1).should == [nil, nil] end - ruby_version_is ""..."1.9" do - it "returns the offset for multi byte strings" do - match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.") - match_data.offset(0).should == [2, 8] - match_data.offset(4).should == [7, 8] - end - - it "returns the offset for multi byte strings with unicode regexp" do - match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.") - match_data.offset(0).should == [1, 8] - match_data.offset(4).should == [7, 8] - end + it "returns the offset for multi byte strings" do + match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.") + match_data.offset(0).should == [1, 7] + match_data.offset(4).should == [6, 7] end - ruby_version_is "1.9" do - it "returns the offset for multi byte strings" do - match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.") - match_data.offset(0).should == [1, 7] - match_data.offset(4).should == [6, 7] - end - - it "returns the offset for multi byte strings with unicode regexp" do - match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.") - match_data.offset(0).should == [1, 7] - match_data.offset(4).should == [6, 7] - end + it "returns the offset for multi byte strings with unicode regexp" do + match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.") + match_data.offset(0).should == [1, 7] + match_data.offset(4).should == [6, 7] end - end diff --git a/spec/ruby/core/matchdata/post_match_spec.rb b/spec/ruby/core/matchdata/post_match_spec.rb index de1bfc82e8..670e0887ab 100644 --- a/spec/ruby/core/matchdata/post_match_spec.rb +++ b/spec/ruby/core/matchdata/post_match_spec.rb @@ -14,14 +14,12 @@ $'.tainted?.should be_true end - ruby_version_is "1.9" do - it "keeps untrusted status from the source string" do - str = "THX1138: The Movie" - str.untrust - res = /(.)(.)(\d+)(\d)/.match(str).post_match - res.untrusted?.should be_true - $'.untrusted?.should be_true - end + it "keeps untrusted status from the source string" do + str = "THX1138: The Movie" + str.untrust + res = /(.)(.)(\d+)(\d)/.match(str).post_match + res.untrusted?.should be_true + $'.untrusted?.should be_true end with_feature :encoding do diff --git a/spec/ruby/core/matchdata/pre_match_spec.rb b/spec/ruby/core/matchdata/pre_match_spec.rb index 8b719b302e..1f1f9daec6 100644 --- a/spec/ruby/core/matchdata/pre_match_spec.rb +++ b/spec/ruby/core/matchdata/pre_match_spec.rb @@ -14,14 +14,12 @@ $`.tainted?.should be_true end - ruby_version_is "1.9" do - it "keeps untrusted status from the source string" do - str = "THX1138: The Movie" - str.untrust - res = /(.)(.)(\d+)(\d)/.match(str).pre_match - res.untrusted?.should be_true - $`.untrusted?.should be_true - end + it "keeps untrusted status from the source string" do + str = "THX1138: The Movie" + str.untrust + res = /(.)(.)(\d+)(\d)/.match(str).pre_match + res.untrusted?.should be_true + $`.untrusted?.should be_true end with_feature :encoding do diff --git a/spec/ruby/core/matchdata/regexp_spec.rb b/spec/ruby/core/matchdata/regexp_spec.rb index cdd2cb63ce..2fdca34c30 100644 --- a/spec/ruby/core/matchdata/regexp_spec.rb +++ b/spec/ruby/core/matchdata/regexp_spec.rb @@ -1,15 +1,13 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.8.8" do - describe "MatchData#regexp" do - it "returns a Regexp object" do - m = 'haystack'.match(/hay/) - m.regexp.should be_an_instance_of(Regexp) - end +describe "MatchData#regexp" do + it "returns a Regexp object" do + m = 'haystack'.match(/hay/) + m.regexp.should be_an_instance_of(Regexp) + end - it "returns the pattern used in the match" do - m = 'haystack'.match(/hay/) - m.regexp.should == /hay/ - end + it "returns the pattern used in the match" do + m = 'haystack'.match(/hay/) + m.regexp.should == /hay/ end end diff --git a/spec/ruby/core/matchdata/select_spec.rb b/spec/ruby/core/matchdata/select_spec.rb deleted file mode 100644 index 085f2cdf8a..0000000000 --- a/spec/ruby/core/matchdata/select_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) - -ruby_version_is ""..."1.9" do - describe "MatchData#select" do - it "yields the contents of the match array to a block" do - /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").select { |x| x }.should == ["HX1138", "H", "X", "113", "8"] - end - end -end diff --git a/spec/ruby/core/matchdata/versions/element_reference_1.9.rb b/spec/ruby/core/matchdata/versions/element_reference_1.9.rb deleted file mode 100644 index d0dd5f576c..0000000000 --- a/spec/ruby/core/matchdata/versions/element_reference_1.9.rb +++ /dev/null @@ -1,65 +0,0 @@ -ruby_version_is "1.9" do - describe "MatchData#[Symbol]" do - it "returns the corresponding named match when given a Symbol" do - md = 'haystack'.match(/(?t(?ack))/) - md[:a].should == 'ack' - md[:t].should == 'tack' - end - - it "returns the corresponding named match when given a String" do - md = 'haystack'.match(/(?t(?ack))/) - md['a'].should == 'ack' - md['t'].should == 'tack' - end - - it "returns the matching version of multiple corresponding named match" do - regexp = /(?: - A(?\w+) - | - B(?\w+) - )/x - md_a = regexp.match("Afoo") - md_b = regexp.match("Bfoo") - - md_a[:word].should == "foo" - md_b[:word].should == "foo" - - md_a['word'].should == "foo" - md_b['word'].should == "foo" - end - - it "returns the last match when multiple named matches exist with the same name" do - md = /(?hay)(?stack)/.match('haystack') - md[:word].should == "stack" - md['word'].should == "stack" - end - - it "returns nil on non-matching named matches" do - regexp = /(?foo )?(?bar)/ - full_match = regexp.match("foo bar") - partial_match = regexp.match("bar") - - full_match[:foo].should == "foo " - partial_match[:foo].should == nil - - full_match['foo'].should == "foo " - partial_match['foo'].should == nil - end - - it "raises an IndexError if there is no named match corresponding to the Symbol" do - md = 'haystack'.match(/(?t(?ack))/) - lambda { md[:baz] }.should raise_error(IndexError, /baz/) - end - - it "raises an IndexError if there is no named match corresponding to the String" do - md = 'haystack'.match(/(?t(?ack))/) - lambda { md['baz'] }.should raise_error(IndexError, /baz/) - end - - it "returns matches in the String's encoding" do - rex = /(?t(?ack))/u - md = 'haystack'.force_encoding('euc-jp').match(rex) - md[:t].encoding.should == Encoding::EUC_JP - end - end -end diff --git a/spec/ruby/core/matchdata/versions/names_1.9.rb b/spec/ruby/core/matchdata/versions/names_1.9.rb deleted file mode 100644 index 17968daf4e..0000000000 --- a/spec/ruby/core/matchdata/versions/names_1.9.rb +++ /dev/null @@ -1,33 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) - -describe "MatchData#names" do - it "returns an Array" do - md = 'haystack'.match(/(?hay)/) - md.names.should be_an_instance_of(Array) - end - - it "sets each element to a String" do - 'haystack'.match(/(?hay)/).names.all? do |e| - e.should be_an_instance_of(String) - end - end - - it "returns the names of the named capture groups" do - md = 'haystack'.match(/(?hay).(?tack)/) - md.names.should == ['yellow', 'pin'] - end - - it "returns [] if there were no named captures" do - 'haystack'.match(/(hay).(tack)/).names.should == [] - end - - it "returns each name only once" do - md = 'haystack'.match(/(?hay)(?.)(?tack)/) - md.names.should == ['hay', 'dot'] - end - - it "equals Regexp#names" do - r = /(?hay)(?.)(?tack)/ - 'haystack'.match(r).names.should == r.names - end -end diff --git a/spec/ruby/core/math/acos_spec.rb b/spec/ruby/core/math/acos_spec.rb index a36288ab98..a090d1885b 100644 --- a/spec/ruby/core/math/acos_spec.rb +++ b/spec/ruby/core/math/acos_spec.rb @@ -30,24 +30,12 @@ end end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the string argument cannot be coerced with Float()" do - lambda { Math.acos("test") }.should raise_error(ArgumentError) - end - - it "raises Errno::EDOM given NaN" do - lambda { Math.acos(nan_value) }.should raise_error(Errno::EDOM) - end + it "raises a TypeError if the string argument cannot be coerced with Float()" do + lambda { Math.acos("test") }.should raise_error(TypeError) end - ruby_version_is "1.9" do - it "raises a TypeError if the string argument cannot be coerced with Float()" do - lambda { Math.acos("test") }.should raise_error(TypeError) - end - - it "returns NaN given NaN" do - Math.acos(nan_value).nan?.should be_true - end + it "returns NaN given NaN" do + Math.acos(nan_value).nan?.should be_true end it "raises a TypeError if the argument cannot be coerced with Float()" do @@ -61,14 +49,6 @@ it "accepts any argument that can be coerced with Float()" do Math.acos(MathSpecs::Float.new(0.5)).should be_close(Math.acos(0.5), TOLERANCE) end - - ruby_version_is ""..."1.9" do - it "coerces string argument with Float() without calling to_f" do - s = MathSpecs::StringSubClass.new("0.5") - s.should_not_receive(:to_f) - Math.acos(s).should be_close(Math.acos(0.5), TOLERANCE) - end - end end describe "Math#acos" do diff --git a/spec/ruby/core/math/acosh_spec.rb b/spec/ruby/core/math/acosh_spec.rb index 4807a538fe..272bfaf6a9 100644 --- a/spec/ruby/core/math/acosh_spec.rb +++ b/spec/ruby/core/math/acosh_spec.rb @@ -19,24 +19,12 @@ end end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.acosh("test") }.should raise_error(ArgumentError) - end - - it "raises Errno::EDOM given NaN" do - lambda { Math.acosh(nan_value) }.should raise_error(Errno::EDOM) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.acosh("test") }.should raise_error(TypeError) end - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.acosh("test") }.should raise_error(TypeError) - end - - it "returns NaN given NaN" do - Math.acosh(nan_value).nan?.should be_true - end + it "returns NaN given NaN" do + Math.acosh(nan_value).nan?.should be_true end it "raises a TypeError if the argument is nil" do diff --git a/spec/ruby/core/math/asin_spec.rb b/spec/ruby/core/math/asin_spec.rb index 1fe3b418f3..ef3426bceb 100644 --- a/spec/ruby/core/math/asin_spec.rb +++ b/spec/ruby/core/math/asin_spec.rb @@ -26,24 +26,12 @@ end end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.asin("test") }.should raise_error(ArgumentError) - end - - it "raises an Errno::EDOM given NaN" do - lambda { Math.asin(nan_value) }.should raise_error( Errno::EDOM) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.asin("test") }.should raise_error(TypeError) end - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.asin("test") }.should raise_error(TypeError) - end - - it "returns NaN given NaN" do - Math.asin(nan_value).nan?.should be_true - end + it "returns NaN given NaN" do + Math.asin(nan_value).nan?.should be_true end it "raises a TypeError if the argument is nil" do diff --git a/spec/ruby/core/math/asinh_spec.rb b/spec/ruby/core/math/asinh_spec.rb index 561d5ec949..0761285806 100644 --- a/spec/ruby/core/math/asinh_spec.rb +++ b/spec/ruby/core/math/asinh_spec.rb @@ -18,16 +18,8 @@ #Math.asinh(-94906265.62).should be_close(-19.0615, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.asinh("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.asinh("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.asinh("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/atan2_spec.rb b/spec/ruby/core/math/atan2_spec.rb index c5fff10568..906852b530 100644 --- a/spec/ruby/core/math/atan2_spec.rb +++ b/spec/ruby/core/math/atan2_spec.rb @@ -13,20 +13,10 @@ Math.atan2(7.22, -3.3).should be_close(1.99950888779256, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.atan2(1.0, "test") }.should raise_error(ArgumentError) - lambda { Math.atan2("test", 0.0) }.should raise_error(ArgumentError) - lambda { Math.atan2("test", "this") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.atan2(1.0, "test") }.should raise_error(TypeError) - lambda { Math.atan2("test", 0.0) }.should raise_error(TypeError) - lambda { Math.atan2("test", "this") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.atan2(1.0, "test") }.should raise_error(TypeError) + lambda { Math.atan2("test", 0.0) }.should raise_error(TypeError) + lambda { Math.atan2("test", "this") }.should raise_error(TypeError) end it "raises a TypeError if the argument is nil" do diff --git a/spec/ruby/core/math/atan_spec.rb b/spec/ruby/core/math/atan_spec.rb index 3f66e4e5b8..6787479cd9 100644 --- a/spec/ruby/core/math/atan_spec.rb +++ b/spec/ruby/core/math/atan_spec.rb @@ -16,18 +16,10 @@ Math.atan(0.75).should be_close(0.643501108793284, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.atan("test") }.should raise_error(ArgumentError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.atan("test") }.should raise_error(TypeError) end - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.atan("test") }.should raise_error(TypeError) - end - end - it "returns NaN given NaN" do Math.atan(nan_value).nan?.should be_true end diff --git a/spec/ruby/core/math/cbrt_spec.rb b/spec/ruby/core/math/cbrt_spec.rb index 9867e3a6b8..0b608151ab 100644 --- a/spec/ruby/core/math/cbrt_spec.rb +++ b/spec/ruby/core/math/cbrt_spec.rb @@ -1,29 +1,27 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "1.9" do - describe "Math.cbrt" do - it "returns a float" do - Math.cbrt(1).should be_an_instance_of(Float) - end +describe "Math.cbrt" do + it "returns a float" do + Math.cbrt(1).should be_an_instance_of(Float) + end - it "returns the cubic root of the argument" do - Math.cbrt(1).should == 1.0 - Math.cbrt(8.0).should == 2.0 - Math.cbrt(-8.0).should == -2.0 - Math.cbrt(3).should be_close(1.44224957030741, TOLERANCE) - end + it "returns the cubic root of the argument" do + Math.cbrt(1).should == 1.0 + Math.cbrt(8.0).should == 2.0 + Math.cbrt(-8.0).should == -2.0 + Math.cbrt(3).should be_close(1.44224957030741, TOLERANCE) + end - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.cbrt("foobar") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.cbrt("foobar") }.should raise_error(TypeError) + end - it "raises a TypeError if the argument is nil" do - lambda { Math.cbrt(nil) }.should raise_error(TypeError) - end + it "raises a TypeError if the argument is nil" do + lambda { Math.cbrt(nil) }.should raise_error(TypeError) + end - it "accepts any argument that can be coerced with Float()" do - Math.cbrt(MathSpecs::Float.new).should be_close(1.0, TOLERANCE) - end + it "accepts any argument that can be coerced with Float()" do + Math.cbrt(MathSpecs::Float.new).should be_close(1.0, TOLERANCE) end end diff --git a/spec/ruby/core/math/cos_spec.rb b/spec/ruby/core/math/cos_spec.rb index 694b857d4f..59b23b198b 100644 --- a/spec/ruby/core/math/cos_spec.rb +++ b/spec/ruby/core/math/cos_spec.rb @@ -16,16 +16,8 @@ end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.cos("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError unless the argument is Numeric and has #to_f" do - lambda { Math.cos("test") }.should raise_error(TypeError) - end + it "raises a TypeError unless the argument is Numeric and has #to_f" do + lambda { Math.cos("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/cosh_spec.rb b/spec/ruby/core/math/cosh_spec.rb index 82c8fa2727..561c3cd312 100644 --- a/spec/ruby/core/math/cosh_spec.rb +++ b/spec/ruby/core/math/cosh_spec.rb @@ -13,16 +13,8 @@ Math.cosh(-2.99).should be_close(9.96798496414416, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.cosh("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.cosh("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.cosh("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/erf_spec.rb b/spec/ruby/core/math/erf_spec.rb index 9799547f19..1ea5693dfe 100644 --- a/spec/ruby/core/math/erf_spec.rb +++ b/spec/ruby/core/math/erf_spec.rb @@ -20,16 +20,8 @@ Math.erf(-0.00000000000001).should be_close(0.0, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.erf("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.erf("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.erf("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/erfc_spec.rb b/spec/ruby/core/math/erfc_spec.rb index e5baa9be47..21c9e246ff 100644 --- a/spec/ruby/core/math/erfc_spec.rb +++ b/spec/ruby/core/math/erfc_spec.rb @@ -19,16 +19,8 @@ Math.erfc(-0.00000000000001).should be_close(1.00000000000001, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.erfc("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.erfc("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.erfc("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/exp_spec.rb b/spec/ruby/core/math/exp_spec.rb index 961ed8d91e..a727404462 100644 --- a/spec/ruby/core/math/exp_spec.rb +++ b/spec/ruby/core/math/exp_spec.rb @@ -13,16 +13,8 @@ Math.exp(1.25).should be_close(3.49034295746184, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.exp("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.exp("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.exp("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/frexp_spec.rb b/spec/ruby/core/math/frexp_spec.rb index 89b17cf668..471f6e7f16 100644 --- a/spec/ruby/core/math/frexp_spec.rb +++ b/spec/ruby/core/math/frexp_spec.rb @@ -8,16 +8,8 @@ exp.should == 7 end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.frexp("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.frexp("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.frexp("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/gamma_spec.rb b/spec/ruby/core/math/gamma_spec.rb index 2f0c09c493..1bc68d59c9 100644 --- a/spec/ruby/core/math/gamma_spec.rb +++ b/spec/ruby/core/math/gamma_spec.rb @@ -1,85 +1,69 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Math.gamma" do - before :all do - @factorial1 = 1 - @factorial2 = 1124000727777607680000 # 22! - end - - it "returns +infinity given 0" do - Math.gamma(0).should == Float::INFINITY - end - - it "returns -infinity given -0.0" do - Math.gamma(-0.0).should == -Float::INFINITY - end +describe "Math.gamma" do + before :all do + @factorial1 = 1 + @factorial2 = 1124000727777607680000 # 22! + end - it "returns Math.sqrt(Math::PI) given 0.5" do - Math.gamma(0.5).should be_close(Math.sqrt(Math::PI), TOLERANCE) - end + it "returns +infinity given 0" do + Math.gamma(0).should == Float::INFINITY + end - # stop at n == 23 because 23! cannot be exactly represented by IEEE 754 double - 2.upto(23) do |n| - it "returns exactly #{n-1}! given #{n}" do - @factorial1 *= n - 1 - Math.gamma(n).should == @factorial1 - end - end + it "returns -infinity given -0.0" do + Math.gamma(-0.0).should == -Float::INFINITY + end - 24.upto(30) do |n| - it "returns approximately #{n-1}! given #{n}" do - @factorial2 *= n - 1 - # compare only the first 12 places, tolerate the rest - Math.gamma(n).should be_close(@factorial2, @factorial2.to_s[12..-1].to_i) - end - end + it "returns Math.sqrt(Math::PI) given 0.5" do + Math.gamma(0.5).should be_close(Math.sqrt(Math::PI), TOLERANCE) + end - it "returns good numerical approximation for gamma(3.2)" do - Math.gamma(3.2).should be_close(2.423965, TOLERANCE) + # stop at n == 23 because 23! cannot be exactly represented by IEEE 754 double + 2.upto(23) do |n| + it "returns exactly #{n-1}! given #{n}" do + @factorial1 *= n - 1 + Math.gamma(n).should == @factorial1 end + end - it "returns good numerical approximation for gamma(-2.15)" do - Math.gamma(-2.15).should be_close(-2.999619, TOLERANCE) + 24.upto(30) do |n| + it "returns approximately #{n-1}! given #{n}" do + @factorial2 *= n - 1 + # compare only the first 12 places, tolerate the rest + Math.gamma(n).should be_close(@factorial2, @factorial2.to_s[12..-1].to_i) end + end - it "returns good numerical approximation for gamma(0.00001)" do - Math.gamma(0.00001).should be_close(99999.422794, TOLERANCE) - end + it "returns good numerical approximation for gamma(3.2)" do + Math.gamma(3.2).should be_close(2.423965, TOLERANCE) + end - it "returns good numerical approximation for gamma(-0.00001)" do - Math.gamma(-0.00001).should be_close(-100000.577225, TOLERANCE) - end + it "returns good numerical approximation for gamma(-2.15)" do + Math.gamma(-2.15).should be_close(-2.999619, TOLERANCE) + end - ruby_version_is ""..."1.9" do - it "raises Errno::EDOM given -1" do - lambda { Math.gamma(-1) }.should raise_error(Errno::EDOM) - end - end + it "returns good numerical approximation for gamma(0.00001)" do + Math.gamma(0.00001).should be_close(99999.422794, TOLERANCE) + end - ruby_version_is "1.9" do - it "raises Math::DomainError given -1" do - lambda { Math.gamma(-1) }.should raise_error(Math::DomainError) - end - end + it "returns good numerical approximation for gamma(-0.00001)" do + Math.gamma(-0.00001).should be_close(-100000.577225, TOLERANCE) + end - # See http://redmine.ruby-lang.org/issues/show/2189 - it "returns +infinity given +infinity" do - Math.gamma(infinity_value).infinite?.should == 1 - end + it "raises Math::DomainError given -1" do + lambda { Math.gamma(-1) }.should raise_error(Math::DomainError) + end - ruby_version_is ""..."1.9" do - it "raises Errno::EDOM given negative infinity" do - lambda { Math.gamma(-infinity_value) }.should raise_error(Errno::EDOM) - end - end + # See http://redmine.ruby-lang.org/issues/show/2189 + it "returns +infinity given +infinity" do + Math.gamma(infinity_value).infinite?.should == 1 + end - it "raises Math::DomainError given negative infinity" do - lambda { Math.gamma(-Float::INFINITY) }.should raise_error(Math::DomainError) - end + it "raises Math::DomainError given negative infinity" do + lambda { Math.gamma(-Float::INFINITY) }.should raise_error(Math::DomainError) + end - it "returns NaN given NaN" do - Math.gamma(nan_value).nan?.should be_true - end + it "returns NaN given NaN" do + Math.gamma(nan_value).nan?.should be_true end end diff --git a/spec/ruby/core/math/hypot_spec.rb b/spec/ruby/core/math/hypot_spec.rb index 478b69f236..8a0832bf48 100644 --- a/spec/ruby/core/math/hypot_spec.rb +++ b/spec/ruby/core/math/hypot_spec.rb @@ -15,16 +15,8 @@ Math.hypot(2, 10).should be_close(10.1980390271856, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.hypot("test", "this") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.hypot("test", "this") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.hypot("test", "this") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/ldexp_spec.rb b/spec/ruby/core/math/ldexp_spec.rb index 1e28e8e31e..360f5c5e2a 100644 --- a/spec/ruby/core/math/ldexp_spec.rb +++ b/spec/ruby/core/math/ldexp_spec.rb @@ -14,22 +14,14 @@ Math.ldexp(5.7, 4).should be_close(91.2, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the first argument cannot be coerced with Float()" do - lambda { Math.ldexp("test", 2) }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the first argument cannot be coerced with Float()" do - lambda { Math.ldexp("test", 2) }.should raise_error(TypeError) - end + it "raises a TypeError if the first argument cannot be coerced with Float()" do + lambda { Math.ldexp("test", 2) }.should raise_error(TypeError) end it "returns NaN given NaN" do Math.ldexp(nan_value, 0).nan?.should be_true end - + it "raises RangeError if NaN is given as the second arg" do lambda { Math.ldexp(0, nan_value) }.should raise_error(RangeError) end diff --git a/spec/ruby/core/math/lgamma_spec.rb b/spec/ruby/core/math/lgamma_spec.rb index 1734abdaad..5f8422c3b6 100644 --- a/spec/ruby/core/math/lgamma_spec.rb +++ b/spec/ruby/core/math/lgamma_spec.rb @@ -1,85 +1,48 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Math.lgamma" do - it "returns [Infinity, 1] when passed 0" do - Math.lgamma(0).should == [infinity_value, 1] - end - - it "returns [Infinity, 1] when passed -1" do - Math.lgamma(-1).should == [infinity_value, 1] - end - - it "returns [log(sqrt(PI)), 1] when passed 0.5" do - lg1 = Math.lgamma(0.5) - lg1[0].should be_close(Math.log(Math.sqrt(Math::PI)), TOLERANCE) - lg1[1].should == 1 - end - - it "returns [log(2/3*PI, 1] when passed 6.0" do - lg2 = Math.lgamma(6.0) - lg2[0].should be_close(Math.log(120.0), TOLERANCE) - lg2[1].should == 1 - end +describe "Math.lgamma" do + it "returns [Infinity, 1] when passed 0" do + Math.lgamma(0).should == [infinity_value, 1] + end - it "returns an approximate value when passed -0.5" do - lg1 = Math.lgamma(-0.5) - lg1[0].should be_close(1.2655121, TOLERANCE) - lg1[1].should == -1 - end + it "returns [Infinity, 1] when passed -1" do + Math.lgamma(-1).should == [infinity_value, 1] + end - it "returns an approximate value when passed -1.5" do - lg2 = Math.lgamma(-1.5) - lg2[0].should be_close(0.8600470, TOLERANCE) - lg2[1].should == 1 - end + it "returns [log(sqrt(PI)), 1] when passed 0.5" do + lg1 = Math.lgamma(0.5) + lg1[0].should be_close(Math.log(Math.sqrt(Math::PI)), TOLERANCE) + lg1[1].should == 1 + end - ruby_version_is ""..."1.9" do - it "returns [Infinity, 1] when passed -Infinity" do - Math.lgamma(-infinity_value).should == [infinity_value, 1] - end - end + it "returns [log(2/3*PI, 1] when passed 6.0" do + lg2 = Math.lgamma(6.0) + lg2[0].should be_close(Math.log(120.0), TOLERANCE) + lg2[1].should == 1 + end - ruby_version_is "1.9" do - it "raises Math::DomainError when passed -Infinity" do - lambda { Math.lgamma(-infinity_value) }.should raise_error(Math::DomainError) - end - end + it "returns an approximate value when passed -0.5" do + lg1 = Math.lgamma(-0.5) + lg1[0].should be_close(1.2655121, TOLERANCE) + lg1[1].should == -1 + end - # Note: see related issue http://redmine.ruby-lang.org/issues/show/2189 - # If you would like to see simpler Ruby behavior, lobby for Ruby to - # have platform-independent Math functions. - ruby_version_is ""..."1.9" do - platform_is_not :darwin do - it "returns [Infinity, 1] when passed Infinity" do - Math.lgamma(-infinity_value).should == [infinity_value, 1] - end - end - end + it "returns an approximate value when passed -1.5" do + lg2 = Math.lgamma(-1.5) + lg2[0].should be_close(0.8600470, TOLERANCE) + lg2[1].should == 1 + end - # Note: see related issue http://redmine.ruby-lang.org/issues/show/2189 - # If you would like to see simpler Ruby behavior, lobby for Ruby to - # have platform-independent Math functions. - ruby_version_is ""..."1.9" do - platform_is :darwin do - # JRuby has platform-independent math and behaves as above - not_compliant_on :jruby do - it "raises an Errno::EDOM when passed Infinity" do - lambda { Math.lgamma(infinity_value) }.should raise_error(Errno::EDOM) - end - end - end - end + it "raises Math::DomainError when passed -Infinity" do + lambda { Math.lgamma(-infinity_value) }.should raise_error(Math::DomainError) + end - ruby_version_is "1.9" do - it "returns [Infinity, 1] when passed Infinity" do - Math.lgamma(infinity_value).should == [infinity_value, 1] - end - end + it "returns [Infinity, 1] when passed Infinity" do + Math.lgamma(infinity_value).should == [infinity_value, 1] + end - it "returns [NaN, 1] when passed NaN" do - Math.lgamma(nan_value)[0].nan?.should be_true - Math.lgamma(nan_value)[1].should == 1 - end + it "returns [NaN, 1] when passed NaN" do + Math.lgamma(nan_value)[0].nan?.should be_true + Math.lgamma(nan_value)[1].should == 1 end end diff --git a/spec/ruby/core/math/log10_spec.rb b/spec/ruby/core/math/log10_spec.rb index 0b1ad78673..8164b9994d 100644 --- a/spec/ruby/core/math/log10_spec.rb +++ b/spec/ruby/core/math/log10_spec.rb @@ -21,24 +21,12 @@ end end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.log10("test") }.should raise_error(ArgumentError) - end - - it "raises an Errno::EDOM given NaN" do - lambda { Math.asin(nan_value) }.should raise_error( Errno::EDOM) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.log10("test") }.should raise_error(TypeError) end - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.log10("test") }.should raise_error(TypeError) - end - - it "returns NaN given NaN" do - Math.log10(nan_value).nan?.should be_true - end + it "returns NaN given NaN" do + Math.log10(nan_value).nan?.should be_true end it "raises a TypeError if the argument is nil" do diff --git a/spec/ruby/core/math/log2_spec.rb b/spec/ruby/core/math/log2_spec.rb index a6ccb0afe7..af9314b1ae 100644 --- a/spec/ruby/core/math/log2_spec.rb +++ b/spec/ruby/core/math/log2_spec.rb @@ -1,70 +1,37 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -extended_on :rubinius do - ruby_version_is "1.8"..."1.9" do - describe "Math.log2" do - it "returns a float" do - Math.log2(5.79).should be_close(2.53356334821451, TOLERANCE) - end - - it "returns the natural logarithm of the argument" do - Math.log2(1.1).should be_close(0.137503523749935, TOLERANCE) - Math.log2(3.14).should be_close(1.6507645591169, TOLERANCE) - end - - it "raises an Errno::EDOM if the argument is less than 0" do - lambda { Math.log2(-1e-15) }.should raise_error( Errno::EDOM) - end - - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.log2("test") }.should raise_error(ArgumentError) - end - - it "raises a TypeError if the argument is nil" do - lambda { Math.log2(nil) }.should raise_error(TypeError) - end - - it "accepts any argument that can be coerced with Float()" do - Math.log2(MathSpecs::Float.new).should be_close(0.0, TOLERANCE) - end - end +describe "Math.log2" do + it "returns a float" do + Math.log2(5.79).should be_close(2.53356334821451, TOLERANCE) end -end - -ruby_version_is "1.9" do - describe "Math.log2" do - it "returns a float" do - Math.log2(5.79).should be_close(2.53356334821451, TOLERANCE) - end - it "returns the natural logarithm of the argument" do - Math.log2(1.1).should be_close(0.137503523749935, TOLERANCE) - Math.log2(3.14).should be_close(1.6507645591169, TOLERANCE) - end + it "returns the natural logarithm of the argument" do + Math.log2(1.1).should be_close(0.137503523749935, TOLERANCE) + Math.log2(3.14).should be_close(1.6507645591169, TOLERANCE) + end - it "raises an Errno::EDOM if the argument is less than 0" do - lambda { Math.log2(-1e-15) }.should raise_error( Math::DomainError) - end + it "raises an Errno::EDOM if the argument is less than 0" do + lambda { Math.log2(-1e-15) }.should raise_error( Math::DomainError) + end - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.log2("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.log2("test") }.should raise_error(TypeError) + end - it "raises a TypeError if passed a numerical argument as a string" do - lambda { Math.log2("1.0") }.should raise_error(TypeError) - end + it "raises a TypeError if passed a numerical argument as a string" do + lambda { Math.log2("1.0") }.should raise_error(TypeError) + end - it "returns NaN given NaN" do - Math.log2(nan_value).nan?.should be_true - end + it "returns NaN given NaN" do + Math.log2(nan_value).nan?.should be_true + end - it "raises a TypeError if the argument is nil" do - lambda { Math.log2(nil) }.should raise_error(TypeError) - end + it "raises a TypeError if the argument is nil" do + lambda { Math.log2(nil) }.should raise_error(TypeError) + end - it "accepts any argument that can be coerced with Float()" do - Math.log2(MathSpecs::Float.new).should be_close(0.0, TOLERANCE) - end + it "accepts any argument that can be coerced with Float()" do + Math.log2(MathSpecs::Float.new).should be_close(0.0, TOLERANCE) end end diff --git a/spec/ruby/core/math/log_spec.rb b/spec/ruby/core/math/log_spec.rb index d54b6777c5..9bcccb55e2 100644 --- a/spec/ruby/core/math/log_spec.rb +++ b/spec/ruby/core/math/log_spec.rb @@ -21,43 +21,26 @@ end end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.log("test") }.should raise_error(ArgumentError) - end - - it "accepts numerical values as string" do - Math.log("10").should be_close( 2.30258509299405, TOLERANCE) - Math.log("10e15").should be_close(36.8413614879047, TOLERANCE) - end - - it "raises Errno::EDOM given NaN" do - lambda { Math.log(nan_value) }.should raise_error(Errno::EDOM) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.log("test") }.should raise_error(TypeError) end - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.log("test") }.should raise_error(TypeError) - end - - it "raises a TypeError for numerical values passed as string" do - lambda { Math.log("10") }.should raise_error(TypeError) - end + it "raises a TypeError for numerical values passed as string" do + lambda { Math.log("10") }.should raise_error(TypeError) + end - it "accepts a second argument for the base" do - Math.log(9, 3).should be_close(2, TOLERANCE) - Math.log(8, 1.4142135623730951).should be_close(6, TOLERANCE) - end + it "accepts a second argument for the base" do + Math.log(9, 3).should be_close(2, TOLERANCE) + Math.log(8, 1.4142135623730951).should be_close(6, TOLERANCE) + end - it "raises a TypeError when the numerical base cannot be coerced to a float" do - lambda { Math.log(10, "2") }.should raise_error(TypeError) - lambda { Math.log(10, nil) }.should raise_error(TypeError) - end + it "raises a TypeError when the numerical base cannot be coerced to a float" do + lambda { Math.log(10, "2") }.should raise_error(TypeError) + lambda { Math.log(10, nil) }.should raise_error(TypeError) + end - it "returns NaN given NaN" do - Math.log(nan_value).nan?.should be_true - end + it "returns NaN given NaN" do + Math.log(nan_value).nan?.should be_true end it "raises a TypeError if the argument is nil" do diff --git a/spec/ruby/core/math/sin_spec.rb b/spec/ruby/core/math/sin_spec.rb index 926d535d85..d8f134e609 100644 --- a/spec/ruby/core/math/sin_spec.rb +++ b/spec/ruby/core/math/sin_spec.rb @@ -15,16 +15,8 @@ Math.sin(2*Math::PI).should be_close(0.0, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.sin("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.sin("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.sin("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/sinh_spec.rb b/spec/ruby/core/math/sinh_spec.rb index 6d7ba7e3c0..daa7d30733 100644 --- a/spec/ruby/core/math/sinh_spec.rb +++ b/spec/ruby/core/math/sinh_spec.rb @@ -13,16 +13,8 @@ Math.sinh(-2.8).should be_close(-8.19191835423591, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.sinh("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.sinh("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.sinh("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/sqrt_spec.rb b/spec/ruby/core/math/sqrt_spec.rb index 8ca05f224b..03891b951a 100644 --- a/spec/ruby/core/math/sqrt_spec.rb +++ b/spec/ruby/core/math/sqrt_spec.rb @@ -12,20 +12,12 @@ Math.sqrt(15241578780673814.441547445).should be_close(123456789.123457, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.sqrt("test") }.should raise_error(ArgumentError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.sqrt("test") }.should raise_error(TypeError) end - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.sqrt("test") }.should raise_error(TypeError) - end - - it "returns NaN given NaN" do - Math.sqrt(nan_value).nan?.should be_true - end + it "returns NaN given NaN" do + Math.sqrt(nan_value).nan?.should be_true end it "raises a TypeError if the argument is nil" do diff --git a/spec/ruby/core/math/tan_spec.rb b/spec/ruby/core/math/tan_spec.rb index 8f0a0ed407..0318ef8a14 100644 --- a/spec/ruby/core/math/tan_spec.rb +++ b/spec/ruby/core/math/tan_spec.rb @@ -18,16 +18,8 @@ Math.tan(-infinity_value).nan?.should == true end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.tan("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.tan("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.tan("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/math/tanh_spec.rb b/spec/ruby/core/math/tanh_spec.rb index 1cd6aad6d6..8f39dc948b 100644 --- a/spec/ruby/core/math/tanh_spec.rb +++ b/spec/ruby/core/math/tanh_spec.rb @@ -15,16 +15,8 @@ Math.tanh(-4.892).should be_close(-0.999887314427707, TOLERANCE) end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if the argument cannot be coerced with Float()" do - lambda { Math.tanh("test") }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if the argument cannot be coerced with Float()" do - lambda { Math.tanh("test") }.should raise_error(TypeError) - end + it "raises a TypeError if the argument cannot be coerced with Float()" do + lambda { Math.tanh("test") }.should raise_error(TypeError) end it "returns NaN given NaN" do diff --git a/spec/ruby/core/method/arity_spec.rb b/spec/ruby/core/method/arity_spec.rb index 123455255a..18025877e6 100644 --- a/spec/ruby/core/method/arity_spec.rb +++ b/spec/ruby/core/method/arity_spec.rb @@ -55,11 +55,9 @@ @m.method(:two_req_one_opt_with_splat_and_block).arity.should == @m.method(:two_req_one_opt_with_splat).arity end - ruby_version_is "1.9" do - describe "for a Method generated by respond_to_missing?" do - it "returns -1" do - @m.method(:handled_via_method_missing).arity.should == -1 - end + describe "for a Method generated by respond_to_missing?" do + it "returns -1" do + @m.method(:handled_via_method_missing).arity.should == -1 end end end diff --git a/spec/ruby/core/method/eql_spec.rb b/spec/ruby/core/method/eql_spec.rb index a5955caaab..f8914e1d12 100644 --- a/spec/ruby/core/method/eql_spec.rb +++ b/spec/ruby/core/method/eql_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/eql', __FILE__) -ruby_version_is "1.9" do - describe "Method#eql?" do - it_behaves_like(:method_equal, :eql?) - end +describe "Method#eql?" do + it_behaves_like(:method_equal, :eql?) end diff --git a/spec/ruby/core/method/fixtures/classes.rb b/spec/ruby/core/method/fixtures/classes.rb index 86d74bcab9..9c9d665f3b 100644 --- a/spec/ruby/core/method/fixtures/classes.rb +++ b/spec/ruby/core/method/fixtures/classes.rb @@ -165,4 +165,20 @@ def to_proc method(:method_called).to_proc end end + + class Methods + def one_splat_one_req(*a,b); end + def one_splat_two_req(*a,b,c); end + def one_splat_one_req_with_block(*a,b,&blk); end + + def one_opt_with_stabby(a=->(b){true}); end + + def one_unnamed_splat(*); end + + def one_splat_one_block(*args, &block) + options = {} + end + + define_method(:one_optional_defined_method) {|x = 1|} + end end diff --git a/spec/ruby/core/method/fixtures/classes_1.9.rb b/spec/ruby/core/method/fixtures/classes_1.9.rb deleted file mode 100644 index a7279872e2..0000000000 --- a/spec/ruby/core/method/fixtures/classes_1.9.rb +++ /dev/null @@ -1,18 +0,0 @@ -module MethodSpecs - - class Methods - def one_splat_one_req(*a,b); end - def one_splat_two_req(*a,b,c); end - def one_splat_one_req_with_block(*a,b,&blk); end - - def one_opt_with_stabby(a=->(b){true}); end - - def one_unnamed_splat(*); end - - def one_splat_one_block(*args, &block) - options = {} - end - - define_method(:one_optional_defined_method) {|x = 1|} - end -end diff --git a/spec/ruby/core/method/hash_spec.rb b/spec/ruby/core/method/hash_spec.rb index d993b3458b..67bc4c16ac 100644 --- a/spec/ruby/core/method/hash_spec.rb +++ b/spec/ruby/core/method/hash_spec.rb @@ -1,19 +1,17 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "1.9" do - describe "Method#hash" do - it "needs to be reviewed for spec completeness" +describe "Method#hash" do + it "needs to be reviewed for spec completeness" - it "returns the same value for user methods that are eql?" do - obj = MethodSpecs::Methods.new - obj.method(:foo).hash.should == obj.method(:bar).hash - end + it "returns the same value for user methods that are eql?" do + obj = MethodSpecs::Methods.new + obj.method(:foo).hash.should == obj.method(:bar).hash + end - # See also redmine #6048 - it "returns the same value for builtin methods that are eql?" do - obj = [42] - obj.method(:to_s).hash.should == obj.method(:inspect).hash - end + # See also redmine #6048 + it "returns the same value for builtin methods that are eql?" do + obj = [42] + obj.method(:to_s).hash.should == obj.method(:inspect).hash end end diff --git a/spec/ruby/core/method/name_spec.rb b/spec/ruby/core/method/name_spec.rb index c4b5f8d3dc..ebc5f856d1 100644 --- a/spec/ruby/core/method/name_spec.rb +++ b/spec/ruby/core/method/name_spec.rb @@ -2,36 +2,21 @@ require File.expand_path('../fixtures/classes', __FILE__) describe "Method#name" do - ruby_version_is '1.8.7'..'1.9' do - it "returns the name of the method" do - "abc".method(:upcase).name.should == "upcase" - end - - it "returns the name even when aliased" do - obj = MethodSpecs::Methods.new - obj.method(:foo).name.should == "foo" - obj.method(:bar).name.should == "bar" - obj.method(:bar).unbind.bind(obj).name.should == "bar" - end + it "returns the name of the method" do + "abc".method(:upcase).name.should == :upcase end - ruby_version_is '1.9' do - it "returns the name of the method" do - "abc".method(:upcase).name.should == :upcase - end - - it "returns the name even when aliased" do - obj = MethodSpecs::Methods.new - obj.method(:foo).name.should == :foo - obj.method(:bar).name.should == :bar - obj.method(:bar).unbind.bind(obj).name.should == :bar - end + it "returns the name even when aliased" do + obj = MethodSpecs::Methods.new + obj.method(:foo).name.should == :foo + obj.method(:bar).name.should == :bar + obj.method(:bar).unbind.bind(obj).name.should == :bar + end - describe "for a Method generated by respond_to_missing?" do - it "returns the name passed to respond_to_missing?" do - @m = MethodSpecs::Methods.new - @m.method(:handled_via_method_missing).name.should == :handled_via_method_missing - end + describe "for a Method generated by respond_to_missing?" do + it "returns the name passed to respond_to_missing?" do + @m = MethodSpecs::Methods.new + @m.method(:handled_via_method_missing).name.should == :handled_via_method_missing end end end diff --git a/spec/ruby/core/method/owner_spec.rb b/spec/ruby/core/method/owner_spec.rb index 814d1397a8..73ad15fd17 100644 --- a/spec/ruby/core/method/owner_spec.rb +++ b/spec/ruby/core/method/owner_spec.rb @@ -2,29 +2,25 @@ require File.expand_path('../fixtures/classes', __FILE__) describe "Method#owner" do - ruby_version_is '1.8.7' do - it "returns the owner of the method" do - "abc".method(:upcase).owner.should == String - end + it "returns the owner of the method" do + "abc".method(:upcase).owner.should == String + end - it "returns the name even when aliased" do - obj = MethodSpecs::Methods.new - obj.method(:foo).owner.should == MethodSpecs::Methods - obj.method(:bar).owner.should == MethodSpecs::Methods - end + it "returns the name even when aliased" do + obj = MethodSpecs::Methods.new + obj.method(:foo).owner.should == MethodSpecs::Methods + obj.method(:bar).owner.should == MethodSpecs::Methods + end - it "returns the class/module it was defined in" do - MethodSpecs::C.new.method(:baz).owner.should == MethodSpecs::A - MethodSpecs::MySuper.new.method(:bar).owner.should == MethodSpecs::MyMod - end + it "returns the class/module it was defined in" do + MethodSpecs::C.new.method(:baz).owner.should == MethodSpecs::A + MethodSpecs::MySuper.new.method(:bar).owner.should == MethodSpecs::MyMod + end - ruby_version_is "1.9" do - describe "for a Method generated by respond_to_missing?" do - it "returns the owner of the method" do - @m = MethodSpecs::Methods.new - @m.method(:handled_via_method_missing).owner.should == MethodSpecs::Methods - end - end + describe "for a Method generated by respond_to_missing?" do + it "returns the owner of the method" do + @m = MethodSpecs::Methods.new + @m.method(:handled_via_method_missing).owner.should == MethodSpecs::Methods end end end diff --git a/spec/ruby/core/method/parameters_spec.rb b/spec/ruby/core/method/parameters_spec.rb index f678df9611..3fa6c2728e 100644 --- a/spec/ruby/core/method/parameters_spec.rb +++ b/spec/ruby/core/method/parameters_spec.rb @@ -1,5 +1,200 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "1.9" do - require File.expand_path("../versions/parameters_1.9", __FILE__) +describe "Method#parameters" do + it "returns an empty Array when the method expects no arguments" do + MethodSpecs::Methods.instance_method(:zero).parameters.should == [] + end + + it "returns [[:req,:name]] for a method expecting one required argument called 'name'" do + MethodSpecs::Methods.instance_method(:one_req).parameters.should == [[:req,:a]] + end + + it "returns [[:req,:a],[:req,:b]] for a method expecting two required arguments called 'a' and 'b''" do + m = MethodSpecs::Methods.instance_method(:two_req) + m.parameters.should == [[:req,:a], [:req,:b]] + end + + it "returns [[:block,:blk]] for a method expecting one block argument called 'a'" do + m = MethodSpecs::Methods.instance_method(:zero_with_block) + m.parameters.should == [[:block,:blk]] + end + + it "returns [[:req,:a],[:block,:b] for a method expecting a required argument ('a') and a block argument ('b')" do + m = MethodSpecs::Methods.instance_method(:one_req_with_block) + m.parameters.should == [[:req,:a], [:block,:blk]] + end + + it "returns [[:req,:a],[:req,:b],[:block,:c] for a method expecting two required arguments ('a','b') and a block argument ('c')" do + m = MethodSpecs::Methods.instance_method(:two_req_with_block) + m.parameters.should == [[:req,:a], [:req,:b], [:block,:blk]] + end + + it "returns [[:opt,:a]] for a method expecting one optional argument ('a')" do + m = MethodSpecs::Methods.instance_method(:one_opt) + m.parameters.should == [[:opt,:a]] + end + + it "returns [[:req,:a],[:opt,:b]] for a method expecting one required argument ('a') and one optional argument ('b')" do + m = MethodSpecs::Methods.instance_method(:one_req_one_opt) + m.parameters.should == [[:req,:a],[:opt,:b]] + end + + it "returns [[:req,:a],[:opt,:b]] for a method expecting one required argument ('a') and one optional argument ('b')" do + m = MethodSpecs::Methods.instance_method(:one_req_one_opt) + m.parameters.should == [[:req,:a],[:opt,:b]] + end + + it "returns [[:req,:a],[:opt,:b],[:opt,:c]] for a method expecting one required argument ('a') and two optional arguments ('b','c')" do + m = MethodSpecs::Methods.instance_method(:one_req_two_opt) + m.parameters.should == [[:req,:a],[:opt,:b],[:opt,:c]] + end + + it "returns [[:req,:a],[:req,:b],[:opt,:c]] for a method expecting two required arguments ('a','b') and one optional arguments ('c')" do + m = MethodSpecs::Methods.instance_method(:two_req_one_opt) + m.parameters.should == [[:req,:a],[:req,:b],[:opt,:c]] + end + + it "returns [[:opt,:a],[:block,:b]] for a method expecting one required argument ('a') and one block argument ('b')" do + m = MethodSpecs::Methods.instance_method(:one_opt_with_block) + m.parameters.should == [[:opt,:a],[:block,:blk]] + end + + it "returns [[:req,:a],[:opt,:b],[:block,:c]] for a method expecting one required argument ('a'), one optional argument ('b'), and a block ('c')" do + m = MethodSpecs::Methods.instance_method(:one_req_one_opt_with_block) + m.parameters.should == [[:req,:a],[:opt,:b],[:block,:blk]] + end + + it "returns [[:req,:a],[:opt,:b],[:opt,:c],[:block,:d]] for a method expecting one required argument ('a'), two optional arguments ('b','c'), and a block ('d')" do + m = MethodSpecs::Methods.instance_method(:one_req_two_opt_with_block) + m.parameters.should == [[:req,:a],[:opt,:b],[:opt,:c],[:block,:blk]] + end + + it "returns [[:rest,:a]] for a method expecting a single splat argument ('a')" do + m = MethodSpecs::Methods.instance_method(:zero_with_splat) + m.parameters.should == [[:rest,:a]] + end + + it "returns [[:req,:a],[:rest,:b]] for a method expecting a splat argument ('a') and a required argument ('b')" do + m = MethodSpecs::Methods.instance_method(:one_req_with_splat) + m.parameters.should == [[:req,:a],[:rest,:b]] + end + + it "returns [[:req,:a],[:req,:b],[:rest,:c]] for a method expecting two required arguments ('a','b') and a splat argument ('c')" do + m = MethodSpecs::Methods.instance_method(:two_req_with_splat) + m.parameters.should == [[:req,:a],[:req,:b],[:rest,:c]] + end + + it "returns [[:req,:a],[:opt,:b],[:rest,:c]] for a method expecting a required argument ('a','b'), an optional argument ('b'), and a splat argument ('c')" do + m = MethodSpecs::Methods.instance_method(:one_req_one_opt_with_splat) + m.parameters.should == [[:req,:a],[:opt,:b],[:rest,:c]] + end + + it "returns [[:req,:a],[:req,:b],[:opt,:b],[:rest,:d]] for a method expecting two required arguments ('a','b'), an optional argument ('c'), and a splat argument ('d')" do + m = MethodSpecs::Methods.instance_method(:two_req_one_opt_with_splat) + m.parameters.should == [[:req,:a],[:req,:b],[:opt,:c],[:rest,:d]] + end + + it "returns [[:req,:a],[:opt,:b],[:opt,:c],[:rest,:d]] for a method expecting a required argument ('a'), two optional arguments ('b','c'), and a splat argument ('d')" do + m = MethodSpecs::Methods.instance_method(:one_req_two_opt_with_splat) + m.parameters.should == [[:req,:a],[:opt,:b],[:opt,:c],[:rest,:d]] + end + + it "returns [[:rest,:a],[:block,:b]] for a method expecting a splat argument ('a') and a block argument ('b')" do + m = MethodSpecs::Methods.instance_method(:zero_with_splat_and_block) + m.parameters.should == [[:rest,:a],[:block,:blk]] + end + + it "returns [[:req,:a],[:rest,:b],[:block,:c]] for a method expecting a required argument ('a'), a splat argument ('b'), and a block ('c')" do + m = MethodSpecs::Methods.instance_method(:one_req_with_splat_and_block) + m.parameters.should == [[:req,:a],[:rest,:b],[:block,:blk]] + end + + it "returns [[:req,:a],[:req,:b],[:rest,:c],[:block,:d]] for a method expecting two required arguments ('a','b'), a splat argument ('c'), and a block ('d')" do + m = MethodSpecs::Methods.instance_method(:two_req_with_splat_and_block) + m.parameters.should == [[:req,:a],[:req,:b],[:rest,:c],[:block,:blk]] + end + + it "returns [[:req,:a],[:opt,:b],[:rest,:c],[:block,:d]] for a method expecting a required argument ('a'), a splat argument ('c'), and a block ('d')" do + m = MethodSpecs::Methods.instance_method(:one_req_one_opt_with_splat_and_block) + m.parameters.should == [[:req,:a],[:opt,:b],[:rest,:c],[:block,:blk]] + end + + it "returns [[:req,:a],[:req,:b],[:opt,:c],[:block,:d]] for a method expecting two required arguments ('a','b'), an optional argument ('c'), a splat argument ('d'), and a block ('e')" do + m = MethodSpecs::Methods.instance_method(:two_req_one_opt_with_splat_and_block) + m.parameters.should == [[:req,:a],[:req,:b],[:opt,:c],[:rest,:d],[:block,:blk]] + end + + # 1.9 semantics + # + it "returns [[:rest,:a],[:req,:b]] for a method expecting a splat argument ('a') and a required argument ('b')" do + m = MethodSpecs::Methods.instance_method(:one_splat_one_req) + m.parameters.should == [[:rest,:a],[:req,:b]] + end + + it "returns [[:rest,:a],[:req,:b],[:req,:c]] for a method expecting a splat argument ('a') and two required arguments ('b','c')" do + m = MethodSpecs::Methods.instance_method(:one_splat_two_req) + m.parameters.should == [[:rest,:a],[:req,:b],[:req,:c]] + end + + it "returns [[:rest,:a],[:req,:b],[:block,:c]] for a method expecting a splat argument ('a'), a required argument ('b'), and a block ('c')" do + m = MethodSpecs::Methods.instance_method(:one_splat_one_req_with_block) + m.parameters.should == [[:rest,:a],[:req,:b],[:block,:blk]] + end + + it "works with ->(){} as the value of an optional argument" do + m = MethodSpecs::Methods.instance_method(:one_opt_with_stabby) + m.parameters.should == [[:opt,:a]] + end + + # define_method variants + it "returns [] for a define_method method with explicit no-args || specification" do + m = MethodSpecs::Methods.instance_method(:zero_defined_method) + m.parameters.should == [] + end + + it "returns [[:rest, :x]] for a define_method method with rest arg 'x' only" do + m = MethodSpecs::Methods.instance_method(:zero_with_splat_defined_method) + m.parameters.should == [[:rest, :x]] + end + + it "returns [[:req, :x]] for a define_method method expecting one required argument 'x'" do + m = MethodSpecs::Methods.instance_method(:one_req_defined_method) + m.parameters.should == [[:req, :x]] + end + + it "returns [[:req, :x], [:req, :y]] for a define_method method expecting two required arguments 'x' and 'y'" do + m = MethodSpecs::Methods.instance_method(:two_req_defined_method) + m.parameters.should == [[:req, :x], [:req, :y]] + end + + it "returns [] for a define_method method with no args specification" do + m = MethodSpecs::Methods.instance_method(:no_args_defined_method) + m.parameters.should == [] + end + + it "returns [[:req]] for a define_method method with a grouping as its only argument" do + m = MethodSpecs::Methods.instance_method(:two_grouped_defined_method) + m.parameters.should == [[:req]] + end + + it "returns [[:opt, :x]] for a define_method method with an optional argument 'x'" do + m = MethodSpecs::Methods.instance_method(:one_optional_defined_method) + m.parameters.should == [[:opt, :x]] + end + + it "returns [[:rest]] for a Method generated by respond_to_missing?" do + m = MethodSpecs::Methods.new + m.method(:handled_via_method_missing).parameters.should == [[:rest]] + end + + it "adds nameless rest arg for \"star\" argument" do + m = MethodSpecs::Methods.new + m.method(:one_unnamed_splat).parameters.should == [[:rest]] + end + + it "returns the args and block for a splat and block argument" do + m = MethodSpecs::Methods.new + m.method(:one_splat_one_block).parameters.should == [[:rest, :args], [:block, :block]] + end end diff --git a/spec/ruby/core/method/receiver_spec.rb b/spec/ruby/core/method/receiver_spec.rb index d04d44a2e4..2c56ab2239 100644 --- a/spec/ruby/core/method/receiver_spec.rb +++ b/spec/ruby/core/method/receiver_spec.rb @@ -2,25 +2,21 @@ require File.expand_path('../fixtures/classes', __FILE__) describe "Method#receiver" do - ruby_version_is '1.8.7' do - it "returns the receiver of the method" do - s = "abc" - s.method(:upcase).receiver.should equal(s) - end + it "returns the receiver of the method" do + s = "abc" + s.method(:upcase).receiver.should equal(s) + end - it "returns the right receiver even when aliased" do - obj = MethodSpecs::Methods.new - obj.method(:foo).receiver.should equal(obj) - obj.method(:bar).receiver.should equal(obj) - end + it "returns the right receiver even when aliased" do + obj = MethodSpecs::Methods.new + obj.method(:foo).receiver.should equal(obj) + obj.method(:bar).receiver.should equal(obj) end - ruby_version_is "1.9" do - describe "for a Method generated by respond_to_missing?" do - it "returns the receiver of the method" do - m = MethodSpecs::Methods.new - m.method(:handled_via_method_missing).receiver.should equal(m) - end + describe "for a Method generated by respond_to_missing?" do + it "returns the receiver of the method" do + m = MethodSpecs::Methods.new + m.method(:handled_via_method_missing).receiver.should equal(m) end end end diff --git a/spec/ruby/core/method/shared/call.rb b/spec/ruby/core/method/shared/call.rb index aae72a835a..047d24c8cb 100644 --- a/spec/ruby/core/method/shared/call.rb +++ b/spec/ruby/core/method/shared/call.rb @@ -17,12 +17,10 @@ }.should raise_error(ArgumentError) end - ruby_version_is "1.9" do - describe "for a Method generated by respond_to_missing?" do - it "invokes method_missing with the specified arguments and returns the result" do - @m = MethodSpecs::Methods.new - @m.method(:handled_via_method_missing).send(@method, :argument).should == [:argument] - end + describe "for a Method generated by respond_to_missing?" do + it "invokes method_missing with the specified arguments and returns the result" do + @m = MethodSpecs::Methods.new + @m.method(:handled_via_method_missing).send(@method, :argument).should == [:argument] end end end diff --git a/spec/ruby/core/method/shared/eql.rb b/spec/ruby/core/method/shared/eql.rb index 5587804845..1adab2decf 100644 --- a/spec/ruby/core/method/shared/eql.rb +++ b/spec/ruby/core/method/shared/eql.rb @@ -22,13 +22,11 @@ m_bar.send(@method, @m_foo).should be_true end - ruby_version_is "1.9" do - it "returns true if the two core methods are aliases" do - s = "hello" - a = s.method(:size) - b = s.method(:length) - a.send(@method, b).should be_true - end + it "returns true if the two core methods are aliases" do + s = "hello" + a = s.method(:size) + b = s.method(:length) + a.send(@method, b).should be_true end it "returns false on a method which is neither aliased nor the same method" do @@ -50,68 +48,25 @@ @m_foo.send(@method, m2).should be_false end - ruby_version_is "1.9" do - it "returns true if a method was defined using the other one" do - MethodSpecs::Methods.send :define_method, :defined_foo, MethodSpecs::Methods.instance_method(:foo) - m2 = @m.method(:defined_foo) - @m_foo.send(@method, m2).should be_true - end - - ruby_version_is ""..."2.0" do - it "returns true for methods defined using the same block/proc" do - class MethodSpecs::Methods - p = Proc.new { :cool } - define_method :proc1, p - define_method :proc2, p - - define_method :block1, &p - define_method :block2, &p - end - proc1 = @m.method :proc1 - proc2 = @m.method :proc2 - block1 = @m.method :proc1 - block2 = @m.method :proc2 - - proc1.send(@method, proc2).should be_true - block1.send(@method, block2).should be_true - proc1.send(@method, block1).should be_true - end - - it "returns true for methods defined using equivalent blocks" do - class MethodSpecs::Methods - p1 = Proc.new { :cool } - p2 = Proc.new { :cool } - define_method :proc1, p1 - define_method :proc2, p2 - - define_method :block1, &p1 - define_method :block2, &p2 - end - proc1 = @m.method :proc1 - proc2 = @m.method :proc2 - block1 = @m.method :proc1 - block2 = @m.method :proc2 - - proc1.send(@method, proc2).should be_true - block1.send(@method, block2).should be_true - proc1.send(@method, block1).should be_true - end - end + it "returns true if a method was defined using the other one" do + MethodSpecs::Methods.send :define_method, :defined_foo, MethodSpecs::Methods.instance_method(:foo) + m2 = @m.method(:defined_foo) + @m_foo.send(@method, m2).should be_true + end - describe 'missing methods' do - it "returns true for the same method missing" do - miss1 = @m.method(:handled_via_method_missing) - miss1bis = @m.method(:handled_via_method_missing) - miss2 = @m.method(:also_handled) + describe 'missing methods' do + it "returns true for the same method missing" do + miss1 = @m.method(:handled_via_method_missing) + miss1bis = @m.method(:handled_via_method_missing) + miss2 = @m.method(:also_handled) - miss1.send(@method, miss1bis).should be_true - miss1.send(@method, miss2).should be_false - end + miss1.send(@method, miss1bis).should be_true + miss1.send(@method, miss2).should be_false + end - it 'calls respond_to_missing? with true to include private methods' do - @m.should_receive(:respond_to_missing?).with(:some_missing_method, true).and_return(true) - @m.method(:some_missing_method) - end + it 'calls respond_to_missing? with true to include private methods' do + @m.should_receive(:respond_to_missing?).with(:some_missing_method, true).and_return(true) + @m.method(:some_missing_method) end end diff --git a/spec/ruby/core/method/source_location_spec.rb b/spec/ruby/core/method/source_location_spec.rb index 11dcfe858e..0c74e6ec02 100644 --- a/spec/ruby/core/method/source_location_spec.rb +++ b/spec/ruby/core/method/source_location_spec.rb @@ -1,101 +1,99 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "1.9" do - describe "Method#source_location" do - before(:each) do - @method = MethodSpecs::SourceLocation.method(:location) - end - - it "returns nil for built-in methods" do - [].method(:size).source_location.should be_nil - end +describe "Method#source_location" do + before(:each) do + @method = MethodSpecs::SourceLocation.method(:location) + end - it "returns an Array" do - @method.source_location.should be_an_instance_of(Array) - end + it "returns nil for built-in methods" do + [].method(:size).source_location.should be_nil + end - it "sets the first value to the path of the file in which the method was defined" do - file = @method.source_location.first - file.should be_an_instance_of(String) - file.should == File.dirname(__FILE__) + '/fixtures/classes.rb' - end + it "returns an Array" do + @method.source_location.should be_an_instance_of(Array) + end - it "sets the last value to a Fixnum representing the line on which the method was defined" do - line = @method.source_location.last - line.should be_an_instance_of(Fixnum) - line.should == 5 - end + it "sets the first value to the path of the file in which the method was defined" do + file = @method.source_location.first + file.should be_an_instance_of(String) + file.should == File.dirname(__FILE__) + '/fixtures/classes.rb' + end - it "returns the last place the method was defined" do - MethodSpecs::SourceLocation.method(:redefined).source_location.last.should == 13 - end + it "sets the last value to a Fixnum representing the line on which the method was defined" do + line = @method.source_location.last + line.should be_an_instance_of(Fixnum) + line.should == 5 + end - it "returns the location of the original method even if it was aliased" do - MethodSpecs::SourceLocation.new.method(:aka).source_location.last.should == 17 - end + it "returns the last place the method was defined" do + MethodSpecs::SourceLocation.method(:redefined).source_location.last.should == 13 + end - it "works for methods defined with a block" do - line = nil - klass = Class.new do - line = __LINE__ + 1 - define_method(:f) { } - end + it "returns the location of the original method even if it was aliased" do + MethodSpecs::SourceLocation.new.method(:aka).source_location.last.should == 17 + end - method = klass.new.method(:f) - method.source_location[0].should =~ /#{__FILE__}/ - method.source_location[1].should == line + it "works for methods defined with a block" do + line = nil + klass = Class.new do + line = __LINE__ + 1 + define_method(:f) { } end - it "works for methods defined with a Method" do - line = nil - klass = Class.new do - line = __LINE__ + 1 - def f - end - define_method :g, new.method(:f) - end + method = klass.new.method(:f) + method.source_location[0].should =~ /#{__FILE__}/ + method.source_location[1].should == line + end - method = klass.new.method(:g) - method.source_location[0].should =~ /#{__FILE__}/ - method.source_location[1].should == line + it "works for methods defined with a Method" do + line = nil + klass = Class.new do + line = __LINE__ + 1 + def f + end + define_method :g, new.method(:f) end - it "works for methods defined with an UnboundMethod" do - line = nil - klass = Class.new do - line = __LINE__ + 1 - def f - end - define_method :g, instance_method(:f) - end + method = klass.new.method(:g) + method.source_location[0].should =~ /#{__FILE__}/ + method.source_location[1].should == line + end - method = klass.new.method(:g) - method.source_location[0].should =~ /#{__FILE__}/ - method.source_location[1].should == line + it "works for methods defined with an UnboundMethod" do + line = nil + klass = Class.new do + line = __LINE__ + 1 + def f + end + define_method :g, instance_method(:f) end - it "works for methods whose visibility has been overridden in a subclass" do - line = nil - superclass = Class.new do - line = __LINE__ + 1 - def f - end - end - subclass = Class.new(superclass) do - private :f - end + method = klass.new.method(:g) + method.source_location[0].should =~ /#{__FILE__}/ + method.source_location[1].should == line + end - method = subclass.new.method(:f) - method.source_location[0].should =~ /#{__FILE__}/ - method.source_location[1].should == line + it "works for methods whose visibility has been overridden in a subclass" do + line = nil + superclass = Class.new do + line = __LINE__ + 1 + def f + end + end + subclass = Class.new(superclass) do + private :f end - describe "for a Method generated by respond_to_missing?" do - it "returns nil" do - m = MethodSpecs::Methods.new - m.method(:handled_via_method_missing).source_location.should be_nil - end + method = subclass.new.method(:f) + method.source_location[0].should =~ /#{__FILE__}/ + method.source_location[1].should == line + end + + describe "for a Method generated by respond_to_missing?" do + it "returns nil" do + m = MethodSpecs::Methods.new + m.method(:handled_via_method_missing).source_location.should be_nil end end end diff --git a/spec/ruby/core/method/to_proc_spec.rb b/spec/ruby/core/method/to_proc_spec.rb index dd6c3ffb8c..8f1e542191 100644 --- a/spec/ruby/core/method/to_proc_spec.rb +++ b/spec/ruby/core/method/to_proc_spec.rb @@ -49,28 +49,16 @@ def x.baz(*a); yield(*a); end x.bar(&m).should == [] x.baz(1,2,3,&m).should == [1,2,3] end - - ruby_bug "#5926", "1.9.2" do - it "returns a proc that can receive a block" do - x = Object.new - def x.foo; yield 'bar'; end - - m = x.method :foo - result = nil - m.to_proc.call {|val| result = val} - result.should == 'bar' - end - end - - ruby_version_is ""..."1.9" do - it "returns a proc that accepts passed arguments like a block would" do - obj = MethodSpecs::ToProc.new - array = [["text", :comment], ["space", :chunk]] - array.each(&obj) + # #5926 + it "returns a proc that can receive a block" do + x = Object.new + def x.foo; yield 'bar'; end - ScratchPad.recorded.should == array = [["text", :comment], ["space", :chunk]] - end + m = x.method :foo + result = nil + m.to_proc.call {|val| result = val} + result.should == 'bar' end it "can be called directly and not unwrap arguments like a block" do @@ -86,13 +74,11 @@ def x.foo; yield 'bar'; end ScratchPad.recorded.should == [[1]] end - ruby_version_is "1.9" do - it "executes method with whole array (one argument)" do - obj = MethodSpecs::ToProcBeta.new + it "executes method with whole array (one argument)" do + obj = MethodSpecs::ToProcBeta.new - array = [[1, 2]] - array.each(&obj) - ScratchPad.recorded.should == [[1, 2]] - end + array = [[1, 2]] + array.each(&obj) + ScratchPad.recorded.should == [[1, 2]] end end diff --git a/spec/ruby/core/method/versions/parameters_1.9.rb b/spec/ruby/core/method/versions/parameters_1.9.rb deleted file mode 100644 index 9d781ef97c..0000000000 --- a/spec/ruby/core/method/versions/parameters_1.9.rb +++ /dev/null @@ -1,204 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/classes', __FILE__) -require File.expand_path('../../fixtures/classes_1.9', __FILE__) - -ruby_version_is "1.9" do - describe "Method#parameters" do - - it "returns an empty Array when the method expects no arguments" do - MethodSpecs::Methods.instance_method(:zero).parameters.should == [] - end - - it "returns [[:req,:name]] for a method expecting one required argument called 'name'" do - MethodSpecs::Methods.instance_method(:one_req).parameters.should == [[:req,:a]] - end - - it "returns [[:req,:a],[:req,:b]] for a method expecting two required arguments called 'a' and 'b''" do - m = MethodSpecs::Methods.instance_method(:two_req) - m.parameters.should == [[:req,:a], [:req,:b]] - end - - it "returns [[:block,:blk]] for a method expecting one block argument called 'a'" do - m = MethodSpecs::Methods.instance_method(:zero_with_block) - m.parameters.should == [[:block,:blk]] - end - - it "returns [[:req,:a],[:block,:b] for a method expecting a required argument ('a') and a block argument ('b')" do - m = MethodSpecs::Methods.instance_method(:one_req_with_block) - m.parameters.should == [[:req,:a], [:block,:blk]] - end - - it "returns [[:req,:a],[:req,:b],[:block,:c] for a method expecting two required arguments ('a','b') and a block argument ('c')" do - m = MethodSpecs::Methods.instance_method(:two_req_with_block) - m.parameters.should == [[:req,:a], [:req,:b], [:block,:blk]] - end - - it "returns [[:opt,:a]] for a method expecting one optional argument ('a')" do - m = MethodSpecs::Methods.instance_method(:one_opt) - m.parameters.should == [[:opt,:a]] - end - - it "returns [[:req,:a],[:opt,:b]] for a method expecting one required argument ('a') and one optional argument ('b')" do - m = MethodSpecs::Methods.instance_method(:one_req_one_opt) - m.parameters.should == [[:req,:a],[:opt,:b]] - end - - it "returns [[:req,:a],[:opt,:b]] for a method expecting one required argument ('a') and one optional argument ('b')" do - m = MethodSpecs::Methods.instance_method(:one_req_one_opt) - m.parameters.should == [[:req,:a],[:opt,:b]] - end - - it "returns [[:req,:a],[:opt,:b],[:opt,:c]] for a method expecting one required argument ('a') and two optional arguments ('b','c')" do - m = MethodSpecs::Methods.instance_method(:one_req_two_opt) - m.parameters.should == [[:req,:a],[:opt,:b],[:opt,:c]] - end - - it "returns [[:req,:a],[:req,:b],[:opt,:c]] for a method expecting two required arguments ('a','b') and one optional arguments ('c')" do - m = MethodSpecs::Methods.instance_method(:two_req_one_opt) - m.parameters.should == [[:req,:a],[:req,:b],[:opt,:c]] - end - - it "returns [[:opt,:a],[:block,:b]] for a method expecting one required argument ('a') and one block argument ('b')" do - m = MethodSpecs::Methods.instance_method(:one_opt_with_block) - m.parameters.should == [[:opt,:a],[:block,:blk]] - end - - it "returns [[:req,:a],[:opt,:b],[:block,:c]] for a method expecting one required argument ('a'), one optional argument ('b'), and a block ('c')" do - m = MethodSpecs::Methods.instance_method(:one_req_one_opt_with_block) - m.parameters.should == [[:req,:a],[:opt,:b],[:block,:blk]] - end - - it "returns [[:req,:a],[:opt,:b],[:opt,:c],[:block,:d]] for a method expecting one required argument ('a'), two optional arguments ('b','c'), and a block ('d')" do - m = MethodSpecs::Methods.instance_method(:one_req_two_opt_with_block) - m.parameters.should == [[:req,:a],[:opt,:b],[:opt,:c],[:block,:blk]] - end - - it "returns [[:rest,:a]] for a method expecting a single splat argument ('a')" do - m = MethodSpecs::Methods.instance_method(:zero_with_splat) - m.parameters.should == [[:rest,:a]] - end - - it "returns [[:req,:a],[:rest,:b]] for a method expecting a splat argument ('a') and a required argument ('b')" do - m = MethodSpecs::Methods.instance_method(:one_req_with_splat) - m.parameters.should == [[:req,:a],[:rest,:b]] - end - - it "returns [[:req,:a],[:req,:b],[:rest,:c]] for a method expecting two required arguments ('a','b') and a splat argument ('c')" do - m = MethodSpecs::Methods.instance_method(:two_req_with_splat) - m.parameters.should == [[:req,:a],[:req,:b],[:rest,:c]] - end - - it "returns [[:req,:a],[:opt,:b],[:rest,:c]] for a method expecting a required argument ('a','b'), an optional argument ('b'), and a splat argument ('c')" do - m = MethodSpecs::Methods.instance_method(:one_req_one_opt_with_splat) - m.parameters.should == [[:req,:a],[:opt,:b],[:rest,:c]] - end - - it "returns [[:req,:a],[:req,:b],[:opt,:b],[:rest,:d]] for a method expecting two required arguments ('a','b'), an optional argument ('c'), and a splat argument ('d')" do - m = MethodSpecs::Methods.instance_method(:two_req_one_opt_with_splat) - m.parameters.should == [[:req,:a],[:req,:b],[:opt,:c],[:rest,:d]] - end - - it "returns [[:req,:a],[:opt,:b],[:opt,:c],[:rest,:d]] for a method expecting a required argument ('a'), two optional arguments ('b','c'), and a splat argument ('d')" do - m = MethodSpecs::Methods.instance_method(:one_req_two_opt_with_splat) - m.parameters.should == [[:req,:a],[:opt,:b],[:opt,:c],[:rest,:d]] - end - - it "returns [[:rest,:a],[:block,:b]] for a method expecting a splat argument ('a') and a block argument ('b')" do - m = MethodSpecs::Methods.instance_method(:zero_with_splat_and_block) - m.parameters.should == [[:rest,:a],[:block,:blk]] - end - - it "returns [[:req,:a],[:rest,:b],[:block,:c]] for a method expecting a required argument ('a'), a splat argument ('b'), and a block ('c')" do - m = MethodSpecs::Methods.instance_method(:one_req_with_splat_and_block) - m.parameters.should == [[:req,:a],[:rest,:b],[:block,:blk]] - end - - it "returns [[:req,:a],[:req,:b],[:rest,:c],[:block,:d]] for a method expecting two required arguments ('a','b'), a splat argument ('c'), and a block ('d')" do - m = MethodSpecs::Methods.instance_method(:two_req_with_splat_and_block) - m.parameters.should == [[:req,:a],[:req,:b],[:rest,:c],[:block,:blk]] - end - - it "returns [[:req,:a],[:opt,:b],[:rest,:c],[:block,:d]] for a method expecting a required argument ('a'), a splat argument ('c'), and a block ('d')" do - m = MethodSpecs::Methods.instance_method(:one_req_one_opt_with_splat_and_block) - m.parameters.should == [[:req,:a],[:opt,:b],[:rest,:c],[:block,:blk]] - end - - it "returns [[:req,:a],[:req,:b],[:opt,:c],[:block,:d]] for a method expecting two required arguments ('a','b'), an optional argument ('c'), a splat argument ('d'), and a block ('e')" do - m = MethodSpecs::Methods.instance_method(:two_req_one_opt_with_splat_and_block) - m.parameters.should == [[:req,:a],[:req,:b],[:opt,:c],[:rest,:d],[:block,:blk]] - end - - # 1.9 semantics - # - it "returns [[:rest,:a],[:req,:b]] for a method expecting a splat argument ('a') and a required argument ('b')" do - m = MethodSpecs::Methods.instance_method(:one_splat_one_req) - m.parameters.should == [[:rest,:a],[:req,:b]] - end - - it "returns [[:rest,:a],[:req,:b],[:req,:c]] for a method expecting a splat argument ('a') and two required arguments ('b','c')" do - m = MethodSpecs::Methods.instance_method(:one_splat_two_req) - m.parameters.should == [[:rest,:a],[:req,:b],[:req,:c]] - end - - it "returns [[:rest,:a],[:req,:b],[:block,:c]] for a method expecting a splat argument ('a'), a required argument ('b'), and a block ('c')" do - m = MethodSpecs::Methods.instance_method(:one_splat_one_req_with_block) - m.parameters.should == [[:rest,:a],[:req,:b],[:block,:blk]] - end - - it "works with ->(){} as the value of an optional argument" do - m = MethodSpecs::Methods.instance_method(:one_opt_with_stabby) - m.parameters.should == [[:opt,:a]] - end - - # define_method variants - it "returns [] for a define_method method with explicit no-args || specification" do - m = MethodSpecs::Methods.instance_method(:zero_defined_method) - m.parameters.should == [] - end - - it "returns [[:rest, :x]] for a define_method method with rest arg 'x' only" do - m = MethodSpecs::Methods.instance_method(:zero_with_splat_defined_method) - m.parameters.should == [[:rest, :x]] - end - - it "returns [[:req, :x]] for a define_method method expecting one required argument 'x'" do - m = MethodSpecs::Methods.instance_method(:one_req_defined_method) - m.parameters.should == [[:req, :x]] - end - - it "returns [[:req, :x], [:req, :y]] for a define_method method expecting two required arguments 'x' and 'y'" do - m = MethodSpecs::Methods.instance_method(:two_req_defined_method) - m.parameters.should == [[:req, :x], [:req, :y]] - end - - it "returns [] for a define_method method with no args specification" do - m = MethodSpecs::Methods.instance_method(:no_args_defined_method) - m.parameters.should == [] - end - - it "returns [[:req]] for a define_method method with a grouping as its only argument" do - m = MethodSpecs::Methods.instance_method(:two_grouped_defined_method) - m.parameters.should == [[:req]] - end - - it "returns [[:opt, :x]] for a define_method method with an optional argument 'x'" do - m = MethodSpecs::Methods.instance_method(:one_optional_defined_method) - m.parameters.should == [[:opt, :x]] - end - - it "returns [[:rest]] for a Method generated by respond_to_missing?" do - m = MethodSpecs::Methods.new - m.method(:handled_via_method_missing).parameters.should == [[:rest]] - end - - it "adds nameless rest arg for \"star\" argument" do - m = MethodSpecs::Methods.new - m.method(:one_unnamed_splat).parameters.should == [[:rest]] - end - - it "returns the args and block for a splat and block argument" do - m = MethodSpecs::Methods.new - m.method(:one_splat_one_block).parameters.should == [[:rest, :args], [:block, :block]] - end - end -end diff --git a/spec/ruby/core/module/alias_method_spec.rb b/spec/ruby/core/module/alias_method_spec.rb index 08b389ce85..ffaaac1266 100644 --- a/spec/ruby/core/module/alias_method_spec.rb +++ b/spec/ruby/core/module/alias_method_spec.rb @@ -34,18 +34,9 @@ lambda { @class.make_alias :ni, :san }.should raise_error(NameError) end - ruby_version_is ""..."1.9" do - it "raises TypeError if frozen" do - @class.freeze - lambda { @class.make_alias :uno, :public_one }.should raise_error(TypeError) - end - end - - ruby_version_is "1.9" do - it "raises RuntimeError if frozen" do - @class.freeze - lambda { @class.make_alias :uno, :public_one }.should raise_error(RuntimeError) - end + it "raises RuntimeError if frozen" do + @class.freeze + lambda { @class.make_alias :uno, :public_one }.should raise_error(RuntimeError) end it "converts the names using #to_str" do @@ -97,48 +88,44 @@ @subclass = ModuleSpecs::AliasingSubclass end - ruby_version_is "1.9" do - it "keeps initialize private when aliasing" do - @class.make_alias(:initialize, :public_one) - @class.private_instance_methods.include?(:initialize).should be_true + it "keeps initialize private when aliasing" do + @class.make_alias(:initialize, :public_one) + @class.private_instance_methods.include?(:initialize).should be_true - @subclass.make_alias(:initialize, :public_one) - @subclass.private_instance_methods.include?(:initialize).should be_true - end + @subclass.make_alias(:initialize, :public_one) + @subclass.private_instance_methods.include?(:initialize).should be_true + end - it "keeps initialize_copy private when aliasing" do - @class.make_alias(:initialize_copy, :public_one) - @class.private_instance_methods.include?(:initialize_copy).should be_true + it "keeps initialize_copy private when aliasing" do + @class.make_alias(:initialize_copy, :public_one) + @class.private_instance_methods.include?(:initialize_copy).should be_true - @subclass.make_alias(:initialize_copy, :public_one) - @subclass.private_instance_methods.include?(:initialize_copy).should be_true - end + @subclass.make_alias(:initialize_copy, :public_one) + @subclass.private_instance_methods.include?(:initialize_copy).should be_true end - ruby_version_is "2.0" do - it "keeps initialize_clone private when aliasing" do - @class.make_alias(:initialize_clone, :public_one) - @class.private_instance_methods.include?(:initialize_clone).should be_true + it "keeps initialize_clone private when aliasing" do + @class.make_alias(:initialize_clone, :public_one) + @class.private_instance_methods.include?(:initialize_clone).should be_true - @subclass.make_alias(:initialize_clone, :public_one) - @subclass.private_instance_methods.include?(:initialize_clone).should be_true - end + @subclass.make_alias(:initialize_clone, :public_one) + @subclass.private_instance_methods.include?(:initialize_clone).should be_true + end - it "keeps initialize_dup private when aliasing" do - @class.make_alias(:initialize_dup, :public_one) - @class.private_instance_methods.include?(:initialize_dup).should be_true + it "keeps initialize_dup private when aliasing" do + @class.make_alias(:initialize_dup, :public_one) + @class.private_instance_methods.include?(:initialize_dup).should be_true - @subclass.make_alias(:initialize_dup, :public_one) - @subclass.private_instance_methods.include?(:initialize_dup).should be_true - end + @subclass.make_alias(:initialize_dup, :public_one) + @subclass.private_instance_methods.include?(:initialize_dup).should be_true + end - it "keeps respond_to_missing? private when aliasing" do - @class.make_alias(:respond_to_missing?, :public_one) - @class.private_instance_methods.include?(:respond_to_missing?).should be_true + it "keeps respond_to_missing? private when aliasing" do + @class.make_alias(:respond_to_missing?, :public_one) + @class.private_instance_methods.include?(:respond_to_missing?).should be_true - @subclass.make_alias(:respond_to_missing?, :public_one) - @subclass.private_instance_methods.include?(:respond_to_missing?).should be_true - end + @subclass.make_alias(:respond_to_missing?, :public_one) + @subclass.private_instance_methods.include?(:respond_to_missing?).should be_true end end end diff --git a/spec/ruby/core/module/append_features_spec.rb b/spec/ruby/core/module/append_features_spec.rb index fbf187d8ba..ceb8c3f8eb 100644 --- a/spec/ruby/core/module/append_features_spec.rb +++ b/spec/ruby/core/module/append_features_spec.rb @@ -53,12 +53,10 @@ def self.append_features(mod) other.tainted?.should be_true end - ruby_version_is "1.9" do - it "copies own untrusted status to the given module" do - other = Module.new - Module.new.untrust.send :append_features, other - other.untrusted?.should be_true - end + it "copies own untrusted status to the given module" do + other = Module.new + Module.new.untrust.send :append_features, other + other.untrusted?.should be_true end describe "when other is frozen" do @@ -67,18 +65,9 @@ def self.append_features(mod) @other = Module.new.freeze end - ruby_version_is ""..."1.9" do - it "raises a TypeError before appending self" do - lambda { @receiver.send(:append_features, @other) }.should raise_error(TypeError) - @other.ancestors.should_not include(@receiver) - end - end - - ruby_version_is "1.9" do - it "raises a RuntimeError before appending self" do - lambda { @receiver.send(:append_features, @other) }.should raise_error(RuntimeError) - @other.ancestors.should_not include(@receiver) - end + it "raises a RuntimeError before appending self" do + lambda { @receiver.send(:append_features, @other) }.should raise_error(RuntimeError) + @other.ancestors.should_not include(@receiver) end end end diff --git a/spec/ruby/core/module/attr_accessor_spec.rb b/spec/ruby/core/module/attr_accessor_spec.rb index eb1027b140..251a31ab1b 100644 --- a/spec/ruby/core/module/attr_accessor_spec.rb +++ b/spec/ruby/core/module/attr_accessor_spec.rb @@ -87,14 +87,5 @@ class Fixnum it "can read through the accessor" do 1.foobar.should be_nil end - - # On Ruby 2.0 immediates are always frozen, so setting fails. - ruby_version_is ""..."2.0" do - it "can set a value through the accessor" do - 1.foobar = 2 - 1.foobar.should == 2 - end - end end - end diff --git a/spec/ruby/core/module/attr_spec.rb b/spec/ruby/core/module/attr_spec.rb index 02a6e5b61f..bbf350fb2e 100644 --- a/spec/ruby/core/module/attr_spec.rb +++ b/spec/ruby/core/module/attr_spec.rb @@ -85,37 +85,35 @@ def initialize lambda { c.new.foo=1 }.should raise_error(NoMethodError) end - ruby_version_is "1.9" do - it "creates a getter but no setter for all given attribute names" do - c = Class.new do - attr :attr, "attr2", "attr3" - - def initialize - @attr, @attr2, @attr3 = "test", "test2", "test3" - end - end - - o = c.new + it "creates a getter but no setter for all given attribute names" do + c = Class.new do + attr :attr, "attr2", "attr3" - %w{attr attr2 attr3}.each do |a| - o.respond_to?(a).should == true - o.respond_to?("#{a}=").should == false + def initialize + @attr, @attr2, @attr3 = "test", "test2", "test3" end + end + + o = c.new - o.attr.should == "test" - o.attr2.should == "test2" - o.attr3.should == "test3" + %w{attr attr2 attr3}.each do |a| + o.respond_to?(a).should == true + o.respond_to?("#{a}=").should == false end - it "applies current visibility to methods created" do - c = Class.new do - protected - attr :foo, :bar - end + o.attr.should == "test" + o.attr2.should == "test2" + o.attr3.should == "test3" + end - lambda { c.new.foo }.should raise_error(NoMethodError) - lambda { c.new.bar }.should raise_error(NoMethodError) + it "applies current visibility to methods created" do + c = Class.new do + protected + attr :foo, :bar end + + lambda { c.new.foo }.should raise_error(NoMethodError) + lambda { c.new.bar }.should raise_error(NoMethodError) end it "converts non string/symbol/fixnum names to strings using to_str" do diff --git a/spec/ruby/core/module/attr_writer_spec.rb b/spec/ruby/core/module/attr_writer_spec.rb index 23f9e7a28a..5be7a93a38 100644 --- a/spec/ruby/core/module/attr_writer_spec.rb +++ b/spec/ruby/core/module/attr_writer_spec.rb @@ -33,23 +33,6 @@ class TrueClass true.instance_variable_get("@spec_attr_writer").should == "a" end - ruby_version_is ""..."1.9" do - not_compliant_on :rubinius do - it "creates a setter for an attribute name given as a Fixnum" do - c = Class.new do - attr_writer :test1.to_i - end - - o = c.new - o.respond_to?("test1").should == false - o.respond_to?("test1=").should == true - - o.test1 = "test_1" - o.instance_variable_get(:@test1).should == "test_1" - end - end - end - it "converts non string/symbol/fixnum names to strings using to_str" do (o = mock('test')).should_receive(:to_str).any_number_of_times.and_return("test") c = Class.new do diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index 5263402e43..cb4968c690 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -179,24 +179,12 @@ module ModuleSpecs::Autoload::Q ModuleSpecs::Autoload.should have_constant(:O) end - ruby_version_is '1.9' ... '1.9.3' do - it "returns nil on refering the constant with defined?()" do - module ModuleSpecs::Autoload::Q - autoload :R, fixture(__FILE__, "autoload.rb") - defined?(R).should be_nil - end - ModuleSpecs::Autoload::Q.should have_constant(:R) - end - end - - ruby_version_is '1.9.3' do - it "returns 'constant' on refering the constant with defined?()" do - module ModuleSpecs::Autoload::Q - autoload :R, fixture(__FILE__, "autoload.rb") - defined?(R).should == 'constant' - end - ModuleSpecs::Autoload::Q.should have_constant(:R) + it "returns 'constant' on refering the constant with defined?()" do + module ModuleSpecs::Autoload::Q + autoload :R, fixture(__FILE__, "autoload.rb") + defined?(R).should == 'constant' end + ModuleSpecs::Autoload::Q.should have_constant(:R) end it "does not load the file when removing an autoload constant" do @@ -259,50 +247,25 @@ def r ModuleSpecs::Autoload.r.should be_kind_of(ModuleSpecs::Autoload::R) end - ruby_version_is "1.9" do - # [ruby-core:19127] [ruby-core:29941] - it "does NOT raise a NameError when the autoload file did not define the constant and a module is opened with the same name" do - module ModuleSpecs::Autoload - class W - autoload :Y, fixture(__FILE__, "autoload_w.rb") + # [ruby-core:19127] [ruby-core:29941] + it "does NOT raise a NameError when the autoload file did not define the constant and a module is opened with the same name" do + module ModuleSpecs::Autoload + class W + autoload :Y, fixture(__FILE__, "autoload_w.rb") - class Y - end + class Y end end - - ModuleSpecs::Autoload::W::Y.should be_kind_of(Class) - ScratchPad.recorded.should == :loaded end - end - - # This spec used autoload_w.rb which is TOTALLY WRONG. Both of these specs run on rubinius - # (only one on MRI), and autoload uses require logic, so we can only pull in - # autoload_w.rb ONCE. Thusly, it now uses autoload_w2.rb. - ruby_version_is ""..."1.9" do - # [ruby-core:19127] - it "raises a NameError when the autoload file did not define the constant and a module is opened with the same name" do - lambda do - module ModuleSpecs::Autoload2 - class W2 - autoload :Y2, fixture(__FILE__, "autoload_w2.rb") - - class Y2 - end - end - end - end.should raise_error(NameError) - ScratchPad.recorded.should == :loaded - end + ModuleSpecs::Autoload::W::Y.should be_kind_of(Class) + ScratchPad.recorded.should == :loaded end - ruby_version_is "1.9" do - it "calls #to_path on non-string filenames" do - p = mock('path') - p.should_receive(:to_path).and_return @non_existent - ModuleSpecs.autoload :A, p - end + it "calls #to_path on non-string filenames" do + p = mock('path') + p.should_receive(:to_path).and_return @non_existent + ModuleSpecs.autoload :A, p end it "raises an ArgumentError when an empty filename is given" do @@ -347,44 +310,23 @@ class ModuleSpecs::Autoload::Z < ModuleSpecs::Autoload::ZZ end.should raise_error(TypeError) end - ruby_version_is ""..."1.9" do - it "raises a TypeError if not passed a String for the filename" do - name = mock("autoload_name.rb") - name.stub!(:to_s).and_return("autoload_name.rb") - name.stub!(:to_str).and_return("autoload_name.rb") + it "raises a TypeError if not passed a String or object respodning to #to_path for the filename" do + name = mock("autoload_name.rb") - lambda { ModuleSpecs::Autoload.autoload :Str, name }.should raise_error(TypeError) - end + lambda { ModuleSpecs::Autoload.autoload :Str, name }.should raise_error(TypeError) end - ruby_version_is "1.9" do - it "raises a TypeError if not passed a String or object respodning to #to_path for the filename" do - name = mock("autoload_name.rb") - - lambda { ModuleSpecs::Autoload.autoload :Str, name }.should raise_error(TypeError) - end - - it "calls #to_path on non-String filename arguments" do - name = mock("autoload_name.rb") - name.should_receive(:to_path).and_return("autoload_name.rb") + it "calls #to_path on non-String filename arguments" do + name = mock("autoload_name.rb") + name.should_receive(:to_path).and_return("autoload_name.rb") - lambda { ModuleSpecs::Autoload.autoload :Str, name }.should_not raise_error - end + lambda { ModuleSpecs::Autoload.autoload :Str, name }.should_not raise_error end describe "on a frozen module" do - ruby_version_is "" ... "1.9" do - it "raises a TypeError before setting the name" do - lambda { @frozen_module.autoload :Foo, @non_existent }.should raise_error(TypeError) - @frozen_module.should_not have_constant(:Foo) - end - end - - ruby_version_is "1.9" do - it "raises a RuntimeError before setting the name" do - lambda { @frozen_module.autoload :Foo, @non_existent }.should raise_error(RuntimeError) - @frozen_module.should_not have_constant(:Foo) - end + it "raises a RuntimeError before setting the name" do + lambda { @frozen_module.autoload :Foo, @non_existent }.should raise_error(RuntimeError) + @frozen_module.should_not have_constant(:Foo) end end @@ -454,50 +396,48 @@ class ModuleSpecs::Autoload::Z < ModuleSpecs::Autoload::ZZ end - ruby_version_is "2.0" do - describe "(concurrently)" do - it "blocks others threads while doing an autoload" do - file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb") - autoload_path = file_path.sub /\.rb\Z/, '' - mod_count = 30 - thread_count = 16 + describe "(concurrently)" do + it "blocks others threads while doing an autoload" do + file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb") + autoload_path = file_path.sub /\.rb\Z/, '' + mod_count = 30 + thread_count = 16 + + mod_names = [] + mod_count.times do |i| + mod_name = :"Mod#{i}" + autoload mod_name, autoload_path + mod_names << mod_name + end - mod_names = [] - mod_count.times do |i| - mod_name = :"Mod#{i}" - autoload mod_name, autoload_path - mod_names << mod_name - end + barrier = ModuleSpecs::CyclicBarrier.new thread_count + ScratchPad.record ModuleSpecs::ThreadSafeCounter.new - barrier = ModuleSpecs::CyclicBarrier.new thread_count - ScratchPad.record ModuleSpecs::ThreadSafeCounter.new - - threads = (1..thread_count).map do - Thread.new do - mod_names.each do |mod_name| - break false unless barrier.enabled? - - was_last_one_in = barrier.await # wait for all threads to finish the iteration - # clean up so we can autoload the same file again - $LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path) - barrier.await # get ready for race - - begin - Object.const_get(mod_name).foo - rescue NoMethodError - barrier.disable! - break false - end + threads = (1..thread_count).map do + Thread.new do + mod_names.each do |mod_name| + break false unless barrier.enabled? + + was_last_one_in = barrier.await # wait for all threads to finish the iteration + # clean up so we can autoload the same file again + $LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path) + barrier.await # get ready for race + + begin + Object.const_get(mod_name).foo + rescue NoMethodError + barrier.disable! + break false end end end + end - # check that no thread got a NoMethodError because of partially loaded module - threads.all? {|t| t.value}.should be_true + # check that no thread got a NoMethodError because of partially loaded module + threads.all? {|t| t.value}.should be_true - # check that the autoloaded file was evaled exactly once - ScratchPad.recorded.get.should == mod_count - end + # check that the autoloaded file was evaled exactly once + ScratchPad.recorded.get.should == mod_count end end end diff --git a/spec/ruby/core/module/class_variable_defined_spec.rb b/spec/ruby/core/module/class_variable_defined_spec.rb index 33a4a5ae49..d47329455f 100644 --- a/spec/ruby/core/module/class_variable_defined_spec.rb +++ b/spec/ruby/core/module/class_variable_defined_spec.rb @@ -39,16 +39,6 @@ c.class_variable_defined?("@@mvar").should == false end - ruby_version_is ""..."1.9" do - not_compliant_on :rubinius do - it "accepts Fixnums for class variables" do - c = Class.new { class_variable_set :@@class_var, "test" } - c.class_variable_defined?(:@@class_var.to_i).should == true - c.class_variable_defined?(:@@no_class_var.to_i).should == false - end - end - end - it "raises a NameError when the given name is not allowed" do c = Class.new diff --git a/spec/ruby/core/module/class_variable_get_spec.rb b/spec/ruby/core/module/class_variable_get_spec.rb index 910205dfc7..01166626c1 100644 --- a/spec/ruby/core/module/class_variable_get_spec.rb +++ b/spec/ruby/core/module/class_variable_get_spec.rb @@ -13,20 +13,10 @@ c.send(:class_variable_get, "@@mvar").should == :mvar end - ruby_version_is ''...'2.1' do - it "allows '@@' to be a valid class variable name" do - c = Class.new { class_variable_set '@@', :foo } - c.send(:class_variable_get, "@@").should == :foo - c.send(:class_variable_get, :"@@").should == :foo - end - end - - ruby_version_is '2.1' do - it "raises a NameError for a class variable named '@@'" do - c = Class.new - lambda { c.send(:class_variable_get, "@@") }.should raise_error(NameError) - lambda { c.send(:class_variable_get, :"@@") }.should raise_error(NameError) - end + it "raises a NameError for a class variable named '@@'" do + c = Class.new + lambda { c.send(:class_variable_get, "@@") }.should raise_error(NameError) + lambda { c.send(:class_variable_get, :"@@") }.should raise_error(NameError) end it "raises a NameError for a class variables with the given name defined in an extended module" do @@ -56,22 +46,6 @@ meta.send(:class_variable_get, :@@var).should == :cvar_value end - ruby_version_is ""..."1.9" do - not_compliant_on :rubinius do - it "accepts Fixnums for class variables" do - c = Class.new { class_variable_set :@@class_var, "test" } - c.send(:class_variable_get, :@@class_var.to_i).should == "test" - end - - it "raises a NameError when a Fixnum for an uninitialized class variable is given" do - c = Class.new - lambda { - c.send :class_variable_get, :@@no_class_var.to_i - }.should raise_error(NameError) - end - end - end - it "raises a NameError when an uninitialized class variable is accessed" do c = Class.new [:@@no_class_var, "@@no_class_var"].each do |cvar| diff --git a/spec/ruby/core/module/class_variable_set_spec.rb b/spec/ruby/core/module/class_variable_set_spec.rb index 65ffb95d99..6d36298f5f 100644 --- a/spec/ruby/core/module/class_variable_set_spec.rb +++ b/spec/ruby/core/module/class_variable_set_spec.rb @@ -25,36 +25,13 @@ c.send(:class_variable_get, "@@mvar").should == :new_mvar end - ruby_version_is ""..."1.9" do - not_compliant_on :rubinius do - it "accepts Fixnums for class variables" do - c = Class.new - c.send(:class_variable_set, :@@test2.to_i, "test2") - c.send(:class_variable_get, :@@test2).should == "test2" - end - end - end - - ruby_version_is ""..."1.9" do - it "raises a TypeError when self is frozen" do - lambda { - Class.new.freeze.send(:class_variable_set, :@@test, "test") - }.should raise_error(TypeError) - lambda { - Module.new.freeze.send(:class_variable_set, :@@test, "test") - }.should raise_error(TypeError) - end - end - - ruby_version_is "1.9" do - it "raises a RuntimeError when self is frozen" do - lambda { - Class.new.freeze.send(:class_variable_set, :@@test, "test") - }.should raise_error(RuntimeError) - lambda { - Module.new.freeze.send(:class_variable_set, :@@test, "test") - }.should raise_error(RuntimeError) - end + it "raises a RuntimeError when self is frozen" do + lambda { + Class.new.freeze.send(:class_variable_set, :@@test, "test") + }.should raise_error(RuntimeError) + lambda { + Module.new.freeze.send(:class_variable_set, :@@test, "test") + }.should raise_error(RuntimeError) end it "raises a NameError when the given name is not allowed" do diff --git a/spec/ruby/core/module/class_variables_spec.rb b/spec/ruby/core/module/class_variables_spec.rb index a46554ecba..066052cd01 100644 --- a/spec/ruby/core/module/class_variables_spec.rb +++ b/spec/ruby/core/module/class_variables_spec.rb @@ -2,57 +2,25 @@ require File.expand_path('../fixtures/classes', __FILE__) describe "Module#class_variables" do - ruby_version_is ""..."1.9" do - it "returns an Array with the names of class variables of self and self's ancestors" do - ModuleSpecs::ClassVars::A.class_variables.should include("@@a_cvar") - ModuleSpecs::ClassVars::M.class_variables.should include("@@m_cvar") - ModuleSpecs::ClassVars::B.class_variables.should include("@@a_cvar", "@@b_cvar", "@@m_cvar") - end - - it "returns an Array with names of class variables defined in metaclasses" do - ModuleSpecs::CVars.class_variables.should include("@@cls", "@@meta") - end - - it "returns an Array of Strings of class variable names defined in a metaclass" do - obj = mock("metaclass class variable") - meta = obj.singleton_class - meta.send :class_variable_set, :@@var, :cvar_value - meta.class_variables.should == ["@@var"] - end - - it "returns an Array with names of class variables defined in included modules" do - c = Class.new { include ModuleSpecs::MVars } - c.class_variables.should include("@@mvar") - end - - it "does not return class variables defined in extended modules" do - c = Class.new - c.extend ModuleSpecs::MVars - c.class_variables.should_not include("@@mvar") - end + it "returns an Array with the names of class variables of self" do + ModuleSpecs::ClassVars::A.class_variables.should include(:@@a_cvar) + ModuleSpecs::ClassVars::M.class_variables.should include(:@@m_cvar) end - ruby_version_is "1.9" do - it "returns an Array with the names of class variables of self" do - ModuleSpecs::ClassVars::A.class_variables.should include(:@@a_cvar) - ModuleSpecs::ClassVars::M.class_variables.should include(:@@m_cvar) - end - - it "returns an Array of Symbols of class variable names defined in a metaclass" do - obj = mock("metaclass class variable") - meta = obj.singleton_class - meta.send :class_variable_set, :@@var, :cvar_value - meta.class_variables.should == [:@@var] - end + it "returns an Array of Symbols of class variable names defined in a metaclass" do + obj = mock("metaclass class variable") + meta = obj.singleton_class + meta.send :class_variable_set, :@@var, :cvar_value + meta.class_variables.should == [:@@var] + end - it "returns an Array with names of class variables defined in metaclasses" do - ModuleSpecs::CVars.class_variables.should include(:@@cls, :@@meta) - end + it "returns an Array with names of class variables defined in metaclasses" do + ModuleSpecs::CVars.class_variables.should include(:@@cls, :@@meta) + end - it "does not return class variables defined in extended modules" do - c = Class.new - c.extend ModuleSpecs::MVars - c.class_variables.should_not include(:@@mvar) - end + it "does not return class variables defined in extended modules" do + c = Class.new + c.extend ModuleSpecs::MVars + c.class_variables.should_not include(:@@mvar) end end diff --git a/spec/ruby/core/module/const_defined_spec.rb b/spec/ruby/core/module/const_defined_spec.rb index bf321ec837..a61b456af9 100644 --- a/spec/ruby/core/module/const_defined_spec.rb +++ b/spec/ruby/core/module/const_defined_spec.rb @@ -9,34 +9,32 @@ ConstantSpecs::ContainerA.const_defined?(:ChildA).should == true end - ruby_version_is "1.9" do - it "returns true if the constant is defined in the reciever's superclass" do - # CS_CONST4 is defined in the superclass of ChildA - ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4).should be_true - end + it "returns true if the constant is defined in the reciever's superclass" do + # CS_CONST4 is defined in the superclass of ChildA + ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4).should be_true + end - it "returns true if the constant is defined in a mixed-in module of the reciever" do - # CS_CONST10 is defined in a module included by ChildA - ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST10).should be_true - end + it "returns true if the constant is defined in a mixed-in module of the reciever" do + # CS_CONST10 is defined in a module included by ChildA + ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST10).should be_true + end - it "returns true if the constant is defined in Object and the receiver is a module" do - # CS_CONST1 is defined in Object - ConstantSpecs::ModuleA.const_defined?(:CS_CONST1).should be_true - end + it "returns true if the constant is defined in Object and the receiver is a module" do + # CS_CONST1 is defined in Object + ConstantSpecs::ModuleA.const_defined?(:CS_CONST1).should be_true + end - it "returns true if the constant is defined in Object and the receiver is a class that has Object among its ancestors" do - # CS_CONST1 is defined in Object - ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST1).should be_true - end + it "returns true if the constant is defined in Object and the receiver is a class that has Object among its ancestors" do + # CS_CONST1 is defined in Object + ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST1).should be_true + end - it "returns false if the constant is defined in the receiver's superclass and the inherit flag is false" do - ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, false).should be_false - end + it "returns false if the constant is defined in the receiver's superclass and the inherit flag is false" do + ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, false).should be_false + end - it "returns true if the constant is defined in the receiver's superclass and the inherit flag is true" do - ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, true).should be_true - end + it "returns true if the constant is defined in the receiver's superclass and the inherit flag is true" do + ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, true).should be_true end it "returns true if the given String names a constant defined in the receiver" do @@ -46,21 +44,12 @@ ConstantSpecs::ContainerA.const_defined?("ChildA").should == true end - ruby_version_is ""..."1.9" do - it "returns false if the constant is not defined in the receiver" do - ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4).should == false - ConstantSpecs::ParentA.const_defined?(:CS_CONST12).should == false - end - end - - ruby_version_is "1.9" do - it "returns false if the constant is not defined in the receiver, its superclass, or any included modules" do - # The following constant isn't defined at all. - ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4726).should be_false - # DETATCHED_CONSTANT is defined in ConstantSpecs::Detatched, which isn't - # included by or inherited from ParentA - ConstantSpecs::ParentA.const_defined?(:DETATCHED_CONSTANT).should be_false - end + it "returns false if the constant is not defined in the receiver, its superclass, or any included modules" do + # The following constant isn't defined at all. + ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4726).should be_false + # DETATCHED_CONSTANT is defined in ConstantSpecs::Detatched, which isn't + # included by or inherited from ParentA + ConstantSpecs::ParentA.const_defined?(:DETATCHED_CONSTANT).should be_false end it "does not call #const_missing if the constant is not defined in the receiver" do diff --git a/spec/ruby/core/module/const_get_spec.rb b/spec/ruby/core/module/const_get_spec.rb index 71b31eba1f..700d0ba0fa 100644 --- a/spec/ruby/core/module/const_get_spec.rb +++ b/spec/ruby/core/module/const_get_spec.rb @@ -65,28 +65,26 @@ end.should raise_error(NameError) end - ruby_version_is "1.9" do - it "raises a NameError if the constant is defined in the receiver's supperclass and the inherit flag is false" do - lambda do - ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, false) - end.should raise_error(NameError) - end + it "raises a NameError if the constant is defined in the receiver's supperclass and the inherit flag is false" do + lambda do + ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, false) + end.should raise_error(NameError) + end - it "searches into the receiver superclasses if the inherit flag is true" do - ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, true).should == :const4 - end + it "searches into the receiver superclasses if the inherit flag is true" do + ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, true).should == :const4 + end - it "raises a NameError when the receiver is a Module, the constant is defined at toplevel and the inherit flag is false" do - lambda do - ConstantSpecs::ModuleA.const_get(:CS_CONST1, false) - end.should raise_error(NameError) - end + it "raises a NameError when the receiver is a Module, the constant is defined at toplevel and the inherit flag is false" do + lambda do + ConstantSpecs::ModuleA.const_get(:CS_CONST1, false) + end.should raise_error(NameError) + end - it "raises a NameError when the receiver is a Class, the constant is defined at toplevel and the inherit flag is false" do - lambda do - ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST1, false) - end.should raise_error(NameError) - end + it "raises a NameError when the receiver is a Class, the constant is defined at toplevel and the inherit flag is false" do + lambda do + ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST1, false) + end.should raise_error(NameError) end it "accepts a toplevel scope qualifier" do diff --git a/spec/ruby/core/module/const_set_spec.rb b/spec/ruby/core/module/const_set_spec.rb index c8a0fa980d..da44e60cee 100644 --- a/spec/ruby/core/module/const_set_spec.rb +++ b/spec/ruby/core/module/const_set_spec.rb @@ -58,18 +58,9 @@ @name = :Foo end - ruby_version_is "" ... "1.9" do - it "raises a TypeError before setting the name" do - lambda { @frozen.const_set @name, nil }.should raise_error(TypeError) - @frozen.should_not have_constant(@name) - end - end - - ruby_version_is "1.9" do - it "raises a RuntimeError before setting the name" do - lambda { @frozen.const_set @name, nil }.should raise_error(RuntimeError) - @frozen.should_not have_constant(@name) - end + it "raises a RuntimeError before setting the name" do + lambda { @frozen.const_set @name, nil }.should raise_error(RuntimeError) + @frozen.should_not have_constant(@name) end end end diff --git a/spec/ruby/core/module/constants_spec.rb b/spec/ruby/core/module/constants_spec.rb index 66a7a2d3d9..6e0ef3a568 100644 --- a/spec/ruby/core/module/constants_spec.rb +++ b/spec/ruby/core/module/constants_spec.rb @@ -10,104 +10,70 @@ module ConstantSpecsAdded Module.constants.size.should == count + 1 end - ruby_version_is "" ... "1.9" do - it "returns an array of String names" do - # This in NOT an exhaustive list - Module.constants.should include("Array", "Bignum", "Class", "Comparable", "Dir", - "Enumerable", "ENV", "Exception", "FalseClass", - "File", "Fixnum", "Float", "Hash", "Integer", "IO", - "Kernel", "Math", "Method", "Module", "NilClass", - "Numeric", "Object", "Range", "Regexp", "String", - "Symbol", "Thread", "Time", "TrueClass") - end + it "returns an array of Symbol names" do + # This in NOT an exhaustive list + Module.constants.should include(:Array, :Bignum, :Class, :Comparable, :Dir, + :Enumerable, :ENV, :Exception, :FalseClass, + :File, :Fixnum, :Float, :Hash, :Integer, :IO, + :Kernel, :Math, :Method, :Module, :NilClass, + :Numeric, :Object, :Range, :Regexp, :String, + :Symbol, :Thread, :Time, :TrueClass) end - ruby_version_is "1.9" do - it "returns an array of Symbol names" do - # This in NOT an exhaustive list - Module.constants.should include(:Array, :Bignum, :Class, :Comparable, :Dir, - :Enumerable, :ENV, :Exception, :FalseClass, - :File, :Fixnum, :Float, :Hash, :Integer, :IO, - :Kernel, :Math, :Method, :Module, :NilClass, - :Numeric, :Object, :Range, :Regexp, :String, - :Symbol, :Thread, :Time, :TrueClass) + it "returns Module's constants when given a parameter" do + direct = Module.constants(false) + indirect = Module.constants(true) + module ConstantSpecsIncludedModule + MODULE_CONSTANTS_SPECS_INDIRECT = :foo end - it "returns Module's constants when given a parameter" do - direct = Module.constants(false) - indirect = Module.constants(true) - module ConstantSpecsIncludedModule - MODULE_CONSTANTS_SPECS_INDIRECT = :foo - end - - class Module - MODULE_CONSTANTS_SPECS_DIRECT = :bar - include ConstantSpecsIncludedModule - end - (Module.constants(false) - direct).should == [:MODULE_CONSTANTS_SPECS_DIRECT] - (Module.constants(true) - indirect).sort.should == [:MODULE_CONSTANTS_SPECS_DIRECT, :MODULE_CONSTANTS_SPECS_INDIRECT] + class Module + MODULE_CONSTANTS_SPECS_DIRECT = :bar + include ConstantSpecsIncludedModule end + (Module.constants(false) - direct).should == [:MODULE_CONSTANTS_SPECS_DIRECT] + (Module.constants(true) - indirect).sort.should == [:MODULE_CONSTANTS_SPECS_DIRECT, :MODULE_CONSTANTS_SPECS_INDIRECT] end end describe "Module#constants" do - ruby_version_is "" ... "1.9" do - it "returns an array of String names of all constants defined in the module" \ - "and all included modules" do - ConstantSpecs::ContainerA.constants.sort.should == [ - "CS_CONST10", "CS_CONST23", "CS_CONST24", "CS_CONST5", "ChildA" - ] - end - - it "includes names of constants defined after a module is included" do - ConstantSpecs::ModuleM::CS_CONST250 = :const250 - ConstantSpecs::ContainerA.constants.should include("CS_CONST250") - end + it "returns an array of Symbol names of all constants defined in the module" \ + "and all included modules" do + ConstantSpecs::ContainerA.constants.sort.should == [ + :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA + ] end - ruby_version_is "1.9" do - it "returns an array of Symbol names of all constants defined in the module" \ - "and all included modules" do - ConstantSpecs::ContainerA.constants.sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA - ] - end - - it "returns all constants including inherited when passed true" do - ConstantSpecs::ContainerA.constants(true).sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA - ] - end - - it "returns all constants including inherited when passed some object" do - ConstantSpecs::ContainerA.constants(Object.new).sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA - ] - end + it "returns all constants including inherited when passed true" do + ConstantSpecs::ContainerA.constants(true).sort.should == [ + :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA + ] + end - it "includes names of constants defined after a module is included" do - ConstantSpecs::ModuleM::CS_CONST251 = :const251 - ConstantSpecs::ContainerA.constants.should include(:CS_CONST251) - end + it "returns all constants including inherited when passed some object" do + ConstantSpecs::ContainerA.constants(Object.new).sort.should == [ + :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA + ] + end - it "doesn't returns inherited constants when passed false" do - ConstantSpecs::ContainerA.constants(false).sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST5, :ChildA - ] - end + it "includes names of constants defined after a module is included" do + ConstantSpecs::ModuleM::CS_CONST251 = :const251 + ConstantSpecs::ContainerA.constants.should include(:CS_CONST251) + end - it "doesn't returns inherited constants when passed nil" do - ConstantSpecs::ContainerA.constants(nil).sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST5, :ChildA - ] - end + it "doesn't returns inherited constants when passed false" do + ConstantSpecs::ContainerA.constants(false).sort.should == [ + :CS_CONST10, :CS_CONST23, :CS_CONST5, :ChildA + ] end - ruby_version_is "1.9.3" do - require File.expand_path('../fixtures/classes19', __FILE__) + it "doesn't returns inherited constants when passed nil" do + ConstantSpecs::ContainerA.constants(nil).sort.should == [ + :CS_CONST10, :CS_CONST23, :CS_CONST5, :ChildA + ] + end - it "returns only public constants" do - ModuleSpecs::PrivConstModule.constants.should == [:PUBLIC_CONSTANT] - end + it "returns only public constants" do + ModuleSpecs::PrivConstModule.constants.should == [:PUBLIC_CONSTANT] end end diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb index 81f10accb4..95b3abce97 100644 --- a/spec/ruby/core/module/define_method_spec.rb +++ b/spec/ruby/core/module/define_method_spec.rb @@ -4,8 +4,28 @@ class DefineMethodSpecClass end -ruby_version_is "1.9" do - require File.expand_path("../versions/define_method_1.9", __FILE__) +describe "passed { |a, b = 1| } creates a method that" do + before :each do + @klass = Class.new do + define_method(:m) { |a, b = 1| return a, b } + end + end + + it "raises an ArgumentError when passed zero arguments" do + lambda { @klass.new.m }.should raise_error(ArgumentError) + end + + it "has a default value for b when passed one argument" do + @klass.new.m(1).should == [1, 1] + end + + it "overrides the default argument when passed two arguments" do + @klass.new.m(1, 2).should == [1, 2] + end + + it "raises an ArgumentError when passed three arguments" do + lambda { @klass.new.m(1, 2, 3) }.should raise_error(ArgumentError) + end end describe "Module#define_method when given an UnboundMethod" do @@ -45,40 +65,30 @@ def test_method @class = child end - ruby_version_is "1.8" ... "1.9" do - it "raises TypeError when calling the method" do - lambda { @class.another_test_method }.should raise_error(TypeError) - end - end - - ruby_version_is "1.9" do - it "doesn't raise TypeError when calling the method" do - @class.another_test_method.should == :foo - end + it "doesn't raise TypeError when calling the method" do + @class.another_test_method.should == :foo end end end describe "Module#define_method when name is :initialize" do - ruby_version_is "1.9" do - describe "passed a block" do - it "sets visibility to private when method name is :initialize" do - klass = Class.new do - define_method(:initialize) { } - end - klass.should have_private_instance_method(:initialize) + describe "passed a block" do + it "sets visibility to private when method name is :initialize" do + klass = Class.new do + define_method(:initialize) { } end + klass.should have_private_instance_method(:initialize) end + end - describe "given an UnboundMethod" do - it "sets the visibility to private when method is named :initialize" do - klass = Class.new do - def test_method - end - define_method(:initialize, instance_method(:test_method)) + describe "given an UnboundMethod" do + it "sets the visibility to private when method is named :initialize" do + klass = Class.new do + def test_method end - klass.should have_private_instance_method(:initialize) + define_method(:initialize, instance_method(:test_method)) end + klass.should have_private_instance_method(:initialize) end end end @@ -145,20 +155,10 @@ class DefineMethodSpecClass lambda { obj.proc_style_test :arg }.should raise_error(ArgumentError) end - ruby_version_is ""..."1.9" do - it "raises a TypeError if frozen" do - lambda { - Class.new { freeze; define_method(:foo) {} } - }.should raise_error(TypeError) - end - end - - ruby_version_is "1.9" do - it "raises a RuntimeError if frozen" do - lambda { - Class.new { freeze; define_method(:foo) {} } - }.should raise_error(RuntimeError) - end + it "raises a RuntimeError if frozen" do + lambda { + Class.new { freeze; define_method(:foo) {} } + }.should raise_error(RuntimeError) end it "accepts a Method (still bound)" do @@ -206,25 +206,10 @@ class DefineMethodByProcClass Module.should have_private_instance_method(:define_method) end - ruby_version_is ""..."2.1" do - it "returns a Proc" do - class DefineMethodSpecClass - method = define_method("return_test") { || true } - method.is_a?(Proc).should be_true - # check if it is a lambda: - lambda { - method.call :too_many_arguments - }.should raise_error(ArgumentError) - end - end - end - - ruby_version_is "2.1" do - it "returns its symbol" do - class DefineMethodSpecClass - method = define_method("return_test") { || true } - method.should == :return_test - end + it "returns its symbol" do + class DefineMethodSpecClass + method = define_method("return_test") { || true } + method.should == :return_test end end @@ -237,23 +222,8 @@ class DefineMethodSpecClass } end - ruby_version_is "1.8" ... "1.9" do - it "raises a TypeError when calling a method from a different object" do - obj = @lazy_class_def.call.new - lambda { obj.bar }.should raise_error(TypeError) - end - end - - ruby_version_is "1.9" ... "2.0" do - it "raises a TypeError when defining a method from a different object" do - lambda { @lazy_class_def.call }.should raise_error(TypeError) - end - end - - ruby_version_is "2.0" do - it "allows methods defined on a different object" do - @lazy_class_def.call.new.bar.should == 'bar' - end + it "allows methods defined on a different object" do + @lazy_class_def.call.new.bar.should == 'bar' end end end @@ -270,24 +240,12 @@ class DefineMethodSpecClass @klass.new.m().should == :called end - ruby_version_is ""..."1.9" do - it "returns the value computed by the block when passed one argument" do - @klass.new.m(1).should == :called - end - - it "returns the value computed by the block when passed two arguments" do - @klass.new.m(1, 2).should == :called - end + it "raises an ArgumentError when passed one argument" do + lambda { @klass.new.m 1 }.should raise_error(ArgumentError) end - ruby_version_is "1.9" do - it "raises an ArgumentError when passed one argument" do - lambda { @klass.new.m 1 }.should raise_error(ArgumentError) - end - - it "raises an ArgumentError when passed two arguments" do - lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when passed two arguments" do + lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError) end end @@ -318,32 +276,16 @@ class DefineMethodSpecClass end end - ruby_version_is ""..."1.9" do - it "receives nil as the argument when passed zero arguments" do - @klass.new.m().should be_nil - end - - it "receives nil as the argument when passed zero arguments and a block" do - @klass.new.m() { :computed }.should be_nil - end - - it "returns the value computed by the block when passed two arguments" do - @klass.new.m(1, 2).should == [1, 2] - end + it "raises an ArgumentError when passed zero arguments" do + lambda { @klass.new.m }.should raise_error(ArgumentError) end - ruby_version_is "1.9" do - it "raises an ArgumentError when passed zero arguments" do - lambda { @klass.new.m }.should raise_error(ArgumentError) - end - - it "raises an ArgumentError when passed zero arguments and a block" do - lambda { @klass.new.m { :computed } }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when passed zero arguments and a block" do + lambda { @klass.new.m { :computed } }.should raise_error(ArgumentError) + end - it "raises an ArgumentError when passed two arguments" do - lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when passed two arguments" do + lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError) end it "receives the value passed as the argument when passed one argument" do diff --git a/spec/ruby/core/module/define_singleton_method_spec.rb b/spec/ruby/core/module/define_singleton_method_spec.rb index 41f39654fd..0841d5d7e2 100644 --- a/spec/ruby/core/module/define_singleton_method_spec.rb +++ b/spec/ruby/core/module/define_singleton_method_spec.rb @@ -1,19 +1,17 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Module#define_singleton_method" do - it "defines the given method as an class method with the given name in self" do - klass = Module.new do - define_singleton_method :a do - 42 - end - define_singleton_method(:b, lambda {|x| 2*x }) +describe "Module#define_singleton_method" do + it "defines the given method as an class method with the given name in self" do + klass = Module.new do + define_singleton_method :a do + 42 end - - klass.a.should == 42 - klass.b(10).should == 20 + define_singleton_method(:b, lambda {|x| 2*x }) end - it "needs to be reviewed for spec completeness" + klass.a.should == 42 + klass.b(10).should == 20 end + + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/core/module/extend_object_spec.rb b/spec/ruby/core/module/extend_object_spec.rb index e43a389f50..73c1623dce 100644 --- a/spec/ruby/core/module/extend_object_spec.rb +++ b/spec/ruby/core/module/extend_object_spec.rb @@ -48,12 +48,10 @@ other.tainted?.should be_false end - ruby_version_is "1.9" do - it "does not copy own untrusted status to the given object" do - other = Object.new - Module.new.untrust.send :extend_object, other - other.untrusted?.should be_false - end + it "does not copy own untrusted status to the given object" do + other = Object.new + Module.new.untrust.send :extend_object, other + other.untrusted?.should be_false end describe "when given a frozen object" do @@ -62,18 +60,9 @@ @object = Object.new.freeze end - ruby_version_is ""..."1.9" do - it "raises a TypeError before extending the object" do - lambda { @receiver.send(:extend_object, @object) }.should raise_error(TypeError) - @object.should_not be_kind_of(@receiver) - end - end - - ruby_version_is "1.9" do - it "raises a RuntimeError before extending the object" do - lambda { @receiver.send(:extend_object, @object) }.should raise_error(RuntimeError) - @object.should_not be_kind_of(@receiver) - end + it "raises a RuntimeError before extending the object" do + lambda { @receiver.send(:extend_object, @object) }.should raise_error(RuntimeError) + @object.should_not be_kind_of(@receiver) end end end diff --git a/spec/ruby/core/module/extended_spec.rb b/spec/ruby/core/module/extended_spec.rb index 8bea768fba..0a62dd9850 100644 --- a/spec/ruby/core/module/extended_spec.rb +++ b/spec/ruby/core/module/extended_spec.rb @@ -38,15 +38,7 @@ def self.extended(o) end end - ruby_version_is ""..."1.9" do - it "is private in its default implementation" do - Module.new.private_methods.should include("extended") - end - end - - ruby_version_is "1.9" do - it "is private in its default implementation" do - Module.new.private_methods.should include(:extended) - end + it "is private in its default implementation" do + Module.new.private_methods.should include(:extended) end end diff --git a/spec/ruby/core/module/fixtures/classes.rb b/spec/ruby/core/module/fixtures/classes.rb index 8a7d4542bf..6077b0a3d5 100644 --- a/spec/ruby/core/module/fixtures/classes.rb +++ b/spec/ruby/core/module/fixtures/classes.rb @@ -1,6 +1,12 @@ module ModuleSpecs CONST = :plain_constant + module PrivConstModule + PRIVATE_CONSTANT = 1 + private_constant :PRIVATE_CONSTANT + PUBLIC_CONSTANT = 2 + end + class Subclass < Module end diff --git a/spec/ruby/core/module/fixtures/classes19.rb b/spec/ruby/core/module/fixtures/classes19.rb deleted file mode 100644 index 4dc21bcd15..0000000000 --- a/spec/ruby/core/module/fixtures/classes19.rb +++ /dev/null @@ -1,7 +0,0 @@ -module ModuleSpecs - module PrivConstModule - PRIVATE_CONSTANT = 1 - private_constant :PRIVATE_CONSTANT - PUBLIC_CONSTANT = 2 - end -end diff --git a/spec/ruby/core/module/include_spec.rb b/spec/ruby/core/module/include_spec.rb index 5bd812cad4..a53b3c362c 100644 --- a/spec/ruby/core/module/include_spec.rb +++ b/spec/ruby/core/module/include_spec.rb @@ -2,16 +2,8 @@ require File.expand_path('../fixtures/classes', __FILE__) describe "Module#include" do - ruby_version_is "" ... "2.1" do - it "is a private method" do - Module.should have_private_instance_method(:include, true) - end - end - - ruby_version_is "2.1" do - it "is a public method" do - Module.should have_public_instance_method(:include, true) - end + it "is a public method" do + Module.should have_public_instance_method(:include, true) end it "calls #append_features(self) in reversed order on each module" do @@ -55,20 +47,10 @@ def self.append_features(mod) lambda { ModuleSpecs::SubclassSpec.send(:include, ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError) end - ruby_version_is ""..."1.9" do - it "imports constants to modules and classes" do - ModuleSpecs::A.constants.should include("CONSTANT_A") - ModuleSpecs::B.constants.should include("CONSTANT_A","CONSTANT_B") - ModuleSpecs::C.constants.should include("CONSTANT_A","CONSTANT_B") - end - end - - ruby_version_is "1.9" do - it "imports constants to modules and classes" do - ModuleSpecs::A.constants.should include(:CONSTANT_A) - ModuleSpecs::B.constants.should include(:CONSTANT_A, :CONSTANT_B) - ModuleSpecs::C.constants.should include(:CONSTANT_A, :CONSTANT_B) - end + it "imports constants to modules and classes" do + ModuleSpecs::A.constants.should include(:CONSTANT_A) + ModuleSpecs::B.constants.should include(:CONSTANT_A, :CONSTANT_B) + ModuleSpecs::C.constants.should include(:CONSTANT_A, :CONSTANT_B) end it "shadows constants from outer scopes" do @@ -83,40 +65,18 @@ def self.append_features(mod) ModuleSpecs::C::OVERRIDE.should == :c end - ruby_version_is ""..."1.9" do - it "imports instance methods to modules and classes" do - ModuleSpecs::A.instance_methods.should include("ma") - ModuleSpecs::B.instance_methods.should include("ma","mb") - ModuleSpecs::C.instance_methods.should include("ma","mb") - end - end - - ruby_version_is "1.9" do - it "imports instance methods to modules and classes" do - ModuleSpecs::A.instance_methods.should include(:ma) - ModuleSpecs::B.instance_methods.should include(:ma,:mb) - ModuleSpecs::C.instance_methods.should include(:ma,:mb) - end + it "imports instance methods to modules and classes" do + ModuleSpecs::A.instance_methods.should include(:ma) + ModuleSpecs::B.instance_methods.should include(:ma,:mb) + ModuleSpecs::C.instance_methods.should include(:ma,:mb) end - ruby_version_is ""..."1.9" do - it "does not import methods to modules and classes" do - ModuleSpecs::A.methods.include?("cma").should == true - ModuleSpecs::B.methods.include?("cma").should == false - ModuleSpecs::B.methods.include?("cmb").should == true - ModuleSpecs::C.methods.include?("cma").should == false - ModuleSpecs::C.methods.include?("cmb").should == false - end - end - - ruby_version_is "1.9" do - it "does not import methods to modules and classes" do - ModuleSpecs::A.methods.include?(:cma).should == true - ModuleSpecs::B.methods.include?(:cma).should == false - ModuleSpecs::B.methods.include?(:cmb).should == true - ModuleSpecs::C.methods.include?(:cma).should == false - ModuleSpecs::C.methods.include?(:cmb).should == false - end + it "does not import methods to modules and classes" do + ModuleSpecs::A.methods.include?(:cma).should == true + ModuleSpecs::B.methods.include?(:cma).should == false + ModuleSpecs::B.methods.include?(:cmb).should == true + ModuleSpecs::C.methods.include?(:cma).should == false + ModuleSpecs::C.methods.include?(:cmb).should == false end it "attaches the module as the caller's immediate ancestor" do diff --git a/spec/ruby/core/module/instance_method_spec.rb b/spec/ruby/core/module/instance_method_spec.rb index 49c22eff5a..9b4e76e329 100644 --- a/spec/ruby/core/module/instance_method_spec.rb +++ b/spec/ruby/core/module/instance_method_spec.rb @@ -51,17 +51,9 @@ @mod_um.inspect.should =~ /\bModuleSpecs::InstanceMethChild\b/ end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if passed a Fixnum that is not a symbol" do - lambda { Object.instance_method(0) }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if not passed a symbol" do - lambda { Object.instance_method([]) }.should raise_error(TypeError) - lambda { Object.instance_method(0) }.should raise_error(TypeError) - end + it "raises a TypeError if not passed a symbol" do + lambda { Object.instance_method([]) }.should raise_error(TypeError) + lambda { Object.instance_method(0) }.should raise_error(TypeError) end it "raises a TypeError if the given name is not a string/symbol" do diff --git a/spec/ruby/core/module/instance_methods_spec.rb b/spec/ruby/core/module/instance_methods_spec.rb index 85d0ed26bf..36757e8e78 100644 --- a/spec/ruby/core/module/instance_methods_spec.rb +++ b/spec/ruby/core/module/instance_methods_spec.rb @@ -1,101 +1,48 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -# Prior to MRI 1.9 #instance_methods returned an Array of Strings -ruby_version_is ""..."1.9" do - describe "Module#instance_methods" do - it "does not return methods undefined in a superclass" do - methods = ModuleSpecs::Parent.instance_methods(false) - methods.should_not include("undefed_method") - end - - it "does not return methods undefined in a subclass" do - methods = ModuleSpecs::Grandchild.instance_methods - methods.should_not include("parent_method", "another_parent_method") - end - - it "does not return methods undefined in the current class" do - ModuleSpecs::Child.send(:undef_method, 'undefed_child') - methods = ModuleSpecs::Child.instance_methods - methods.should_not include("undefed_method", "undefed_child") - end - - it "does not return methods from an included module that are undefined in the class" do - ModuleSpecs::Grandchild.instance_methods.should_not include("super_included_method") - end - - it "returns the public and protected methods of self if include_super is false" do - methods = ModuleSpecs::Parent.instance_methods(false) - methods.should include("protected_parent", "public_parent") - - methods = ModuleSpecs::Child.instance_methods(false) - methods.should include("protected_child", "public_child") - end - - it "returns the public and protected methods of self and it's ancestors" do - methods = ModuleSpecs::Basic.instance_methods - methods.should include("protected_module", "public_module") - - methods = ModuleSpecs::Super.instance_methods - methods.should include("protected_module", "protected_super_module", - "public_module", "public_super_module") - end - - it "makes a private Object instance method public in Kernel" do - methods = Kernel.instance_methods - methods.should include("module_specs_private_method_on_object_for_kernel_public") - methods = Object.instance_methods - methods.should_not include("module_specs_private_method_on_object_for_kernel_public") - end +describe "Module#instance_methods" do + it "does not return methods undefined in a superclass" do + methods = ModuleSpecs::Parent.instance_methods(false) + methods.should_not include(:undefed_method) end -end - -# As of MRI 1.9 #instance_methods returns an Array of Symbols -ruby_version_is "1.9" do - describe "Module#instance_methods" do - it "does not return methods undefined in a superclass" do - methods = ModuleSpecs::Parent.instance_methods(false) - methods.should_not include(:undefed_method) - end - - it "does not return methods undefined in a subclass" do - methods = ModuleSpecs::Grandchild.instance_methods - methods.should_not include(:parent_method, :another_parent_method) - end + it "does not return methods undefined in a subclass" do + methods = ModuleSpecs::Grandchild.instance_methods + methods.should_not include(:parent_method, :another_parent_method) + end - it "does not return methods undefined in the current class" do - ModuleSpecs::Child.send(:undef_method, 'undefed_child') - methods = ModuleSpecs::Child.instance_methods - methods.should_not include(:undefed_method, :undefed_child) - end + it "does not return methods undefined in the current class" do + ModuleSpecs::Child.send(:undef_method, 'undefed_child') + methods = ModuleSpecs::Child.instance_methods + methods.should_not include(:undefed_method, :undefed_child) + end - it "does not return methods from an included module that are undefined in the class" do - ModuleSpecs::Grandchild.instance_methods.should_not include(:super_included_method) - end + it "does not return methods from an included module that are undefined in the class" do + ModuleSpecs::Grandchild.instance_methods.should_not include(:super_included_method) + end - it "returns the public and protected methods of self if include_super is false" do - methods = ModuleSpecs::Parent.instance_methods(false) - methods.should include(:protected_parent, :public_parent) + it "returns the public and protected methods of self if include_super is false" do + methods = ModuleSpecs::Parent.instance_methods(false) + methods.should include(:protected_parent, :public_parent) - methods = ModuleSpecs::Child.instance_methods(false) - methods.should include(:protected_child, :public_child) - end + methods = ModuleSpecs::Child.instance_methods(false) + methods.should include(:protected_child, :public_child) + end - it "returns the public and protected methods of self and it's ancestors" do - methods = ModuleSpecs::Basic.instance_methods - methods.should include(:protected_module, :public_module) + it "returns the public and protected methods of self and it's ancestors" do + methods = ModuleSpecs::Basic.instance_methods + methods.should include(:protected_module, :public_module) - methods = ModuleSpecs::Super.instance_methods - methods.should include(:protected_module, :protected_super_module, - :public_module, :public_super_module) - end + methods = ModuleSpecs::Super.instance_methods + methods.should include(:protected_module, :protected_super_module, + :public_module, :public_super_module) + end - it "makes a private Object instance method public in Kernel" do - methods = Kernel.instance_methods - methods.should include(:module_specs_private_method_on_object_for_kernel_public) - methods = Object.instance_methods - methods.should_not include(:module_specs_private_method_on_object_for_kernel_public) - end + it "makes a private Object instance method public in Kernel" do + methods = Kernel.instance_methods + methods.should include(:module_specs_private_method_on_object_for_kernel_public) + methods = Object.instance_methods + methods.should_not include(:module_specs_private_method_on_object_for_kernel_public) end end diff --git a/spec/ruby/core/module/module_function_spec.rb b/spec/ruby/core/module/module_function_spec.rb index de904a5e70..55404a8ebe 100644 --- a/spec/ruby/core/module/module_function_spec.rb +++ b/spec/ruby/core/module/module_function_spec.rb @@ -235,28 +235,14 @@ def test2() end m.respond_to?(:test1).should == true end - ruby_version_is "" ... "2.1" do - it "affects definitions when inside an eval even if the definitions are outside of it" do - m = Module.new { - eval "module_function" - - def test1() end - } - - m.respond_to?(:test1).should be_true - end - end - - ruby_version_is "2.1" do - it "does not affect definitions when inside an eval even if the definitions are outside of it" do - m = Module.new { - eval "module_function" + it "does not affect definitions when inside an eval even if the definitions are outside of it" do + m = Module.new { + eval "module_function" - def test1() end - } + def test1() end + } - m.respond_to?(:test1).should be_false - end + m.respond_to?(:test1).should be_false end it "functions normally if both toggle and definitions inside a eval" do diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb index cf61102b68..303ae0646b 100644 --- a/spec/ruby/core/module/name_spec.rb +++ b/spec/ruby/core/module/name_spec.rb @@ -2,42 +2,20 @@ require File.expand_path('../fixtures/module', __FILE__) describe "Module#name" do - ruby_version_is ""..."1.9" do - it "is an empty string for an anonymous module" do - Module.new.name.should == "" - end - - it "is an empty string when assigning to a constant in an anonymous module" do - m = Module.new - m::N = Module.new - m::N.name.should == "" - end - - ruby_bug "http://bugs.ruby-lang.org/issues/6078", "2.0.0" do - it "is an empty string for a nested module created with the module keyword" do - m = Module.new - module m::N; end - m::N.name.should == "" - end - end + it "is nil for an anonymous module" do + Module.new.name.should be_nil end - ruby_version_is "1.9" do - it "is nil for an anonymous module" do - Module.new.name.should be_nil - end - - it "is nil when assigned to a constant in an anonymous module" do - m = Module.new - m::N = Module.new - m::N.name.should be_nil - end + it "is nil when assigned to a constant in an anonymous module" do + m = Module.new + m::N = Module.new + m::N.name.should be_nil + end - it "is nil for a nested module created with the module keyword" do - m = Module.new - module m::N; end - m::N.name.should =~ /#::N/ - end + it "is nil for a nested module created with the module keyword" do + m = Module.new + module m::N; end + m::N.name.should =~ /#::N/ end it "is set when opened with the module keyword" do @@ -62,26 +40,23 @@ module m::N; end m.name.should == "ModuleSpecs::Anonymous::B" end - ruby_version_is "1.9" do - ruby_bug "http://bugs.ruby-lang.org/issues/6067", "2.0.0" do - it "is set with a conditional assignment to a nested constant" do - eval("ModuleSpecs::Anonymous::F ||= Module.new") - ModuleSpecs::Anonymous::F.name.should == "ModuleSpecs::Anonymous::F" - end - end + # http://bugs.ruby-lang.org/issues/6067 + it "is set with a conditional assignment to a nested constant" do + eval("ModuleSpecs::Anonymous::F ||= Module.new") + ModuleSpecs::Anonymous::F.name.should == "ModuleSpecs::Anonymous::F" + end - it "is set with a conditional assignment to a constant" do - module ModuleSpecs::Anonymous - D ||= Module.new - end - ModuleSpecs::Anonymous::D.name.should == "ModuleSpecs::Anonymous::D" + it "is set with a conditional assignment to a constant" do + module ModuleSpecs::Anonymous + D ||= Module.new end + ModuleSpecs::Anonymous::D.name.should == "ModuleSpecs::Anonymous::D" + end - # http://redmine.ruby-lang.org/issues/show/1833 - it "preserves the encoding in which the class was defined" do - require fixture(__FILE__, "name") - ModuleSpecs::NameEncoding.new.name.encoding.should == Encoding::UTF_8 - end + # http://redmine.ruby-lang.org/issues/show/1833 + it "preserves the encoding in which the class was defined" do + require fixture(__FILE__, "name") + ModuleSpecs::NameEncoding.new.name.encoding.should == Encoding::UTF_8 end it "is set when the anonymous outer module name is set" do diff --git a/spec/ruby/core/module/prepend_features_spec.rb b/spec/ruby/core/module/prepend_features_spec.rb index edc78a77f7..02071f6792 100644 --- a/spec/ruby/core/module/prepend_features_spec.rb +++ b/spec/ruby/core/module/prepend_features_spec.rb @@ -1,58 +1,56 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "2.0" do - describe "Module#prepend_features" do - it "is a private method" do - Module.should have_private_instance_method(:prepend_features, true) - end +describe "Module#prepend_features" do + it "is a private method" do + Module.should have_private_instance_method(:prepend_features, true) + end - it "gets called when self is included in another module/class" do - ScratchPad.record [] + it "gets called when self is included in another module/class" do + ScratchPad.record [] - m = Module.new do - def self.prepend_features(mod) - ScratchPad << mod - end + m = Module.new do + def self.prepend_features(mod) + ScratchPad << mod end - - c = Class.new do - prepend m - end - - ScratchPad.recorded.should == [c] end - it "raises an ArgumentError on a cyclic prepend" do - lambda { - ModuleSpecs::CyclicPrepend.send(:prepend_features, ModuleSpecs::CyclicPrepend) - }.should raise_error(ArgumentError) + c = Class.new do + prepend m end - it "copies own tainted status to the given module" do - other = Module.new - Module.new.taint.send :prepend_features, other - other.tainted?.should be_true - end + ScratchPad.recorded.should == [c] + end - it "copies own untrusted status to the given module" do - other = Module.new - Module.new.untrust.send :prepend_features, other - other.untrusted?.should be_true - end + it "raises an ArgumentError on a cyclic prepend" do + lambda { + ModuleSpecs::CyclicPrepend.send(:prepend_features, ModuleSpecs::CyclicPrepend) + }.should raise_error(ArgumentError) + end - describe "on Class" do - ruby_bug "GH-376", "2.0.0.312" do - it "is undefined" do - Class.should_not have_private_instance_method(:prepend_features, true) - end - end + it "copies own tainted status to the given module" do + other = Module.new + Module.new.taint.send :prepend_features, other + other.tainted?.should be_true + end + + it "copies own untrusted status to the given module" do + other = Module.new + Module.new.untrust.send :prepend_features, other + other.untrusted?.should be_true + end - it "raises a TypeError if calling after rebinded to Class" do - lambda { - Module.instance_method(:prepend_features).bind(Class.new).call Module.new - }.should raise_error(TypeError) + describe "on Class" do + ruby_bug "GH-376", "2.0.0.312" do + it "is undefined" do + Class.should_not have_private_instance_method(:prepend_features, true) end end + + it "raises a TypeError if calling after rebinded to Class" do + lambda { + Module.instance_method(:prepend_features).bind(Class.new).call Module.new + }.should raise_error(TypeError) + end end end diff --git a/spec/ruby/core/module/prepend_spec.rb b/spec/ruby/core/module/prepend_spec.rb index 15d4e7ba39..87d44a07b3 100644 --- a/spec/ruby/core/module/prepend_spec.rb +++ b/spec/ruby/core/module/prepend_spec.rb @@ -1,239 +1,229 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "2.0" do - describe "Module#prepend" do - ruby_version_is "" ... "2.1" do - it "is a private method" do - Module.should have_private_instance_method(:prepend, true) +describe "Module#prepend" do + it "is a public method" do + Module.should have_public_instance_method(:prepend, true) + end + + it "calls #prepend_features(self) in reversed order on each module" do + ScratchPad.record [] + + m = Module.new do + def self.prepend_features(mod) + ScratchPad << [ self, mod ] end end - ruby_version_is "2.1" do - it "is a public method" do - Module.should have_public_instance_method(:prepend, true) + m2 = Module.new do + def self.prepend_features(mod) + ScratchPad << [ self, mod ] end end - it "calls #prepend_features(self) in reversed order on each module" do - ScratchPad.record [] - - m = Module.new do - def self.prepend_features(mod) - ScratchPad << [ self, mod ] - end + m3 = Module.new do + def self.prepend_features(mod) + ScratchPad << [ self, mod ] end + end - m2 = Module.new do - def self.prepend_features(mod) - ScratchPad << [ self, mod ] - end - end + c = Class.new { prepend(m, m2, m3) } - m3 = Module.new do - def self.prepend_features(mod) - ScratchPad << [ self, mod ] - end - end + ScratchPad.recorded.should == [ [ m3, c], [ m2, c ], [ m, c ] ] + end - c = Class.new { prepend(m, m2, m3) } + it "raises a TypeError when the argument is not a Module" do + lambda { ModuleSpecs::Basic.send(:prepend, Class.new) }.should raise_error(TypeError) + end - ScratchPad.recorded.should == [ [ m3, c], [ m2, c ], [ m, c ] ] - end + it "does not raise a TypeError when the argument is an instance of a subclass of Module" do + lambda { ModuleSpecs::SubclassSpec.send(:prepend, ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError) + end - it "raises a TypeError when the argument is not a Module" do - lambda { ModuleSpecs::Basic.send(:prepend, Class.new) }.should raise_error(TypeError) - end + it "does not import constants" do + m1 = Module.new { A = 1 } + m2 = Module.new { prepend(m1) } + m1.constants.should_not include(:A) + end - it "does not raise a TypeError when the argument is an instance of a subclass of Module" do - lambda { ModuleSpecs::SubclassSpec.send(:prepend, ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError) - end + it "imports instance methods" do + Module.new { prepend ModuleSpecs::A }.instance_methods.should include(:ma) + end - it "does not import constants" do - m1 = Module.new { A = 1 } - m2 = Module.new { prepend(m1) } - m1.constants.should_not include(:A) - end + it "does not import methods to modules and classes" do + Module.new { prepend ModuleSpecs::A }.methods.should_not include(:ma) + end - it "imports instance methods" do - Module.new { prepend ModuleSpecs::A }.instance_methods.should include(:ma) - end + it "allows wrapping methods" do + m = Module.new { def calc(x) super + 3 end } + c = Class.new { def calc(x) x*2 end } + c.send(:prepend, m) + c.new.calc(1).should == 5 + end - it "does not import methods to modules and classes" do - Module.new { prepend ModuleSpecs::A }.methods.should_not include(:ma) - end + it "also prepends included modules" do + a = Module.new { def calc(x) x end } + b = Module.new { include a } + c = Class.new { prepend b } + c.new.calc(1).should == 1 + end - it "allows wrapping methods" do - m = Module.new { def calc(x) super + 3 end } - c = Class.new { def calc(x) x*2 end } - c.send(:prepend, m) - c.new.calc(1).should == 5 - end + it "prepends multiple modules in the right order" do + m1 = Module.new { def chain; super << :m1; end } + m2 = Module.new { def chain; super << :m2; end; prepend(m1) } + c = Class.new { def chain; [:c]; end; prepend(m2) } + c.new.chain.should == [:c, :m2, :m1] + end - it "also prepends included modules" do - a = Module.new { def calc(x) x end } - b = Module.new { include a } - c = Class.new { prepend b } - c.new.calc(1).should == 1 - end + it "includes prepended modules in ancestors" do + m = Module.new + Class.new { prepend(m) }.ancestors.should include(m) + end - it "prepends multiple modules in the right order" do - m1 = Module.new { def chain; super << :m1; end } - m2 = Module.new { def chain; super << :m2; end; prepend(m1) } - c = Class.new { def chain; [:c]; end; prepend(m2) } - c.new.chain.should == [:c, :m2, :m1] - end + it "sees an instance of a prepended class as kind of the prepended module" do + m = Module.new + c = Class.new { prepend(m) } + c.new.should be_kind_of(m) + end - it "includes prepended modules in ancestors" do - m = Module.new - Class.new { prepend(m) }.ancestors.should include(m) - end + it "keeps the module in the chain when dupping the class" do + m = Module.new + c = Class.new { prepend(m) } + c.dup.new.should be_kind_of(m) + end - it "sees an instance of a prepended class as kind of the prepended module" do - m = Module.new - c = Class.new { prepend(m) } - c.new.should be_kind_of(m) - end + it "keeps the module in the chain when dupping an intermediate module" do + m1 = Module.new { def calc(x) x end } + m2 = Module.new { prepend(m1) } + c1 = Class.new { prepend(m2) } + c2 = Class.new { prepend(m2.dup) } + c1.new.should be_kind_of(m1) + c2.new.should be_kind_of(m1) + end - it "keeps the module in the chain when dupping the class" do - m = Module.new - c = Class.new { prepend(m) } - c.dup.new.should be_kind_of(m) - end + it "depends on prepend_features to add the module" do + m = Module.new { def self.prepend_features(mod) end } + Class.new { prepend(m) }.ancestors.should_not include(m) + end - it "keeps the module in the chain when dupping an intermediate module" do - m1 = Module.new { def calc(x) x end } - m2 = Module.new { prepend(m1) } - c1 = Class.new { prepend(m2) } - c2 = Class.new { prepend(m2.dup) } - c1.new.should be_kind_of(m1) - c2.new.should be_kind_of(m1) - end + it "inserts a later prepended module into the chain" do + m1 = Module.new { def chain; super << :m1; end } + m2 = Module.new { def chain; super << :m2; end } + c1 = Class.new { def chain; [:c1]; end; prepend m1 } + c2 = Class.new(c1) { def chain; super << :c2; end } + c2.new.chain.should == [:c1, :m1, :c2] + c1.send(:prepend, m2) + c2.new.chain.should == [:c1, :m1, :m2, :c2] + end - it "depends on prepend_features to add the module" do - m = Module.new { def self.prepend_features(mod) end } - Class.new { prepend(m) }.ancestors.should_not include(m) + it "works with subclasses" do + m = Module.new do + def chain + super << :module + end end - it "inserts a later prepended module into the chain" do - m1 = Module.new { def chain; super << :m1; end } - m2 = Module.new { def chain; super << :m2; end } - c1 = Class.new { def chain; [:c1]; end; prepend m1 } - c2 = Class.new(c1) { def chain; super << :c2; end } - c2.new.chain.should == [:c1, :m1, :c2] - c1.send(:prepend, m2) - c2.new.chain.should == [:c1, :m1, :m2, :c2] + c = Class.new do + prepend m + def chain + [:class] + end end - it "works with subclasses" do - m = Module.new do - def chain - super << :module - end + s = Class.new(c) do + def chain + super << :subclass end + end - c = Class.new do - prepend m - def chain - [:class] - end - end + s.new.chain.should == [:class, :module, :subclass] + end - s = Class.new(c) do - def chain - super << :subclass - end + it "throws a NoMethodError when there is no more superclass" do + m = Module.new do + def chain + super << :module end - - s.new.chain.should == [:class, :module, :subclass] end - it "throws a NoMethodError when there is no more superclass" do - m = Module.new do - def chain - super << :module - end + c = Class.new do + prepend m + def chain + super << :class end - - c = Class.new do - prepend m - def chain - super << :class - end - end - lambda { c.new.chain }.should raise_error(NoMethodError) end + lambda { c.new.chain }.should raise_error(NoMethodError) + end - it "calls prepended after prepend_features" do - ScratchPad.record [] + it "calls prepended after prepend_features" do + ScratchPad.record [] - m = Module.new do - def self.prepend_features(klass) - ScratchPad << [:prepend_features, klass] - end - def self.prepended(klass) - ScratchPad << [:prepended, klass] - end + m = Module.new do + def self.prepend_features(klass) + ScratchPad << [:prepend_features, klass] + end + def self.prepended(klass) + ScratchPad << [:prepended, klass] end - - c = Class.new { prepend(m) } - ScratchPad.recorded.should == [[:prepend_features, c], [:prepended, c]] end - it "detects cyclic prepends" do - lambda { - module ModuleSpecs::P - prepend ModuleSpecs::P - end - }.should raise_error(ArgumentError) - end + c = Class.new { prepend(m) } + ScratchPad.recorded.should == [[:prepend_features, c], [:prepended, c]] + end - it "accepts no-arguments" do - lambda { - Module.new do - prepend - end - }.should_not raise_error - end + it "detects cyclic prepends" do + lambda { + module ModuleSpecs::P + prepend ModuleSpecs::P + end + }.should raise_error(ArgumentError) + end - it "returns the class it's included into" do - m = Module.new - r = nil - c = Class.new { r = prepend m } - r.should == c - end + it "accepts no-arguments" do + lambda { + Module.new do + prepend + end + }.should_not raise_error + end - it "clears any caches" do - module ModuleSpecs::M3 - module PM1 - def foo - :m1 - end - end + it "returns the class it's included into" do + m = Module.new + r = nil + c = Class.new { r = prepend m } + r.should == c + end - module PM2 - def foo - :m2 - end + it "clears any caches" do + module ModuleSpecs::M3 + module PM1 + def foo + :m1 end + end - class PC - prepend PM1 - - def get - foo - end + module PM2 + def foo + :m2 end + end - c = PC.new - c.get.should == :m1 + class PC + prepend PM1 - class PC - prepend PM2 + def get + foo end + end - c.get.should == :m2 + c = PC.new + c.get.should == :m1 + + class PC + prepend PM2 end + + c.get.should == :m2 end end end diff --git a/spec/ruby/core/module/prepended_spec.rb b/spec/ruby/core/module/prepended_spec.rb index 5ba4146015..d1e267b0c6 100644 --- a/spec/ruby/core/module/prepended_spec.rb +++ b/spec/ruby/core/module/prepended_spec.rb @@ -2,10 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "2.0" do - describe "Module#prepended" do - it "is a private method" do - Module.should have_private_instance_method(:prepended, true) - end +describe "Module#prepended" do + it "is a private method" do + Module.should have_private_instance_method(:prepended, true) end end diff --git a/spec/ruby/core/module/private_constant_spec.rb b/spec/ruby/core/module/private_constant_spec.rb index c429053921..7b1382e10b 100644 --- a/spec/ruby/core/module/private_constant_spec.rb +++ b/spec/ruby/core/module/private_constant_spec.rb @@ -1,28 +1,26 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9.3" do - describe "Module#private_constant" do - it "can only be passed constant names defined in the target (self) module" do - cls1 = Class.new - cls1.const_set :Foo, true - cls2 = Class.new(cls1) - - lambda do - cls2.send :private_constant, :Foo - end.should raise_error(NameError) - end - - ruby_bug "[ruby-list:48559]", "1.9.3" do - it "accepts multiple names" do - mod = Module.new - mod.const_set :Foo, true - mod.const_set :Bar, true - - mod.send :private_constant, :Foo, :Bar - - lambda {mod::Foo}.should raise_error(NameError) - lambda {mod::Bar}.should raise_error(NameError) - end +describe "Module#private_constant" do + it "can only be passed constant names defined in the target (self) module" do + cls1 = Class.new + cls1.const_set :Foo, true + cls2 = Class.new(cls1) + + lambda do + cls2.send :private_constant, :Foo + end.should raise_error(NameError) + end + + ruby_bug "[ruby-list:48559]", "1.9.3" do + it "accepts multiple names" do + mod = Module.new + mod.const_set :Foo, true + mod.const_set :Bar, true + + mod.send :private_constant, :Foo, :Bar + + lambda {mod::Foo}.should raise_error(NameError) + lambda {mod::Bar}.should raise_error(NameError) end end end diff --git a/spec/ruby/core/module/private_method_defined_spec.rb b/spec/ruby/core/module/private_method_defined_spec.rb index 7475af3c99..389e692616 100644 --- a/spec/ruby/core/module/private_method_defined_spec.rb +++ b/spec/ruby/core/module/private_method_defined_spec.rb @@ -31,20 +31,10 @@ ModuleSpecs::CountsMixin.private_method_defined?(:private_3).should == true end - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if passed a Fixnum" do - lambda { - ModuleSpecs::CountsMixin.private_method_defined?(1) - }.should raise_error(ArgumentError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if passed a Fixnum" do - lambda { - ModuleSpecs::CountsMixin.private_method_defined?(1) - }.should raise_error(TypeError) - end + it "raises a TypeError if passed a Fixnum" do + lambda { + ModuleSpecs::CountsMixin.private_method_defined?(1) + }.should raise_error(TypeError) end it "raises a TypeError if passed nil" do diff --git a/spec/ruby/core/module/protected_instance_methods_spec.rb b/spec/ruby/core/module/protected_instance_methods_spec.rb index 167a042c7a..874a15fca6 100644 --- a/spec/ruby/core/module/protected_instance_methods_spec.rb +++ b/spec/ruby/core/module/protected_instance_methods_spec.rb @@ -4,48 +4,24 @@ # TODO: rewrite describe "Module#protected_instance_methods" do - ruby_version_is ""..."1.9" do - it "returns a list of protected methods in module and its ancestors" do - methods = ModuleSpecs::CountsMixin.protected_instance_methods - methods.should include('protected_3') - - methods = ModuleSpecs::CountsParent.protected_instance_methods - methods.should include('protected_3') - methods.should include('protected_2') - - methods = ModuleSpecs::CountsChild.protected_instance_methods - methods.should include('protected_3') - methods.should include('protected_2') - methods.should include('protected_1') - end - - it "when passed false as a parameter, should return only methods defined in that module" do - ModuleSpecs::CountsMixin.protected_instance_methods(false).should == ['protected_3'] - ModuleSpecs::CountsParent.protected_instance_methods(false).should == ['protected_2'] - ModuleSpecs::CountsChild.protected_instance_methods(false).should == ['protected_1'] - end + it "returns a list of protected methods in module and its ancestors" do + methods = ModuleSpecs::CountsMixin.protected_instance_methods + methods.should include(:protected_3) + + methods = ModuleSpecs::CountsParent.protected_instance_methods + methods.should include(:protected_3) + methods.should include(:protected_2) + + methods = ModuleSpecs::CountsChild.protected_instance_methods + methods.should include(:protected_3) + methods.should include(:protected_2) + methods.should include(:protected_1) end - ruby_version_is "1.9" do - it "returns a list of protected methods in module and its ancestors" do - methods = ModuleSpecs::CountsMixin.protected_instance_methods - methods.should include(:protected_3) - - methods = ModuleSpecs::CountsParent.protected_instance_methods - methods.should include(:protected_3) - methods.should include(:protected_2) - - methods = ModuleSpecs::CountsChild.protected_instance_methods - methods.should include(:protected_3) - methods.should include(:protected_2) - methods.should include(:protected_1) - end - - it "when passed false as a parameter, should return only methods defined in that module" do - ModuleSpecs::CountsMixin.protected_instance_methods(false).should == [:protected_3] - ModuleSpecs::CountsParent.protected_instance_methods(false).should == [:protected_2] - ModuleSpecs::CountsChild.protected_instance_methods(false).should == [:protected_1] - end + it "when passed false as a parameter, should return only methods defined in that module" do + ModuleSpecs::CountsMixin.protected_instance_methods(false).should == [:protected_3] + ModuleSpecs::CountsParent.protected_instance_methods(false).should == [:protected_2] + ModuleSpecs::CountsChild.protected_instance_methods(false).should == [:protected_1] end it "default list should be the same as passing true as an argument" do diff --git a/spec/ruby/core/module/protected_method_defined_spec.rb b/spec/ruby/core/module/protected_method_defined_spec.rb index f2c5849e75..61617a0b31 100644 --- a/spec/ruby/core/module/protected_method_defined_spec.rb +++ b/spec/ruby/core/module/protected_method_defined_spec.rb @@ -31,49 +31,22 @@ ModuleSpecs::CountsMixin.protected_method_defined?(:protected_3).should == true end - not_compliant_on :rubinius do - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if passed a Fixnum" do - lambda { - ModuleSpecs::CountsMixin.protected_method_defined?(1) - }.should raise_error(ArgumentError) - end + it "raises a TypeError if not passed a Symbol" do + lambda { + ModuleSpecs::CountsMixin.protected_method_defined?(1) + }.should raise_error(TypeError) + lambda { + ModuleSpecs::CountsMixin.protected_method_defined?(nil) + }.should raise_error(TypeError) + lambda { + ModuleSpecs::CountsMixin.protected_method_defined?(false) + }.should raise_error(TypeError) - it "raises a TypeError if not passed a Symbol" do - lambda { - ModuleSpecs::CountsMixin.protected_method_defined?(nil) - }.should raise_error(TypeError) - lambda { - ModuleSpecs::CountsMixin.protected_method_defined?(false) - }.should raise_error(TypeError) - - sym = mock('symbol') - def sym.to_sym() :protected_3 end - lambda { - ModuleSpecs::CountsMixin.protected_method_defined?(sym) - }.should raise_error(TypeError) - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if not passed a Symbol" do - lambda { - ModuleSpecs::CountsMixin.protected_method_defined?(1) - }.should raise_error(TypeError) - lambda { - ModuleSpecs::CountsMixin.protected_method_defined?(nil) - }.should raise_error(TypeError) - lambda { - ModuleSpecs::CountsMixin.protected_method_defined?(false) - }.should raise_error(TypeError) - - sym = mock('symbol') - def sym.to_sym() :protected_3 end - lambda { - ModuleSpecs::CountsMixin.protected_method_defined?(sym) - }.should raise_error(TypeError) - end - end + sym = mock('symbol') + def sym.to_sym() :protected_3 end + lambda { + ModuleSpecs::CountsMixin.protected_method_defined?(sym) + }.should raise_error(TypeError) end it "accepts any object that is a String type" do diff --git a/spec/ruby/core/module/public_constant_spec.rb b/spec/ruby/core/module/public_constant_spec.rb index b193d4cdee..881bf4ea9b 100644 --- a/spec/ruby/core/module/public_constant_spec.rb +++ b/spec/ruby/core/module/public_constant_spec.rb @@ -1,31 +1,28 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9.3" do - describe "Module#public_constant" do - it "can only be passed constant names defined in the target (self) module" do - cls1 = Class.new - cls1.const_set :Foo, true - cls2 = Class.new(cls1) - - lambda do - cls2.send :public_constant, :Foo - end.should raise_error(NameError) - end - - ruby_bug "[ruby-list:48558]", "1.9.3" do - it "accepts multiple names" do - mod = Module.new - mod.const_set :Foo, true - mod.const_set :Bar, true - - mod.send :private_constant, :Foo - mod.send :private_constant, :Bar - - mod.send :public_constant, :Foo, :Bar - - mod::Foo.should == true - mod::Bar.should == true - end - end +describe "Module#public_constant" do + it "can only be passed constant names defined in the target (self) module" do + cls1 = Class.new + cls1.const_set :Foo, true + cls2 = Class.new(cls1) + + lambda do + cls2.send :public_constant, :Foo + end.should raise_error(NameError) + end + + # [ruby-list:48558] + it "accepts multiple names" do + mod = Module.new + mod.const_set :Foo, true + mod.const_set :Bar, true + + mod.send :private_constant, :Foo + mod.send :private_constant, :Bar + + mod.send :public_constant, :Foo, :Bar + + mod::Foo.should == true + mod::Bar.should == true end end diff --git a/spec/ruby/core/module/public_instance_method_spec.rb b/spec/ruby/core/module/public_instance_method_spec.rb index 6ced1f3763..268b988f8f 100644 --- a/spec/ruby/core/module/public_instance_method_spec.rb +++ b/spec/ruby/core/module/public_instance_method_spec.rb @@ -1,67 +1,65 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "1.9" do - describe "Module#public_instance_method" do - it "is a public method" do - Module.should have_public_instance_method(:public_instance_method, false) - end - - it "requires an argument" do - Module.new.method(:public_instance_method).arity.should == 1 - end +describe "Module#public_instance_method" do + it "is a public method" do + Module.should have_public_instance_method(:public_instance_method, false) + end - describe "when given a public method name" do - it "returns an UnboundMethod corresponding to the defined Module" do - ret = ModuleSpecs::Super.public_instance_method(:public_module) - ret.should be_an_instance_of(UnboundMethod) - ret.owner.should equal(ModuleSpecs::Basic) + it "requires an argument" do + Module.new.method(:public_instance_method).arity.should == 1 + end - ret = ModuleSpecs::Super.public_instance_method(:public_super_module) - ret.should be_an_instance_of(UnboundMethod) - ret.owner.should equal(ModuleSpecs::Super) - end + describe "when given a public method name" do + it "returns an UnboundMethod corresponding to the defined Module" do + ret = ModuleSpecs::Super.public_instance_method(:public_module) + ret.should be_an_instance_of(UnboundMethod) + ret.owner.should equal(ModuleSpecs::Basic) - it "accepts if the name is a Symbol or String" do - ret = ModuleSpecs::Basic.public_instance_method(:public_module) - ModuleSpecs::Basic.public_instance_method("public_module").should == ret - end + ret = ModuleSpecs::Super.public_instance_method(:public_super_module) + ret.should be_an_instance_of(UnboundMethod) + ret.owner.should equal(ModuleSpecs::Super) end - it "raises a TypeError when given a name is not Symbol or String" do - lambda { Module.new.public_instance_method(nil) }.should raise_error(TypeError) + it "accepts if the name is a Symbol or String" do + ret = ModuleSpecs::Basic.public_instance_method(:public_module) + ModuleSpecs::Basic.public_instance_method("public_module").should == ret end + end - it "raises a NameError when given a protected method name" do - lambda do - ModuleSpecs::Basic.public_instance_method(:protected_module) - end.should raise_exception(NameError) - end + it "raises a TypeError when given a name is not Symbol or String" do + lambda { Module.new.public_instance_method(nil) }.should raise_error(TypeError) + end - it "raises a NameError if the method is private" do - lambda do - ModuleSpecs::Basic.public_instance_method(:private_module) - end.should raise_exception(NameError) - end + it "raises a NameError when given a protected method name" do + lambda do + ModuleSpecs::Basic.public_instance_method(:protected_module) + end.should raise_exception(NameError) + end - it "raises a NameError if the method has been undefined" do - lambda do - ModuleSpecs::Parent.public_instance_method(:undefed_method) - end.should raise_exception(NameError) - end + it "raises a NameError if the method is private" do + lambda do + ModuleSpecs::Basic.public_instance_method(:private_module) + end.should raise_exception(NameError) + end - it "raises a NameError if the method does not exist" do - lambda do - Module.new.public_instance_method(:missing) - end.should raise_exception(NameError) - end + it "raises a NameError if the method has been undefined" do + lambda do + ModuleSpecs::Parent.public_instance_method(:undefed_method) + end.should raise_exception(NameError) + end + + it "raises a NameError if the method does not exist" do + lambda do + Module.new.public_instance_method(:missing) + end.should raise_exception(NameError) + end - it "sets the NameError#name attribute to the name of the missing method" do - begin - Module.new.public_instance_method(:missing) - rescue NameError => e - e.name.should == :missing - end + it "sets the NameError#name attribute to the name of the missing method" do + begin + Module.new.public_instance_method(:missing) + rescue NameError => e + e.name.should == :missing end end end diff --git a/spec/ruby/core/module/public_instance_methods_spec.rb b/spec/ruby/core/module/public_instance_methods_spec.rb index 1ee44ee807..6ca89b791c 100644 --- a/spec/ruby/core/module/public_instance_methods_spec.rb +++ b/spec/ruby/core/module/public_instance_methods_spec.rb @@ -3,78 +3,39 @@ require File.expand_path('../../../fixtures/reflection', __FILE__) # TODO: rewrite -# Before MRI 1.9 #public_instance_methods returned an Array of Strings -ruby_version_is ""..."1.9" do - describe "Module#public_instance_methods" do - it "returns a list of public methods in module and its ancestors" do - methods = ModuleSpecs::CountsMixin.public_instance_methods - methods.should include('public_3') - - methods = ModuleSpecs::CountsParent.public_instance_methods - methods.should include('public_3') - methods.should include('public_2') - - methods = ModuleSpecs::CountsChild.public_instance_methods - methods.should include('public_3') - methods.should include('public_2') - methods.should include('public_1') - - methods = ModuleSpecs::Child2.public_instance_methods - methods.should include('foo') - end - - it "when passed false as a parameter, should return only methods defined in that module" do - ModuleSpecs::CountsMixin.public_instance_methods(false).should == ['public_3'] - ModuleSpecs::CountsParent.public_instance_methods(false).should == ['public_2'] - ModuleSpecs::CountsChild.public_instance_methods(false).should == ['public_1'] - end - - it "default list should be the same as passing true as an argument" do - ModuleSpecs::CountsMixin.public_instance_methods(true).should == - ModuleSpecs::CountsMixin.public_instance_methods - ModuleSpecs::CountsParent.public_instance_methods(true).should == - ModuleSpecs::CountsParent.public_instance_methods - ModuleSpecs::CountsChild.public_instance_methods(true).should == - ModuleSpecs::CountsChild.public_instance_methods - end - end -end - # As of MRI 1.9 #public_instance_methods returns an Array of Symbols -ruby_version_is "1.9" do - describe "Module#public_instance_methods" do - it "returns a list of public methods in module and its ancestors" do - methods = ModuleSpecs::CountsMixin.public_instance_methods - methods.should include(:public_3) +describe "Module#public_instance_methods" do + it "returns a list of public methods in module and its ancestors" do + methods = ModuleSpecs::CountsMixin.public_instance_methods + methods.should include(:public_3) - methods = ModuleSpecs::CountsParent.public_instance_methods - methods.should include(:public_3) - methods.should include(:public_2) + methods = ModuleSpecs::CountsParent.public_instance_methods + methods.should include(:public_3) + methods.should include(:public_2) - methods = ModuleSpecs::CountsChild.public_instance_methods - methods.should include(:public_3) - methods.should include(:public_2) - methods.should include(:public_1) + methods = ModuleSpecs::CountsChild.public_instance_methods + methods.should include(:public_3) + methods.should include(:public_2) + methods.should include(:public_1) - methods = ModuleSpecs::Child2.public_instance_methods - methods.should include(:foo) - end + methods = ModuleSpecs::Child2.public_instance_methods + methods.should include(:foo) + end - it "when passed false as a parameter, should return only methods defined in that module" do - ModuleSpecs::CountsMixin.public_instance_methods(false).should == [:public_3] - ModuleSpecs::CountsParent.public_instance_methods(false).should == [:public_2] - ModuleSpecs::CountsChild.public_instance_methods(false).should == [:public_1] - end + it "when passed false as a parameter, should return only methods defined in that module" do + ModuleSpecs::CountsMixin.public_instance_methods(false).should == [:public_3] + ModuleSpecs::CountsParent.public_instance_methods(false).should == [:public_2] + ModuleSpecs::CountsChild.public_instance_methods(false).should == [:public_1] + end - it "default list should be the same as passing true as an argument" do - ModuleSpecs::CountsMixin.public_instance_methods(true).should == - ModuleSpecs::CountsMixin.public_instance_methods - ModuleSpecs::CountsParent.public_instance_methods(true).should == - ModuleSpecs::CountsParent.public_instance_methods - ModuleSpecs::CountsChild.public_instance_methods(true).should == - ModuleSpecs::CountsChild.public_instance_methods - end + it "default list should be the same as passing true as an argument" do + ModuleSpecs::CountsMixin.public_instance_methods(true).should == + ModuleSpecs::CountsMixin.public_instance_methods + ModuleSpecs::CountsParent.public_instance_methods(true).should == + ModuleSpecs::CountsParent.public_instance_methods + ModuleSpecs::CountsChild.public_instance_methods(true).should == + ModuleSpecs::CountsChild.public_instance_methods end end diff --git a/spec/ruby/core/module/public_method_defined_spec.rb b/spec/ruby/core/module/public_method_defined_spec.rb index 575460b8ae..6a2e5b7291 100644 --- a/spec/ruby/core/module/public_method_defined_spec.rb +++ b/spec/ruby/core/module/public_method_defined_spec.rb @@ -31,43 +31,16 @@ ModuleSpecs::CountsMixin.public_method_defined?(:public_3).should == true end - not_compliant_on :rubinius do - ruby_version_is ""..."1.9" do - it "raises an ArgumentError if called with a Fixnum" do - lambda { - ModuleSpecs::CountsMixin.public_method_defined?(1) - }.should raise_error(ArgumentError) - end - - it "raises a TypeError if not passed a Symbol" do - lambda { - ModuleSpecs::CountsMixin.public_method_defined?(nil) - }.should raise_error(TypeError) - lambda { - ModuleSpecs::CountsMixin.public_method_defined?(false) - }.should raise_error(TypeError) - - sym = mock('symbol') - def sym.to_sym() :public_3 end - lambda { - ModuleSpecs::CountsMixin.public_method_defined?(sym) - }.should raise_error(TypeError) - end - end - end - - ruby_version_is "1.9" do - it "raises a TypeError if not passed a Symbol" do - lambda { - ModuleSpecs::CountsMixin.public_method_defined?(1) - }.should raise_error(TypeError) - lambda { - ModuleSpecs::CountsMixin.public_method_defined?(nil) - }.should raise_error(TypeError) - lambda { - ModuleSpecs::CountsMixin.public_method_defined?(false) - }.should raise_error(TypeError) - end + it "raises a TypeError if not passed a Symbol" do + lambda { + ModuleSpecs::CountsMixin.public_method_defined?(1) + }.should raise_error(TypeError) + lambda { + ModuleSpecs::CountsMixin.public_method_defined?(nil) + }.should raise_error(TypeError) + lambda { + ModuleSpecs::CountsMixin.public_method_defined?(false) + }.should raise_error(TypeError) end not_compliant_on :rubinius do diff --git a/spec/ruby/core/module/remove_class_variable_spec.rb b/spec/ruby/core/module/remove_class_variable_spec.rb index 7a80124bd2..adf2c1d1f8 100644 --- a/spec/ruby/core/module/remove_class_variable_spec.rb +++ b/spec/ruby/core/module/remove_class_variable_spec.rb @@ -38,15 +38,7 @@ lambda { ModuleSpecs::MVars.send(:remove_class_variable, :@@nonexisting_class_variable) }.should raise_error(NameError) end - ruby_version_is "" ... "1.9" do - it "is private" do - Module.should have_private_instance_method(:remove_class_variable) - end - end - - ruby_version_is "1.9" do - it "is public" do - Module.should_not have_private_instance_method(:remove_class_variable) - end + it "is public" do + Module.should_not have_private_instance_method(:remove_class_variable) end end diff --git a/spec/ruby/core/module/remove_const_spec.rb b/spec/ruby/core/module/remove_const_spec.rb index f9741c22a1..c681965d1e 100644 --- a/spec/ruby/core/module/remove_const_spec.rb +++ b/spec/ruby/core/module/remove_const_spec.rb @@ -69,16 +69,7 @@ lambda { ConstantSpecs.send :remove_const, name }.should raise_error(TypeError) end - ruby_version_is "" ... "1.9" do - it "is a private method" do - Module.private_methods.should include("remove_const") - end - end - - ruby_version_is "1.9" do - it "is a private method" do - Module.private_methods.should include(:remove_const) - end + it "is a private method" do + Module.private_methods.should include(:remove_const) end end - diff --git a/spec/ruby/core/module/remove_method_spec.rb b/spec/ruby/core/module/remove_method_spec.rb index 9c6e8fcd50..1ed817df83 100644 --- a/spec/ruby/core/module/remove_method_spec.rb +++ b/spec/ruby/core/module/remove_method_spec.rb @@ -83,24 +83,12 @@ class Third < ModuleSpecs::Second @frozen = @module.dup.freeze end - ruby_version_is "" ... "1.9" do - it "raises a TypeError when passed a name" do - lambda { @frozen.send :remove_method, :method_to_remove }.should raise_error(TypeError) - end - - it "raises a TypeError when passed a missing name" do - lambda { @frozen.send :remove_method, :not_exist }.should raise_error(TypeError) - end + it "raises a RuntimeError when passed a name" do + lambda { @frozen.send :remove_method, :method_to_remove }.should raise_error(RuntimeError) end - ruby_version_is "1.9" do - it "raises a RuntimeError when passed a name" do - lambda { @frozen.send :remove_method, :method_to_remove }.should raise_error(RuntimeError) - end - - it "raises a RuntimeError when passed a missing name" do - lambda { @frozen.send :remove_method, :not_exist }.should raise_error(RuntimeError) - end + it "raises a RuntimeError when passed a missing name" do + lambda { @frozen.send :remove_method, :not_exist }.should raise_error(RuntimeError) end it "raises a TypeError when passed a not name" do diff --git a/spec/ruby/core/module/shared/set_visibility.rb b/spec/ruby/core/module/shared/set_visibility.rb index e79849419d..755329e89f 100644 --- a/spec/ruby/core/module/shared/set_visibility.rb +++ b/spec/ruby/core/module/shared/set_visibility.rb @@ -81,32 +81,17 @@ def test1() end mod.should send(:"have_#{@method}_instance_method", :test1, false) end - ruby_version_is "" ... "2.1" do - it "affects method definitions when itself is inside an eval and method definitions are outside" do - visibility = @method - mod = Module.new { - eval visibility.to_s - - def test1() end - } - - mod.should send(:"have_#{@method}_instance_method", :test1, false) - end - end - - ruby_version_is "2.1" do - it "does not affect method definitions when itself is inside an eval and method definitions are outside" do - visibility = @method - initialized_visibility = [:public, :protected, :private].find {|sym| sym != visibility } - mod = Module.new { - send initialized_visibility - eval visibility.to_s + it "does not affect method definitions when itself is inside an eval and method definitions are outside" do + visibility = @method + initialized_visibility = [:public, :protected, :private].find {|sym| sym != visibility } + mod = Module.new { + send initialized_visibility + eval visibility.to_s - def test1() end - } + def test1() end + } - mod.should send(:"have_#{initialized_visibility}_instance_method", :test1, false) - end + mod.should send(:"have_#{initialized_visibility}_instance_method", :test1, false) end it "affects evaled method definitions when itself is outside the eval" do diff --git a/spec/ruby/core/module/undef_method_spec.rb b/spec/ruby/core/module/undef_method_spec.rb index 95dccc8c80..44f5986fd9 100644 --- a/spec/ruby/core/module/undef_method_spec.rb +++ b/spec/ruby/core/module/undef_method_spec.rb @@ -57,24 +57,12 @@ class Descendant < Ancestor @frozen = @module.dup.freeze end - ruby_version_is "" ... "1.9" do - it "raises a TypeError when passed a name" do - lambda { @frozen.send :undef_method, :method_to_undef }.should raise_error(TypeError) - end - - it "raises a TypeError when passed a missing name" do - lambda { @frozen.send :undef_method, :not_exist }.should raise_error(TypeError) - end + it "raises a RuntimeError when passed a name" do + lambda { @frozen.send :undef_method, :method_to_undef }.should raise_error(RuntimeError) end - ruby_version_is "1.9" do - it "raises a RuntimeError when passed a name" do - lambda { @frozen.send :undef_method, :method_to_undef }.should raise_error(RuntimeError) - end - - it "raises a RuntimeError when passed a missing name" do - lambda { @frozen.send :undef_method, :not_exist }.should raise_error(RuntimeError) - end + it "raises a RuntimeError when passed a missing name" do + lambda { @frozen.send :undef_method, :not_exist }.should raise_error(RuntimeError) end it "raises a TypeError when passed a not name" do diff --git a/spec/ruby/core/module/versions/define_method_1.9.rb b/spec/ruby/core/module/versions/define_method_1.9.rb deleted file mode 100644 index 9aebb37c5e..0000000000 --- a/spec/ruby/core/module/versions/define_method_1.9.rb +++ /dev/null @@ -1,31 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/classes', __FILE__) - -ruby_version_is "1.9" do - - describe "passed { |a, b = 1| } creates a method that" do - before :each do - @klass = Class.new do - define_method(:m) { |a, b = 1| return a, b } - end - end - - it "raises an ArgumentError when passed zero arguments" do - lambda { @klass.new.m }.should raise_error(ArgumentError) - end - - it "has a default value for b when passed one argument" do - @klass.new.m(1).should == [1, 1] - end - - it "overrides the default argument when passed two arguments" do - @klass.new.m(1, 2).should == [1, 2] - end - - it "raises an ArgumentError when passed three arguments" do - lambda { @klass.new.m(1, 2, 3) }.should raise_error(ArgumentError) - end - - end - -end diff --git a/spec/ruby/core/mutex/lock_spec.rb b/spec/ruby/core/mutex/lock_spec.rb index e6d447d563..32f61fabd3 100644 --- a/spec/ruby/core/mutex/lock_spec.rb +++ b/spec/ruby/core/mutex/lock_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/mutex/lock', __FILE__) -ruby_version_is "1.9" do - describe "Mutex#lock" do - it_behaves_like :mutex_lock, :lock - end +describe "Mutex#lock" do + it_behaves_like :mutex_lock, :lock end diff --git a/spec/ruby/core/mutex/locked_spec.rb b/spec/ruby/core/mutex/locked_spec.rb index 7ed988cc03..5a91fb7a9e 100644 --- a/spec/ruby/core/mutex/locked_spec.rb +++ b/spec/ruby/core/mutex/locked_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/mutex/locked', __FILE__) -ruby_version_is "1.9" do - describe "Mutex#locked?" do - it_behaves_like :mutex_locked, :locked? - end +describe "Mutex#locked?" do + it_behaves_like :mutex_locked, :locked? end diff --git a/spec/ruby/core/mutex/sleep_spec.rb b/spec/ruby/core/mutex/sleep_spec.rb index 396f107d4e..86b45d3ece 100644 --- a/spec/ruby/core/mutex/sleep_spec.rb +++ b/spec/ruby/core/mutex/sleep_spec.rb @@ -1,73 +1,71 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Mutex#sleep" do - describe "when not locked by the current thread" do - it "raises a ThreadError" do - m = Mutex.new - lambda { m.sleep }.should raise_error(ThreadError) - end - - it "raises an ArgumentError if passed a negative duration" do - m = Mutex.new - lambda { m.sleep -0.1 }.should raise_error(ArgumentError) - lambda { m.sleep -1 }.should raise_error(ArgumentError) - end +describe "Mutex#sleep" do + describe "when not locked by the current thread" do + it "raises a ThreadError" do + m = Mutex.new + lambda { m.sleep }.should raise_error(ThreadError) end it "raises an ArgumentError if passed a negative duration" do m = Mutex.new - m.lock lambda { m.sleep -0.1 }.should raise_error(ArgumentError) lambda { m.sleep -1 }.should raise_error(ArgumentError) end + end - it "pauses execution for approximately the duration requested" do - m = Mutex.new - m.lock - duration = 0.1 - start = Time.now - m.sleep duration - (Time.now - start).should be_close(duration, 0.1) - end + it "raises an ArgumentError if passed a negative duration" do + m = Mutex.new + m.lock + lambda { m.sleep -0.1 }.should raise_error(ArgumentError) + lambda { m.sleep -1 }.should raise_error(ArgumentError) + end - it "unlocks the mutex while sleeping" do - m = Mutex.new - locked = false - th = Thread.new { m.lock; locked = true; m.sleep } - Thread.pass until locked - Thread.pass while th.status and th.status != "sleep" - m.locked?.should be_false - th.run - th.join - end + it "pauses execution for approximately the duration requested" do + m = Mutex.new + m.lock + duration = 0.1 + start = Time.now + m.sleep duration + (Time.now - start).should be_close(duration, 0.1) + end - it "relocks the mutex when woken" do - m = Mutex.new - m.lock - m.sleep(0.01) - m.locked?.should be_true - end + it "unlocks the mutex while sleeping" do + m = Mutex.new + locked = false + th = Thread.new { m.lock; locked = true; m.sleep } + Thread.pass until locked + Thread.pass while th.status and th.status != "sleep" + m.locked?.should be_false + th.run + th.join + end - it "relocks the mutex when woken by an exception being raised" do - m = Mutex.new - th = Thread.new do - m.lock - begin - m.sleep - rescue Exception - m.locked? - end - end - Thread.pass while th.status and th.status != "sleep" - th.raise(Exception) - th.value.should be_true - end + it "relocks the mutex when woken" do + m = Mutex.new + m.lock + m.sleep(0.01) + m.locked?.should be_true + end - it "returns the rounded number of seconds asleep" do - m = Mutex.new + it "relocks the mutex when woken by an exception being raised" do + m = Mutex.new + th = Thread.new do m.lock - m.sleep(0.01).should be_kind_of(Integer) + begin + m.sleep + rescue Exception + m.locked? + end end + Thread.pass while th.status and th.status != "sleep" + th.raise(Exception) + th.value.should be_true + end + + it "returns the rounded number of seconds asleep" do + m = Mutex.new + m.lock + m.sleep(0.01).should be_kind_of(Integer) end end diff --git a/spec/ruby/core/mutex/synchronize_spec.rb b/spec/ruby/core/mutex/synchronize_spec.rb index e3532f8782..d770238165 100644 --- a/spec/ruby/core/mutex/synchronize_spec.rb +++ b/spec/ruby/core/mutex/synchronize_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/mutex/synchronize', __FILE__) -ruby_version_is "1.9" do - describe "Mutex#synchronize" do - it_behaves_like :mutex_synchronize, :synchronize - end +describe "Mutex#synchronize" do + it_behaves_like :mutex_synchronize, :synchronize end diff --git a/spec/ruby/core/mutex/try_lock_spec.rb b/spec/ruby/core/mutex/try_lock_spec.rb index 99c88e9927..abdf1f1b0e 100644 --- a/spec/ruby/core/mutex/try_lock_spec.rb +++ b/spec/ruby/core/mutex/try_lock_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/mutex/try_lock', __FILE__) -ruby_version_is "1.9" do - describe "Mutex#try_lock" do - it_behaves_like :mutex_try_lock, :try_lock - end +describe "Mutex#try_lock" do + it_behaves_like :mutex_try_lock, :try_lock end diff --git a/spec/ruby/core/mutex/unlock_spec.rb b/spec/ruby/core/mutex/unlock_spec.rb index cfea3150ae..f84ba8b4d3 100644 --- a/spec/ruby/core/mutex/unlock_spec.rb +++ b/spec/ruby/core/mutex/unlock_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/mutex/unlock', __FILE__) -ruby_version_is "1.9" do - describe "Mutex#unlock" do - it_behaves_like :mutex_unlock, :unlock - end +describe "Mutex#unlock" do + it_behaves_like :mutex_unlock, :unlock end diff --git a/spec/ruby/core/nil/rationalize_spec.rb b/spec/ruby/core/nil/rationalize_spec.rb index 16080b3609..1292cfd250 100644 --- a/spec/ruby/core/nil/rationalize_spec.rb +++ b/spec/ruby/core/nil/rationalize_spec.rb @@ -1,18 +1,16 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "NilClass#rationalize" do - it "returns 0/1" do - nil.rationalize.should == Rational(0, 1) - end +describe "NilClass#rationalize" do + it "returns 0/1" do + nil.rationalize.should == Rational(0, 1) + end - it "ignores a single argument" do - nil.rationalize(0.1).should == Rational(0, 1) - end + it "ignores a single argument" do + nil.rationalize(0.1).should == Rational(0, 1) + end - it "raises ArgumentError when passed more than one argument" do - lambda { nil.rationalize(0.1, 0.1) }.should raise_error(ArgumentError) - lambda { nil.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) - end + it "raises ArgumentError when passed more than one argument" do + lambda { nil.rationalize(0.1, 0.1) }.should raise_error(ArgumentError) + lambda { nil.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) end end diff --git a/spec/ruby/core/nil/to_c_spec.rb b/spec/ruby/core/nil/to_c_spec.rb index fbb903d963..5b768b4afc 100644 --- a/spec/ruby/core/nil/to_c_spec.rb +++ b/spec/ruby/core/nil/to_c_spec.rb @@ -1,9 +1,7 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "NilClass#to_c" do - it "returns Complex(0, 0)" do - nil.to_c.should eql(Complex(0, 0)) - end +describe "NilClass#to_c" do + it "returns Complex(0, 0)" do + nil.to_c.should eql(Complex(0, 0)) end end diff --git a/spec/ruby/core/nil/to_h_spec.rb b/spec/ruby/core/nil/to_h_spec.rb index 2673e839f4..5300802d19 100644 --- a/spec/ruby/core/nil/to_h_spec.rb +++ b/spec/ruby/core/nil/to_h_spec.rb @@ -1,10 +1,8 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "2.0" do - describe "NilClass#to_h" do - it "returns an empty hash" do - nil.to_h.should == {} - nil.to_h.default.should == nil - end +describe "NilClass#to_h" do + it "returns an empty hash" do + nil.to_h.should == {} + nil.to_h.default.should == nil end end diff --git a/spec/ruby/core/nil/to_r_spec.rb b/spec/ruby/core/nil/to_r_spec.rb index 265e186efe..efbd2f5540 100644 --- a/spec/ruby/core/nil/to_r_spec.rb +++ b/spec/ruby/core/nil/to_r_spec.rb @@ -1,9 +1,7 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "NilClass#to_r" do - it "returns 0/1" do - nil.to_r.should == Rational(0, 1) - end +describe "NilClass#to_r" do + it "returns 0/1" do + nil.to_r.should == Rational(0, 1) end end diff --git a/spec/ruby/core/numeric/abs2_spec.rb b/spec/ruby/core/numeric/abs2_spec.rb index 112905a8e6..0ab0707885 100644 --- a/spec/ruby/core/numeric/abs2_spec.rb +++ b/spec/ruby/core/numeric/abs2_spec.rb @@ -1,36 +1,34 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#abs2" do - before(:each) do - @numbers = [ - 0, - 0.0, - 1, - 20, - bignum_value, - 278202.292871, - 72829, - 3.333333333333, - 0.1, - infinity_value - ].map { |n| [-n, n] }.flatten - end +describe "Numeric#abs2" do + before(:each) do + @numbers = [ + 0, + 0.0, + 1, + 20, + bignum_value, + 278202.292871, + 72829, + 3.333333333333, + 0.1, + infinity_value + ].map { |n| [-n, n] }.flatten + end - it "returns the square of the absolute value of self" do - @numbers.each do |number| - number.abs2.should eql(number.abs ** 2) - end + it "returns the square of the absolute value of self" do + @numbers.each do |number| + number.abs2.should eql(number.abs ** 2) end + end - it "calls #* on self" do - number = mock_numeric('numeric') - number.should_receive(:*).and_return(:result) - number.abs2.should == :result - end + it "calls #* on self" do + number = mock_numeric('numeric') + number.should_receive(:*).and_return(:result) + number.abs2.should == :result + end - it "returns NaN when self is NaN" do - nan_value.abs2.nan?.should be_true - end + it "returns NaN when self is NaN" do + nan_value.abs2.nan?.should be_true end end diff --git a/spec/ruby/core/numeric/angle_spec.rb b/spec/ruby/core/numeric/angle_spec.rb index 7b0255cb5d..d7134168b3 100644 --- a/spec/ruby/core/numeric/angle_spec.rb +++ b/spec/ruby/core/numeric/angle_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/complex/numeric/arg', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#angle" do - it_behaves_like(:numeric_arg, :angle) - end +describe "Numeric#angle" do + it_behaves_like(:numeric_arg, :angle) end diff --git a/spec/ruby/core/numeric/arg_spec.rb b/spec/ruby/core/numeric/arg_spec.rb index f8325b93f5..0729a29226 100644 --- a/spec/ruby/core/numeric/arg_spec.rb +++ b/spec/ruby/core/numeric/arg_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/complex/numeric/arg', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#arg" do - it_behaves_like(:numeric_arg, :arg) - end +describe "Numeric#arg" do + it_behaves_like(:numeric_arg, :arg) end diff --git a/spec/ruby/core/numeric/conj_spec.rb b/spec/ruby/core/numeric/conj_spec.rb index 716ac8a865..8fa0fd9457 100644 --- a/spec/ruby/core/numeric/conj_spec.rb +++ b/spec/ruby/core/numeric/conj_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/complex/numeric/conj', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#conj" do - it_behaves_like(:numeric_conj, :conj) - end +describe "Numeric#conj" do + it_behaves_like(:numeric_conj, :conj) end diff --git a/spec/ruby/core/numeric/conjugate_spec.rb b/spec/ruby/core/numeric/conjugate_spec.rb index 5f1db75064..f7e095514e 100644 --- a/spec/ruby/core/numeric/conjugate_spec.rb +++ b/spec/ruby/core/numeric/conjugate_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/complex/numeric/conj', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#conjugate" do - it_behaves_like(:numeric_conj, :conjugate) - end +describe "Numeric#conjugate" do + it_behaves_like(:numeric_conj, :conjugate) end diff --git a/spec/ruby/core/numeric/denominator_spec.rb b/spec/ruby/core/numeric/denominator_spec.rb index cd411a3114..0a2c5d8c68 100644 --- a/spec/ruby/core/numeric/denominator_spec.rb +++ b/spec/ruby/core/numeric/denominator_spec.rb @@ -1,26 +1,24 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#denominator" do - # The Numeric child classes override this method, so their behaviour is - # specified in the appropriate place - before(:each) do - @numbers = [ - 20, # Integer - 99999999**99, # Bignum - ] - end +describe "Numeric#denominator" do + # The Numeric child classes override this method, so their behaviour is + # specified in the appropriate place + before(:each) do + @numbers = [ + 20, # Integer + 99999999**99, # Bignum + ] + end - it "returns 1" do - @numbers.each {|number| number.denominator.should == 1} - end + it "returns 1" do + @numbers.each {|number| number.denominator.should == 1} + end - it "works with Numeric subclasses" do - rational = mock_numeric('rational') - rational.should_receive(:denominator).and_return(:denominator) - numeric = mock_numeric('numeric') - numeric.should_receive(:to_r).and_return(rational) - numeric.denominator.should == :denominator - end + it "works with Numeric subclasses" do + rational = mock_numeric('rational') + rational.should_receive(:denominator).and_return(:denominator) + numeric = mock_numeric('numeric') + numeric.should_receive(:to_r).and_return(rational) + numeric.denominator.should == :denominator end end diff --git a/spec/ruby/core/numeric/div_spec.rb b/spec/ruby/core/numeric/div_spec.rb index ab8ce43c30..2dac4dbe35 100644 --- a/spec/ruby/core/numeric/div_spec.rb +++ b/spec/ruby/core/numeric/div_spec.rb @@ -6,29 +6,17 @@ @obj = NumericSpecs::Subclass.new end - ruby_version_is ""..."1.9" do - it "calls self#/ with other, converts the result to a Float (using #to_f) and returns the #floor'ed result" do - result = mock("Numeric#div result") - result.should_receive(:to_f).and_return(13 - TOLERANCE) - @obj.should_receive(:/).with(10).and_return(result) + it "calls self#/ with other, then returns the #floor'ed result" do + result = mock("Numeric#div result") + result.should_receive(:floor).and_return(12) + @obj.should_receive(:/).with(10).and_return(result) - @obj.div(10).should == 12 - end + @obj.div(10).should == 12 end - ruby_version_is "1.9" do - it "calls self#/ with other, then returns the #floor'ed result" do - result = mock("Numeric#div result") - result.should_receive(:floor).and_return(12) - @obj.should_receive(:/).with(10).and_return(result) - - @obj.div(10).should == 12 - end - - it "raises ZeroDivisionError for 0" do - lambda { @obj.div(0) }.should raise_error(ZeroDivisionError) - lambda { @obj.div(0.0) }.should raise_error(ZeroDivisionError) - lambda { @obj.div(Complex(0,0)) }.should raise_error(ZeroDivisionError) - end + it "raises ZeroDivisionError for 0" do + lambda { @obj.div(0) }.should raise_error(ZeroDivisionError) + lambda { @obj.div(0.0) }.should raise_error(ZeroDivisionError) + lambda { @obj.div(Complex(0,0)) }.should raise_error(ZeroDivisionError) end end diff --git a/spec/ruby/core/numeric/divmod_spec.rb b/spec/ruby/core/numeric/divmod_spec.rb index a59464c614..10cbf531ee 100644 --- a/spec/ruby/core/numeric/divmod_spec.rb +++ b/spec/ruby/core/numeric/divmod_spec.rb @@ -6,21 +6,10 @@ @obj = NumericSpecs::Subclass.new end - ruby_version_is ""..."1.9" do - it "returns [quotient, modulus], with quotient being obtained as in Numeric#div and modulus being obtained by calling self#% with other" do - @obj.should_receive(:/).with(10).and_return(13 - TOLERANCE) - @obj.should_receive(:%).with(10).and_return(3) + it "returns [quotient, modulus], with quotient being obtained as in Numeric#div then #floor and modulus being obtained by calling self#- with quotient * other" do + @obj.should_receive(:/).twice.with(10).and_return(13 - TOLERANCE, 13 - TOLERANCE) + @obj.should_receive(:-).with(120).and_return(3) - @obj.divmod(10).should == [12, 3] - end - end - - ruby_version_is "1.9" do - it "returns [quotient, modulus], with quotient being obtained as in Numeric#div then #floor and modulus being obtained by calling self#- with quotient * other" do - @obj.should_receive(:/).twice.with(10).and_return(13 - TOLERANCE, 13 - TOLERANCE) - @obj.should_receive(:-).with(120).and_return(3) - - @obj.divmod(10).should == [12, 3] - end + @obj.divmod(10).should == [12, 3] end end diff --git a/spec/ruby/core/numeric/fdiv_spec.rb b/spec/ruby/core/numeric/fdiv_spec.rb index 440c155463..4b27382012 100644 --- a/spec/ruby/core/numeric/fdiv_spec.rb +++ b/spec/ruby/core/numeric/fdiv_spec.rb @@ -2,37 +2,31 @@ require File.expand_path('../shared/quo', __FILE__) describe "Numeric#fdiv" do - ruby_version_is ""..."1.9" do - it_behaves_like :numeric_quo_18, :fdiv + it "coerces self with #to_f" do + numeric = mock_numeric('numeric') + numeric.should_receive(:to_f).and_return(3.0) + numeric.fdiv(0.5).should == 6.0 end - ruby_version_is "1.9" do - it "coerces self with #to_f" do - numeric = mock_numeric('numeric') - numeric.should_receive(:to_f).and_return(3.0) - numeric.fdiv(0.5).should == 6.0 - end - - it "coerces other with #to_f" do - numeric = mock_numeric('numeric') - numeric.should_receive(:to_f).and_return(3.0) - 6.fdiv(numeric).should == 2.0 - end + it "coerces other with #to_f" do + numeric = mock_numeric('numeric') + numeric.should_receive(:to_f).and_return(3.0) + 6.fdiv(numeric).should == 2.0 + end - it "performs floating-point division" do - 3.fdiv(2).should == 1.5 - end + it "performs floating-point division" do + 3.fdiv(2).should == 1.5 + end - it "returns a Float" do - bignum_value.fdiv(Float::MAX).should be_an_instance_of(Float) - end + it "returns a Float" do + bignum_value.fdiv(Float::MAX).should be_an_instance_of(Float) + end - it "returns Infinity if other is 0" do - 8121.92821.fdiv(0).infinite?.should == 1 - end + it "returns Infinity if other is 0" do + 8121.92821.fdiv(0).infinite?.should == 1 + end - it "returns NaN if other is NaN" do - 3334.fdiv(nan_value).nan?.should be_true - end + it "returns NaN if other is NaN" do + 3334.fdiv(nan_value).nan?.should be_true end end diff --git a/spec/ruby/core/numeric/i_spec.rb b/spec/ruby/core/numeric/i_spec.rb index 5a6d566712..fae4fefe3d 100644 --- a/spec/ruby/core/numeric/i_spec.rb +++ b/spec/ruby/core/numeric/i_spec.rb @@ -1,17 +1,15 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#i" do - it "returns a Complex object" do - 34.i.should be_an_instance_of(Complex) - end +describe "Numeric#i" do + it "returns a Complex object" do + 34.i.should be_an_instance_of(Complex) + end - it "sets the real part to 0" do - 7342.i.real.should == 0 - end + it "sets the real part to 0" do + 7342.i.real.should == 0 + end - it "sets the imaginary part to self" do - 62.81.i.imag.should == 62.81 - end + it "sets the imaginary part to self" do + 62.81.i.imag.should == 62.81 end end diff --git a/spec/ruby/core/numeric/imag_spec.rb b/spec/ruby/core/numeric/imag_spec.rb index 9cd6b16ed5..a80e42d265 100644 --- a/spec/ruby/core/numeric/imag_spec.rb +++ b/spec/ruby/core/numeric/imag_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/complex/numeric/imag', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#imag" do - it_behaves_like(:numeric_imag, :imag) - end +describe "Numeric#imag" do + it_behaves_like(:numeric_imag, :imag) end diff --git a/spec/ruby/core/numeric/imaginary_spec.rb b/spec/ruby/core/numeric/imaginary_spec.rb index 18c207e07f..41226569b3 100644 --- a/spec/ruby/core/numeric/imaginary_spec.rb +++ b/spec/ruby/core/numeric/imaginary_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/complex/numeric/imag', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#imaginary" do - it_behaves_like(:numeric_imag, :imaginary) - end +describe "Numeric#imaginary" do + it_behaves_like(:numeric_imag, :imaginary) end diff --git a/spec/ruby/core/numeric/magnitude_spec.rb b/spec/ruby/core/numeric/magnitude_spec.rb index 2788670c59..947ee69730 100644 --- a/spec/ruby/core/numeric/magnitude_spec.rb +++ b/spec/ruby/core/numeric/magnitude_spec.rb @@ -1,7 +1,5 @@ require File.expand_path('../shared/abs', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#magnitude" do - it_behaves_like(:numeric_abs, :magnitude) - end +describe "Numeric#magnitude" do + it_behaves_like(:numeric_abs, :magnitude) end diff --git a/spec/ruby/core/numeric/modulo_spec.rb b/spec/ruby/core/numeric/modulo_spec.rb index f419fba882..7cf41233ab 100644 --- a/spec/ruby/core/numeric/modulo_spec.rb +++ b/spec/ruby/core/numeric/modulo_spec.rb @@ -1,37 +1,24 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "".."1.9" do - describe "Numeric#modulo" do - it "returns the result of calling self#% with other" do - obj = NumericSpecs::Subclass.new - obj.should_receive(:%).with(20).and_return(:result) - - obj.modulo(20).should == :result - end +describe :numeric_modulo_19, :shared => true do + it "returns self - other * self.div(other)" do + s = mock_numeric('self') + o = mock_numeric('other') + n3 = mock_numeric('n3') + n4 = mock_numeric('n4') + n5 = mock_numeric('n5') + s.should_receive(:div).with(o).and_return(n3) + o.should_receive(:*).with(n3).and_return(n4) + s.should_receive(:-).with(n4).and_return(n5) + s.send(@method, o).should == n5 end end -ruby_version_is "1.9" do - describe :numeric_modulo_19, :shared => true do - it "returns self - other * self.div(other)" do - s = mock_numeric('self') - o = mock_numeric('other') - n3 = mock_numeric('n3') - n4 = mock_numeric('n4') - n5 = mock_numeric('n5') - s.should_receive(:div).with(o).and_return(n3) - o.should_receive(:*).with(n3).and_return(n4) - s.should_receive(:-).with(n4).and_return(n5) - s.send(@method, o).should == n5 - end - end - - describe "Numeric#modulo" do - it_behaves_like :numeric_modulo_19, :modulo - end +describe "Numeric#modulo" do + it_behaves_like :numeric_modulo_19, :modulo +end - describe "Numeric#%" do - it_behaves_like :numeric_modulo_19, :% - end +describe "Numeric#%" do + it_behaves_like :numeric_modulo_19, :% end diff --git a/spec/ruby/core/numeric/numerator_spec.rb b/spec/ruby/core/numeric/numerator_spec.rb index 8768cea31c..752dbb3f0e 100644 --- a/spec/ruby/core/numeric/numerator_spec.rb +++ b/spec/ruby/core/numeric/numerator_spec.rb @@ -1,35 +1,33 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#numerator" do - before(:all) do - @numbers = [ - 0, - 29871, - 99999999999999**99, - -72628191273, - 29282.2827, - -2927.00091, - 0.0, - 12.0, - Float::MAX, - ] - end +describe "Numeric#numerator" do + before(:all) do + @numbers = [ + 0, + 29871, + 99999999999999**99, + -72628191273, + 29282.2827, + -2927.00091, + 0.0, + 12.0, + Float::MAX, + ] + end - # This isn't entirely true, as NaN.numerator works, whereas - # Rational(NaN) raises an exception, but we test this in Float#numerator - it "converts self to a Rational object then returns its numerator" do - @numbers.each do |number| - number.numerator.should == Rational(number).numerator - end + # This isn't entirely true, as NaN.numerator works, whereas + # Rational(NaN) raises an exception, but we test this in Float#numerator + it "converts self to a Rational object then returns its numerator" do + @numbers.each do |number| + number.numerator.should == Rational(number).numerator end + end - it "works with Numeric subclasses" do - rational = mock_numeric('rational') - rational.should_receive(:numerator).and_return(:numerator) - numeric = mock_numeric('numeric') - numeric.should_receive(:to_r).and_return(rational) - numeric.numerator.should == :numerator - end + it "works with Numeric subclasses" do + rational = mock_numeric('rational') + rational.should_receive(:numerator).and_return(:numerator) + numeric = mock_numeric('numeric') + numeric.should_receive(:to_r).and_return(rational) + numeric.numerator.should == :numerator end end diff --git a/spec/ruby/core/numeric/phase_spec.rb b/spec/ruby/core/numeric/phase_spec.rb index beea4993db..7c408db83b 100644 --- a/spec/ruby/core/numeric/phase_spec.rb +++ b/spec/ruby/core/numeric/phase_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/complex/numeric/arg', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#phase" do - it_behaves_like(:numeric_arg, :phase) - end +describe "Numeric#phase" do + it_behaves_like(:numeric_arg, :phase) end diff --git a/spec/ruby/core/numeric/polar_spec.rb b/spec/ruby/core/numeric/polar_spec.rb index 0e7fa3bc5f..5492483215 100644 --- a/spec/ruby/core/numeric/polar_spec.rb +++ b/spec/ruby/core/numeric/polar_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../shared/complex/numeric/polar', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#polar" do - it_behaves_like(:numeric_polar, :polar) - end +describe "Numeric#polar" do + it_behaves_like(:numeric_polar, :polar) end diff --git a/spec/ruby/core/numeric/quo_spec.rb b/spec/ruby/core/numeric/quo_spec.rb index 314a808c76..d872625781 100644 --- a/spec/ruby/core/numeric/quo_spec.rb +++ b/spec/ruby/core/numeric/quo_spec.rb @@ -3,47 +3,41 @@ require File.expand_path('../shared/quo', __FILE__) describe "Numeric#quo" do - ruby_version_is ""..."1.9" do - it_behaves_like :numeric_quo_18, :quo + it "returns the result of self divided by the given Integer as a Rational" do + 5.quo(2).should eql(Rational(5,2)) end - ruby_version_is "1.9" do - it "returns the result of self divided by the given Integer as a Rational" do - 5.quo(2).should eql(Rational(5,2)) - end - - it "returns the result of self divided by the given Float as a Float" do - 2.quo(2.5).should eql(0.8) - end + it "returns the result of self divided by the given Float as a Float" do + 2.quo(2.5).should eql(0.8) + end - it "returns the result of self divided by the given Bignum as a Float" do - 45.quo(bignum_value).should be_close(1.04773789668636e-08, TOLERANCE) - end + it "returns the result of self divided by the given Bignum as a Float" do + 45.quo(bignum_value).should be_close(1.04773789668636e-08, TOLERANCE) + end - it "raises a ZeroDivisionError when the given Integer is 0" do - lambda { 0.quo(0) }.should raise_error(ZeroDivisionError) - lambda { 10.quo(0) }.should raise_error(ZeroDivisionError) - lambda { -10.quo(0) }.should raise_error(ZeroDivisionError) - lambda { bignum_value.quo(0) }.should raise_error(ZeroDivisionError) - lambda { -bignum_value.quo(0) }.should raise_error(ZeroDivisionError) - end + it "raises a ZeroDivisionError when the given Integer is 0" do + lambda { 0.quo(0) }.should raise_error(ZeroDivisionError) + lambda { 10.quo(0) }.should raise_error(ZeroDivisionError) + lambda { -10.quo(0) }.should raise_error(ZeroDivisionError) + lambda { bignum_value.quo(0) }.should raise_error(ZeroDivisionError) + lambda { -bignum_value.quo(0) }.should raise_error(ZeroDivisionError) + end - it "returns the result of calling self#/ with other" do - obj = NumericSpecs::Subclass.new - obj.should_receive(:coerce).twice.and_return([19,19]) - obj.should_receive(:<=>).any_number_of_times.and_return(1) - obj.should_receive(:/).and_return(20) + it "returns the result of calling self#/ with other" do + obj = NumericSpecs::Subclass.new + obj.should_receive(:coerce).twice.and_return([19,19]) + obj.should_receive(:<=>).any_number_of_times.and_return(1) + obj.should_receive(:/).and_return(20) - obj.quo(19).should == 20 - end + obj.quo(19).should == 20 + end - it "raises a TypeError when given a non-Integer" do - lambda { - (obj = mock('x')).should_not_receive(:to_int) - 13.quo(obj) - }.should raise_error(TypeError) - lambda { 13.quo("10") }.should raise_error(TypeError) - lambda { 13.quo(:symbol) }.should raise_error(TypeError) - end + it "raises a TypeError when given a non-Integer" do + lambda { + (obj = mock('x')).should_not_receive(:to_int) + 13.quo(obj) + }.should raise_error(TypeError) + lambda { 13.quo("10") }.should raise_error(TypeError) + lambda { 13.quo(:symbol) }.should raise_error(TypeError) end end diff --git a/spec/ruby/core/numeric/real_spec.rb b/spec/ruby/core/numeric/real_spec.rb index 7dab68d8b2..3e34410155 100644 --- a/spec/ruby/core/numeric/real_spec.rb +++ b/spec/ruby/core/numeric/real_spec.rb @@ -2,16 +2,12 @@ require File.expand_path('../../../shared/complex/numeric/real', __FILE__) require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#real" do - it_behaves_like(:numeric_real, :real) - end +describe "Numeric#real" do + it_behaves_like(:numeric_real, :real) end -ruby_version_is "1.9" do - describe "Numeric#real?" do - it "returns true" do - NumericSpecs::Subclass.new.real?.should == true - end +describe "Numeric#real?" do + it "returns true" do + NumericSpecs::Subclass.new.real?.should == true end end diff --git a/spec/ruby/core/numeric/rect_spec.rb b/spec/ruby/core/numeric/rect_spec.rb index 0ce9ca5796..88d5ee3881 100644 --- a/spec/ruby/core/numeric/rect_spec.rb +++ b/spec/ruby/core/numeric/rect_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/rect', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#rect" do - it_behaves_like(:numeric_rect, :rect) - end +describe "Numeric#rect" do + it_behaves_like(:numeric_rect, :rect) end diff --git a/spec/ruby/core/numeric/rectangular_spec.rb b/spec/ruby/core/numeric/rectangular_spec.rb index f13f1e0b4a..b34100ca74 100644 --- a/spec/ruby/core/numeric/rectangular_spec.rb +++ b/spec/ruby/core/numeric/rectangular_spec.rb @@ -1,8 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../shared/rect', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#rectangular" do - it_behaves_like(:numeric_rect, :rectangular) - end +describe "Numeric#rectangular" do + it_behaves_like(:numeric_rect, :rectangular) end diff --git a/spec/ruby/core/numeric/step_spec.rb b/spec/ruby/core/numeric/step_spec.rb index 30f56cecd4..c727f3ea61 100644 --- a/spec/ruby/core/numeric/step_spec.rb +++ b/spec/ruby/core/numeric/step_spec.rb @@ -20,22 +20,20 @@ ScratchPad.recorded.should == [1, 2, 3, 4, 5] end - ruby_version_is "1.8.7" do - it "returns an Enumerator when step is 0" do - 1.step(2, 0).should be_an_instance_of(enumerator_class) - end + it "returns an Enumerator when step is 0" do + 1.step(2, 0).should be_an_instance_of(enumerator_class) + end - it "returns an Enumerator when not passed a block and self > stop" do - 1.step(0, 2).should be_an_instance_of(enumerator_class) - end + it "returns an Enumerator when not passed a block and self > stop" do + 1.step(0, 2).should be_an_instance_of(enumerator_class) + end - it "returns an Enumerator when not passed a block and self < stop" do - 1.step(2, 3).should be_an_instance_of(enumerator_class) - end + it "returns an Enumerator when not passed a block and self < stop" do + 1.step(2, 3).should be_an_instance_of(enumerator_class) + end - it "returns an Enumerator that uses the given step" do - 0.step(5, 2).to_a.should == [0, 2, 4] - end + it "returns an Enumerator that uses the given step" do + 0.step(5, 2).to_a.should == [0, 2, 4] end describe "with [stop, step]" do @@ -45,21 +43,6 @@ @obj = NumericSpecs::Subclass.new end - ruby_version_is ""..."1.8.7" do - it "does not raise a LocalJumpError when not passed a block and self > stop" do - @step.should_receive(:>).with(0).and_return(true) - @obj.should_receive(:>).with(@stop).and_return(true) - @obj.step(@stop, @step) - end - - it "raises a LocalJumpError when not passed a block and self < stop" do - @step.should_receive(:>).with(0).and_return(true) - @obj.should_receive(:>).with(@stop).and_return(false) - - lambda { @obj.step(@stop, @step) }.should raise_error(LocalJumpError) - end - end - it "increments self using #+ until self > stop when step > 0" do @step.should_receive(:>).with(0).and_return(true) @obj.should_receive(:>).with(@stop).and_return(false, false, false, true) diff --git a/spec/ruby/core/numeric/to_c_spec.rb b/spec/ruby/core/numeric/to_c_spec.rb index 4d72e5b861..d2cbbe3728 100644 --- a/spec/ruby/core/numeric/to_c_spec.rb +++ b/spec/ruby/core/numeric/to_c_spec.rb @@ -1,47 +1,45 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "Numeric#to_c" do - before(:all) do - @numbers = [ - 0, - 29871, - 99999999999999**99, - -72628191273, - Rational(2,3), - Rational(1.898), - Rational(-238), - 29282.2827, - -2927.00091, - 0.0, - 12.0, - Float::MAX, - infinity_value, - nan_value - ] - end +describe "Numeric#to_c" do + before(:all) do + @numbers = [ + 0, + 29871, + 99999999999999**99, + -72628191273, + Rational(2,3), + Rational(1.898), + Rational(-238), + 29282.2827, + -2927.00091, + 0.0, + 12.0, + Float::MAX, + infinity_value, + nan_value + ] + end - it "returns a Complex object" do - @numbers.each do |number| - number.to_c.should be_an_instance_of(Complex) - end + it "returns a Complex object" do + @numbers.each do |number| + number.to_c.should be_an_instance_of(Complex) end + end - it "uses self as the real component" do - @numbers.each do |number| - real = number.to_c.real - if number.to_f.nan? - real.nan?.should be_true - else - real.should == number - end + it "uses self as the real component" do + @numbers.each do |number| + real = number.to_c.real + if number.to_f.nan? + real.nan?.should be_true + else + real.should == number end end + end - it "uses 0 as the imaginary component" do - @numbers.each do |number| - number.to_c.imag.should == 0 - end + it "uses 0 as the imaginary component" do + @numbers.each do |number| + number.to_c.imag.should == 0 end end end diff --git a/spec/ruby/core/object/__id__spec.rb b/spec/ruby/core/object/__id__spec.rb deleted file mode 100644 index 7ad17a51d9..0000000000 --- a/spec/ruby/core/object/__id__spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../../../shared/object/object_id', __FILE__) - -ruby_version_is "".."1.9" do - describe "Object#__id__" do - it_behaves_like :basic_object_id, :__id__, Object - it_behaves_like :object_id, :__id__, Object - end -end diff --git a/spec/ruby/core/object/id_spec.rb b/spec/ruby/core/object/id_spec.rb deleted file mode 100644 index 943da29b8b..0000000000 --- a/spec/ruby/core/object/id_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../../../shared/object/object_id', __FILE__) - -ruby_version_is "".."1.9" do - describe "Object#id" do - it_behaves_like :basic_object_id, :id, Object - it_behaves_like :object_id, :id, Object - end -end diff --git a/spec/ruby/core/object/instance_exec_spec.rb b/spec/ruby/core/object/instance_exec_spec.rb index 1c609c589b..d11724b31f 100644 --- a/spec/ruby/core/object/instance_exec_spec.rb +++ b/spec/ruby/core/object/instance_exec_spec.rb @@ -1,110 +1,97 @@ require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) -ruby_version_is "1.8.7" do - - require File.expand_path('../fixtures/classes', __FILE__) - - describe "Object#instance_exec" do - it "raises a LocalJumpError unless given a block" do - lambda { "hola".instance_exec }.should raise_error(LocalJumpError) - end +describe "Object#instance_exec" do + it "raises a LocalJumpError unless given a block" do + lambda { "hola".instance_exec }.should raise_error(LocalJumpError) + end - it "has an arity of -1" do - Object.new.method(:instance_exec).arity.should == -1 - end + it "has an arity of -1" do + Object.new.method(:instance_exec).arity.should == -1 + end - it "accepts arguments with a block" do - lambda { "hola".instance_exec(4, 5) { |a,b| a + b } }.should_not raise_error - end + it "accepts arguments with a block" do + lambda { "hola".instance_exec(4, 5) { |a,b| a + b } }.should_not raise_error + end - it "doesn't pass self to the block as an argument" do - "hola".instance_exec { |o| o }.should be_nil - end + it "doesn't pass self to the block as an argument" do + "hola".instance_exec { |o| o }.should be_nil + end - it "passes any arguments to the block" do - Object.new.instance_exec(1,2) {|one, two| one + two}.should == 3 - end + it "passes any arguments to the block" do + Object.new.instance_exec(1,2) {|one, two| one + two}.should == 3 + end - it "only binds the exec to the receiver" do - f = Object.new - f.instance_exec do - def foo - 1 - end + it "only binds the exec to the receiver" do + f = Object.new + f.instance_exec do + def foo + 1 end - f.foo.should == 1 - lambda { Object.new.foo }.should raise_error(NoMethodError) end + f.foo.should == 1 + lambda { Object.new.foo }.should raise_error(NoMethodError) + end - # TODO: This should probably be replaced with a "should behave like" that uses - # the many scoping/binding specs from kernel/eval_spec, since most of those - # behaviors are the same for instance_exec. See also module_eval/class_eval. + # TODO: This should probably be replaced with a "should behave like" that uses + # the many scoping/binding specs from kernel/eval_spec, since most of those + # behaviors are the same for instance_exec. See also module_eval/class_eval. - it "binds self to the receiver" do - s = "hola" - (s == s.instance_exec { self }).should == true - end - - it "binds the block's binding self to the receiver" do - s = "hola" - (s == s.instance_exec { eval "self", binding }).should == true - end + it "binds self to the receiver" do + s = "hola" + (s == s.instance_exec { self }).should == true + end - it "executes in the context of the receiver" do - "Ruby-fu".instance_exec { size }.should == 7 - Object.class_eval { "Ruby-fu".instance_exec{ to_s } }.should == "Ruby-fu" - end + it "binds the block's binding self to the receiver" do + s = "hola" + (s == s.instance_exec { eval "self", binding }).should == true + end - it "has access to receiver's instance variables" do - ObjectSpecs::IVars.new.instance_exec { @secret }.should == 99 - end + it "executes in the context of the receiver" do + "Ruby-fu".instance_exec { size }.should == 7 + Object.class_eval { "Ruby-fu".instance_exec{ to_s } }.should == "Ruby-fu" + end - it "invokes Method objects without rebinding self" do - 3.instance_exec(4, &5.method(:+)).should == 9 - end + it "has access to receiver's instance variables" do + ObjectSpecs::IVars.new.instance_exec { @secret }.should == 99 + end - ruby_version_is ""..."1.9" do - it "sets class variables in the receiver" do - ObjectSpecs::InstExec.class_variables.should include("@@count") - ObjectSpecs::InstExec.send(:class_variable_get, :@@count).should == 2 - end - end + it "invokes Method objects without rebinding self" do + 3.instance_exec(4, &5.method(:+)).should == 9 + end - ruby_version_is "1.9" do - it "sets class variables in the receiver" do - ObjectSpecs::InstExec.class_variables.should include(:@@count) - ObjectSpecs::InstExec.send(:class_variable_get, :@@count).should == 2 - end - end + it "sets class variables in the receiver" do + ObjectSpecs::InstExec.class_variables.should include(:@@count) + ObjectSpecs::InstExec.send(:class_variable_get, :@@count).should == 2 + end - it "raises a TypeError when defining methods on an immediate" do - lambda do - 1.instance_exec { def foo; end } - end.should raise_error(TypeError) - lambda do - :foo.instance_exec { def foo; end } - end.should raise_error(TypeError) - end + it "raises a TypeError when defining methods on an immediate" do + lambda do + 1.instance_exec { def foo; end } + end.should raise_error(TypeError) + lambda do + :foo.instance_exec { def foo; end } + end.should raise_error(TypeError) + end - quarantine! do # Not clean, leaves cvars lying around to break other specs - it "scopes class var accesses in the caller when called on a Fixnum" do - # Fixnum can take instance vars - Fixnum.class_eval "@@__tmp_instance_exec_spec = 1" - (defined? @@__tmp_instance_exec_spec).should == nil +quarantine! do # Not clean, leaves cvars lying around to break other specs + it "scopes class var accesses in the caller when called on a Fixnum" do + # Fixnum can take instance vars + Fixnum.class_eval "@@__tmp_instance_exec_spec = 1" + (defined? @@__tmp_instance_exec_spec).should == nil - @@__tmp_instance_exec_spec = 2 - 1.instance_exec { @@__tmp_instance_exec_spec }.should == 2 - Fixnum.__send__(:remove_class_variable, :@@__tmp_instance_exec_spec) - end + @@__tmp_instance_exec_spec = 2 + 1.instance_exec { @@__tmp_instance_exec_spec }.should == 2 + Fixnum.__send__(:remove_class_variable, :@@__tmp_instance_exec_spec) end +end - it "raises a TypeError when defining methods on numerics" do - lambda do - (1.0).instance_exec { def foo; end } - end.should raise_error(TypeError) - lambda do - (1 << 64).instance_exec { def foo; end } - end.should raise_error(TypeError) - end + it "raises a TypeError when defining methods on numerics" do + lambda do + (1.0).instance_exec { def foo; end } + end.should raise_error(TypeError) + lambda do + (1 << 64).instance_exec { def foo; end } + end.should raise_error(TypeError) end end diff --git a/spec/ruby/core/object/match_spec.rb b/spec/ruby/core/object/match_spec.rb index 221c310b99..b5dea403b6 100644 --- a/spec/ruby/core/object/match_spec.rb +++ b/spec/ruby/core/object/match_spec.rb @@ -1,29 +1,14 @@ require File.expand_path('../../../spec_helper', __FILE__) -describe Object, '=~' do - ruby_version_is ""..."1.9" do - it "returns false matching any object" do - o = Object.new - - (o =~ /Object/).should == false - (o =~ 'Object').should == false - (o =~ Object).should == false - (o =~ Object.new).should == false - (o =~ nil).should == false - (o =~ true).should == false - end - end - - ruby_version_is "1.9" do - it "returns nil matching any object" do - o = Object.new - - (o =~ /Object/).should be_nil - (o =~ 'Object').should be_nil - (o =~ Object).should be_nil - (o =~ Object.new).should be_nil - (o =~ nil).should be_nil - (o =~ true).should be_nil - end +describe "Object#=~" do + it "returns nil matching any object" do + o = Object.new + + (o =~ /Object/).should be_nil + (o =~ 'Object').should be_nil + (o =~ Object).should be_nil + (o =~ Object.new).should be_nil + (o =~ nil).should be_nil + (o =~ true).should be_nil end end diff --git a/spec/ruby/core/object/new_spec.rb b/spec/ruby/core/object/new_spec.rb index f8c205d801..d576dbc8b4 100644 --- a/spec/ruby/core/object/new_spec.rb +++ b/spec/ruby/core/object/new_spec.rb @@ -5,20 +5,9 @@ Object.new.should be_kind_of(Object) end - ruby_version_is "1.9.1".."1.9.2" do # Ref: [redmine:2451] - it "accepts any number of arguments" do - lambda { - Object.new("This", "makes it easier", "to call super", "from other constructors") - }.should_not raise_error - end - end - - ruby_version_is "1.9.3" do # Ref: [redmine:2451] - it "doesn't accept arguments" do - lambda { - Object.new("This", "makes it easier", "to call super", "from other constructors") - }.should raise_error - end + it "doesn't accept arguments" do + lambda { + Object.new("This", "makes it easier", "to call super", "from other constructors") + }.should raise_error end end - diff --git a/spec/ruby/core/object/shared/dup_clone.rb b/spec/ruby/core/object/shared/dup_clone.rb index f4a918a96f..596fdebe44 100644 --- a/spec/ruby/core/object/shared/dup_clone.rb +++ b/spec/ruby/core/object/shared/dup_clone.rb @@ -69,16 +69,14 @@ def initialize_copy(original) o2.object_id.should_not == old_object_id end - ruby_version_is "1.9" do - it "preserves untrusted state from the original" do - o = ObjectSpecDupInitCopy.new - o2 = o.send(@method) - o.untrust - o3 = o.send(@method) - - o2.untrusted?.should == false - o3.untrusted?.should == true - end + it "preserves untrusted state from the original" do + o = ObjectSpecDupInitCopy.new + o2 = o.send(@method) + o.untrust + o3 = o.send(@method) + + o2.untrusted?.should == false + o3.untrusted?.should == true end it "raises a TypeError for NilClass" do diff --git a/spec/ruby/core/objectspace/count_objects_spec.rb b/spec/ruby/core/objectspace/count_objects_spec.rb index b3c5814b47..3e77d562a8 100644 --- a/spec/ruby/core/objectspace/count_objects_spec.rb +++ b/spec/ruby/core/objectspace/count_objects_spec.rb @@ -1,7 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) -ruby_version_is "1.9" do - describe "ObjectSpace.count_objects" do - it "needs to be reviewed for spec completeness" - end +describe "ObjectSpace.count_objects" do + it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/core/objectspace/define_finalizer_spec.rb b/spec/ruby/core/objectspace/define_finalizer_spec.rb index f3f0d226b1..606bdf67ab 100644 --- a/spec/ruby/core/objectspace/define_finalizer_spec.rb +++ b/spec/ruby/core/objectspace/define_finalizer_spec.rb @@ -24,36 +24,34 @@ def handler.call(obj) end end # see [ruby-core:24095] - ruby_version_is "1.9" do - with_feature :fork do - it "calls finalizer on process termination" do - rd, wr = IO.pipe - if Kernel::fork then - wr.close - rd.read.should == "finalized" - rd.close - else - rd.close - handler = ObjectSpaceFixtures.scoped(wr) - obj = "Test" - ObjectSpace.define_finalizer(obj, handler) - exit 0 - end + with_feature :fork do + it "calls finalizer on process termination" do + rd, wr = IO.pipe + if Kernel::fork then + wr.close + rd.read.should == "finalized" + rd.close + else + rd.close + handler = ObjectSpaceFixtures.scoped(wr) + obj = "Test" + ObjectSpace.define_finalizer(obj, handler) + exit 0 end + end - it "calls finalizer at exit even if it is self-referencing" do - rd, wr = IO.pipe - if Kernel::fork then - wr.close - rd.read.should == "finalized" - rd.close - else - rd.close - obj = "Test" - handler = Proc.new { wr.write "finalized"; wr.close } - ObjectSpace.define_finalizer(obj, handler) - exit 0 - end + it "calls finalizer at exit even if it is self-referencing" do + rd, wr = IO.pipe + if Kernel::fork then + wr.close + rd.read.should == "finalized" + rd.close + else + rd.close + obj = "Test" + handler = Proc.new { wr.write "finalized"; wr.close } + ObjectSpace.define_finalizer(obj, handler) + exit 0 end end end diff --git a/spec/ruby/core/objectspace/each_object_spec.rb b/spec/ruby/core/objectspace/each_object_spec.rb index 610581cd43..df3fc5e564 100644 --- a/spec/ruby/core/objectspace/each_object_spec.rb +++ b/spec/ruby/core/objectspace/each_object_spec.rb @@ -33,16 +33,14 @@ module ObjectSpaceSpecEachModule; end end end - ruby_version_is '1.8.7' do - it "returns an enumerator if not given a block" do - class ObjectSpaceSpecEachOtherObject; end - new_obj = ObjectSpaceSpecEachOtherObject.new + it "returns an enumerator if not given a block" do + class ObjectSpaceSpecEachOtherObject; end + new_obj = ObjectSpaceSpecEachOtherObject.new - counter = ObjectSpace.each_object(ObjectSpaceSpecEachOtherObject) - counter.should be_an_instance_of(enumerator_class) - counter.each{}.should == 1 - # this is needed to prevent the new_obj from being GC'd too early - new_obj.should_not == nil - end + counter = ObjectSpace.each_object(ObjectSpaceSpecEachOtherObject) + counter.should be_an_instance_of(enumerator_class) + counter.each{}.should == 1 + # this is needed to prevent the new_obj from being GC'd too early + new_obj.should_not == nil end end diff --git a/spec/ruby/core/precision/included_spec.rb b/spec/ruby/core/precision/included_spec.rb deleted file mode 100644 index b8da0c5b71..0000000000 --- a/spec/ruby/core/precision/included_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) - -ruby_version_is ""..."1.9.1" do - describe "Precision.included" do - it "raises a TypeError when a class mixed with Precision does not specify induced_from" do - class Foo ;include Precision ;end - lambda { Foo.induced_from(1) }.should raise_error(TypeError) - end - - it "doesn't raise a TypeError when a class mixed with Precision specifies induced_from" do - class Foo - include Precision - def self.induced_from(obj) - # nothing - end - end - lambda { Foo.induced_from(1) }.should_not raise_error(TypeError) - end - end -end diff --git a/spec/ruby/core/precision/prec_f_spec.rb b/spec/ruby/core/precision/prec_f_spec.rb deleted file mode 100644 index c2e827ac34..0000000000 --- a/spec/ruby/core/precision/prec_f_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) - -ruby_version_is ""..."1.9.1" do - describe "Precision#prec_f" do - it "converts an Integer to Float when called on an Integer" do - 1.prec_f.should==1.0 - end - - it "returns the same Float when called on a Float" do - 1.9.prec_f.should==1.9 - end - end -end diff --git a/spec/ruby/core/precision/prec_i_spec.rb b/spec/ruby/core/precision/prec_i_spec.rb deleted file mode 100644 index 14868ea9eb..0000000000 --- a/spec/ruby/core/precision/prec_i_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) - -ruby_version_is ""..."1.9.1" do - describe "Precision#prec_i" do - it "returns the same Integer when called on an Integer" do - 1.prec_i.should == 1 - end - - it "converts Float to an Integer when called on an Integer" do - 1.9.prec_i.should == 1 - end - end -end diff --git a/spec/ruby/core/precision/prec_spec.rb b/spec/ruby/core/precision/prec_spec.rb deleted file mode 100644 index af8153e197..0000000000 --- a/spec/ruby/core/precision/prec_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require File.expand_path('../../../spec_helper', __FILE__) - -ruby_version_is ""..."1.9.1" do - describe "Float#prec" do - it "returns the same Float when given the class Float" do - 1.4.prec(Float).should == 1.4 - end - - it "converts the Float to an Integer when given the class Integer" do - 1.4.prec(Integer).should == 1 - end - end - - describe "Integer#prec" do - it "returns the same Integer when given the class Integer" do - 1.prec(Integer).should == 1 - end - - it "converts the Integer to Float when given the class Float" do - 1.prec(Float).should == 1.0 - end - end -end - -describe "Precision#prec" do - it "needs to be reviewed for spec completeness" -end diff --git a/spec/ruby/shared/kernel/method_missing.rb b/spec/ruby/shared/kernel/method_missing.rb index 9d11e6a5d0..1257f24f5b 100644 --- a/spec/ruby/shared/kernel/method_missing.rb +++ b/spec/ruby/shared/kernel/method_missing.rb @@ -1,12 +1,6 @@ require File.expand_path('../../../spec_helper', __FILE__) require File.expand_path('../../../fixtures/kernel/classes', __FILE__) -describe :method_missing, :shared => true do - it "is a private method" do - @object.should have_private_instance_method(:method_missing) - end -end - describe :method_missing_defined_module, :shared => true do describe "for a Module with #method_missing defined" do it "is not called when a defined method is called" do