Created
February 23, 2012 12:04
-
-
Save royosherove/1892558 to your computer and use it in GitHub Desktop.
There's has to be a cleaner way to do this with rspec and ruby
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
[ ["1,2",3], ["1,3",4] ].each do |arr| | |
it "'s add method should return the sum of multiple numbers" do | |
StringCalc.new.add(arr[0]).should == arr[1] | |
end | |
end |
I'd do something similar, but use example
in place of it
.
context "when adding numbers" do
{"1,2" => 3, "1,3" => 4}.each do |input, expected|
example input do # input is already a String, and no need to add surrounding text
StringCalc.new.add(input).should == expected
end
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not way cleaner, but what about:
{"1,2" => 3,
"1,3" => 4 }.each do |numbers, expected|
it "'s add method should return the sum of multiple numbers" do
StringCalc.new.add(numbers).should == expected
end
end