Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c710f737f83e
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 92869ebdf1c6
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Mar 7, 2015

  1. Copy the full SHA
    1f0ed32 View commit details
  2. Merge pull request #3347 from jsyeo/slice_when_spec

    Add specs for Enumerable#slice_when
    Yorick Peterse committed Mar 7, 2015
    Copy the full SHA
    92869eb View commit details
Showing with 40 additions and 0 deletions.
  1. +36 −0 spec/ruby/core/enumerable/slice_when_spec.rb
  2. +4 −0 spec/tags/ruby/core/enumerable/slice_when_tags.txt
36 changes: 36 additions & 0 deletions spec/ruby/core/enumerable/slice_when_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Enumerable#slice_when" do
before :each do
ary = [10, 9, 7, 6, 4, 3, 2, 1]
@enum = EnumerableSpecs::Numerous.new *ary
@result = @enum.slice_when { |i, j| i - 1 != j }
@enum_length = ary.length
end

context "when given a block" do
it "returns an enumerator" do
@result.should be_an_instance_of(enumerator_class)
end

it "splits chunks between adjacent elements i and j where the block returns true" do
@result.to_a.should == [[10, 9], [7, 6], [4, 3, 2, 1]]
end

it "calls the block for length of the receiver enumerable minus one times" do
times_called = 0
@enum.slice_when do |i, j|
times_called += 1
i - 1 != j
end.to_a
times_called.should == (@enum_length - 1)
end
end

context "when not given a block" do
it "raises an ArgumentError" do
lambda { @enum.slice_when }.should raise_error(ArgumentError)
end
end
end
4 changes: 4 additions & 0 deletions spec/tags/ruby/core/enumerable/slice_when_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fails:Enumerable#slice_when when given a block returns an enumerator
fails:Enumerable#slice_when when given a block splits chunks between adjacent elements i and j where the block returns true
fails:Enumerable#slice_when when given a block calls the block the length of the receiver enumerable minus one times
fails:Enumerable#slice_when when not given a block raises an Argument error