Skip to content

Instantly share code, notes, and snippets.

@mungruby
Created November 2, 2011 14:50
Show Gist options
  • Save mungruby/1333813 to your computer and use it in GitHub Desktop.
Save mungruby/1333813 to your computer and use it in GitHub Desktop.
rspec inject examples
C:\projects\ruby\enumerable\inject>rspec inject_spec.rb -fdoc
Enumerable#inject
Array
should respond to #inject
Hash
should respond to #inject
0..100 (a Range)
should respond to #inject
with an explicit subject
should respond to #inject
when provided the name of a method as an argument
should call that argument passing in each successive member
Finished in 0 seconds
5 examples, 0 failures
describe "Enumerable#inject" do
context Array do
it {should respond_to :inject}
end
context Hash do
it {should respond_to :inject}
end
context (0..100), "(a Range)" do
it {should respond_to :inject}
end
context "with an explicit subject" do
subject {%w[first second third]}
it {should respond_to :inject}
end
context "when provided the name of a method as an argument" do
it "should call that argument passing in each successive member" do
%w[this fine day].inject(:+).should == "thisfineday"
accumulator = []
%w[this fine day].inject(accumulator, :push)
accumulator.should == ['this', 'fine', 'day']
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment