Skip to content

Commit

Permalink
Add specs for inject
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabigeek committed Feb 1, 2024
1 parent 6b0c323 commit 7131244
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/ruby/core/enumerable/shared/inject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-).should == 4
end

it "can take a string as the second argument" do
EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, "-").should == 4
end

it "ignores the block if two arguments" do
-> {
EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-) { raise "we never get here"}.should == 4
Expand All @@ -41,6 +45,10 @@
EnumerableSpecs::Numerous.new(10, 1, 2, 3).send(@method, :-).should == 4
end

it "can take a string argument" do
EnumerableSpecs::Numerous.new(10, 1, 2, 3).send(@method, "-").should == 4
end

it "without argument takes a block with an accumulator (with first element as initial value) and the current element. Value of block becomes new accumulator" do
a = []
EnumerableSpecs::Numerous.new.send(@method) { |memo, i| a << [memo, i]; i }
Expand Down

0 comments on commit 7131244

Please sign in to comment.