Skip to content

Instantly share code, notes, and snippets.

@novikserg
Created January 19, 2017 01:51
Show Gist options
  • Save novikserg/f21a67671069ceef5b7b209404dfac1d to your computer and use it in GitHub Desktop.
Save novikserg/f21a67671069ceef5b7b209404dfac1d to your computer and use it in GitHub Desktop.
class BuckFizz
def print
all.each do |buck_fizz|
puts buck_fizz
end
end
private
def all
1.upto(100).map do |number|
case
when number % 15 == 0 then "BucksFizz"
when number % 3 == 0 then "Bucks"
when number % 5 == 0 then "Fizz"
else number
end
end
end
end
describe BuckFizz do
describe "#print" do
it "prints FizzBucks correctly" do
expect{ BuckFizz.new.print }.to output(start_with(
%w(1 2 Bucks 4 Fizz Bucks 7 8 Bucks Fizz 11 Bucks 13 14 BucksFizz 16).join("\n")
)).to_stdout
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment