diff options
Diffstat (limited to 'spec/rubyspec/core')
-rw-r--r-- | spec/rubyspec/core/kernel/fixtures/classes.rb | 16 | ||||
-rw-r--r-- | spec/rubyspec/core/kernel/yield_self_spec.rb | 26 | ||||
-rw-r--r-- | spec/rubyspec/core/string/split_spec.rb | 4 |
3 files changed, 30 insertions, 16 deletions
diff --git a/spec/rubyspec/core/kernel/fixtures/classes.rb b/spec/rubyspec/core/kernel/fixtures/classes.rb index fa6d8baf0b..c4a4d00485 100644 --- a/spec/rubyspec/core/kernel/fixtures/classes.rb +++ b/spec/rubyspec/core/kernel/fixtures/classes.rb @@ -213,22 +213,6 @@ module KernelSpecs end end - module KernelBlockGiven - def self.accept_block - Kernel.block_given? - end - - def self.accept_block_as_argument(&block) - Kernel.block_given? - end - - class << self - define_method(:defined_block) do - Kernel.block_given? - end - end - end - module SelfBlockGiven def self.accept_block self.send(:block_given?) diff --git a/spec/rubyspec/core/kernel/yield_self_spec.rb b/spec/rubyspec/core/kernel/yield_self_spec.rb new file mode 100644 index 0000000000..817c01f288 --- /dev/null +++ b/spec/rubyspec/core/kernel/yield_self_spec.rb @@ -0,0 +1,26 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +has_yield_self = VersionGuard.new("2.5").match? || PlatformGuard.implementation?(:truffleruby) + +if has_yield_self + describe "Kernel#yield_self" do + it "yields self" do + object = Object.new + object.yield_self { |o| o.should equal object } + end + + it "returns the block return value" do + object = Object.new + object.yield_self { 42 }.should equal 42 + end + + it "returns a sized Enumerator when no block given" do + object = Object.new + enum = object.yield_self + enum.should be_an_instance_of Enumerator + enum.size.should equal 1 + enum.peek.should equal object + enum.first.should equal object + end + end +end diff --git a/spec/rubyspec/core/string/split_spec.rb b/spec/rubyspec/core/string/split_spec.rb index 7d7d383f9c..1a4128f828 100644 --- a/spec/rubyspec/core/string/split_spec.rb +++ b/spec/rubyspec/core/string/split_spec.rb @@ -300,6 +300,10 @@ describe "String#split with Regexp" do "AabB".split(/([a-z])+/).should == ["A", "b", "B"] end + it "applies the limit to the number of split substrings, without counting captures" do + "aBaBa".split(/(B)()()/, 2).should == ["a", "B", "", "", "aBa"] + end + it "does not include non-matching captures in the result array" do "hello".split(/(el)|(xx)/).should == ["h", "el", "lo"] end |