Created
November 14, 2013 17:18
-
-
Save sarogers/7470647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Complete the "my_each" method. | |
def my_each | |
end | |
describe "my_each" do | |
it "should let us iterate over a collection of objects and do stuff" do | |
students = [ | |
{ name: 'Rachael' }, | |
{ name: 'Josephina'}, | |
{ name: 'Benedict'} | |
] | |
my_each(students) do |student| | |
student[:enrolled] = true | |
end | |
students[0][:enrolled].should == true | |
students[1][:enrolled].should == true | |
students[2][:enrolled].should == true | |
end | |
it "should return the original collection" do | |
array = %w(foo bar baz qux) | |
my_each(array) do |word| | |
word.upcase | |
end.should == %w(foo bar baz qux) | |
end | |
it "should not execute the block given an empty collection" do | |
o = Object.new | |
o.should_not_receive(:methods) | |
my_each([]) do |n| | |
o.methods | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment