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: d64a4567746b
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7e5c87e75930
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Mar 3, 2015

  1. Copy the full SHA
    c3fd4a3 View commit details
  2. Copy the full SHA
    44e57fd View commit details
  3. Merge pull request #3339 from jsyeo/add-slice-after-spec

    Add spec for Enumerable#slice_after
    Yorick Peterse committed Mar 3, 2015
    Copy the full SHA
    7e5c87e View commit details
Showing with 59 additions and 0 deletions.
  1. +53 −0 spec/ruby/core/enumerable/slice_after_spec.rb
  2. +6 −0 spec/tags/ruby/core/enumerable/slice_after_tags.txt
53 changes: 53 additions & 0 deletions spec/ruby/core/enumerable/slice_after_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Enumerable#slice_after" do
before :each do
@enum = EnumerableSpecs::Numerous.new(7, 6, 5, 4, 3, 2, 1)
end

describe "when given an argument and no block" do
it "calls === on the argument to determine when to yield" do
arg = mock "filter"
arg.should_receive(:===).and_return(false, true, false, false, false, true, false)
e = @enum.slice_after(arg)
e.should be_an_instance_of(enumerator_class)
e.to_a.should == [[7, 6], [5, 4, 3, 2], [1]]
end

it "doesn't yield an empty array if the filter matches the first entry or the last entry" do
arg = mock "filter"
arg.should_receive(:===).and_return(true).exactly(7)
e = @enum.slice_after(arg)
e.to_a.should == [[7], [6], [5], [4], [3], [2], [1]]
end

it "uses standard boolean as a test" do
arg = mock "filter"
arg.should_receive(:===).and_return(false, :foo, nil, false, false, 42, false)
e = @enum.slice_after(arg)
e.to_a.should == [[7, 6], [5, 4, 3, 2], [1]]
end
end

describe "when given a block" do
describe "and no argument" do
it "calls the block to determine when to yield" do
e = @enum.slice_after{ |i| i == 6 || i == 2 }
e.should be_an_instance_of(enumerator_class)
e.to_a.should == [[7, 6], [5, 4, 3, 2], [1]]
end
end

describe "and an argument" do
it "raises an Argument error" do
lambda { @enum.slice_after(42) { |i| i == 6 } }.should raise_error(ArgumentError)
end
end
end

it "raises an Argument error when given an incorrect number of arguments" do
lambda { @enum.slice_after("one", "two") }.should raise_error(ArgumentError)
lambda { @enum.slice_after }.should raise_error(ArgumentError)
end
end
6 changes: 6 additions & 0 deletions spec/tags/ruby/core/enumerable/slice_after_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fails:Enumerable#slice_after when given an argument and no block calls === on the argument to determine when to yield
fails:Enumerable#slice_after when given an argument and no block doesn't yield an empty array if the filter matches the first entry or the last entry
fails:Enumerable#slice_after when given an argument and no block uses standard boolean as a test
fails:Enumerable#slice_after when given a block and no argument calls the block to determine when to yield
fails:Enumerable#slice_after when given a block and an argument raises an Argument error
fails:Enumerable#slice_after raises an Argument error when given an incorrect number of arguments