Skip to content

Instantly share code, notes, and snippets.

@royosherove
Created February 23, 2012 12:04
Show Gist options
  • Save royosherove/1892558 to your computer and use it in GitHub Desktop.
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
[ ["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
@rauchy
Copy link

rauchy commented Feb 23, 2012

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

@jbrains
Copy link

jbrains commented Feb 23, 2012

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