Skip to content

Instantly share code, notes, and snippets.

@artm
Last active December 15, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artm/5180707 to your computer and use it in GitHub Desktop.
Save artm/5180707 to your computer and use it in GitHub Desktop.
DRYer specs
module Something
def self.foo a, *args
a.zip(*args).flatten.select{|e|e}
end
end
require 'minitest/autorun'
require 'something'
describe Something do
{
"with 1 array" => [ [1,2,3] ],
"with 2 arrays" => [ [1,2,3], [4,5,6] ],
"with more than 2 arrays" => [ [1,2,3], [4,5,6], [7], [8,9] ],
}.each do |title,data|
describe title do
it "returns all elements" do
Something.foo(*data).count.must_equal data.reduce(0){|sum,a|sum+a.count}
do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment