blob: 7a489ab71b05034f5ba8e67e86329967bca2441d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
require "spec_helper"
class FizzBuzz
def print(item, printer)
printer << "Fizz" if fizzy?(item)
printer << "Buzz" if buzzy?(item)
#printer << item unless fizzy?(item) || buzzy?(item)
printer << item if printer.string == ""
end
def fizzy?(item)
(item % 3) == 0
end
def buzzy?(item)
(item % 5) == 0
end
end
describe FizzBuzz do
subject { FizzBuzz.new }
let(:printer) { StringIO.new }
it "should return Fizz for multiples of 3" do
subject.print(3, printer)
expect(printer.string).to eq("Fizz")
end
it "should return Buzz for multiples of 5" do
subject.print(5, printer)
expect(printer.string).to eq("Buzz")
end
it "should return FizzBuzz for multiples of 3 and 5" do
subject.print(15, printer)
expect(printer.string).to eq("FizzBuzz")
end
it "should return the number for everything else" do
subject.print(16, printer)
expect(printer.string).to eq("16")
end
end
|