-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfizzbuzz_generator_spec.rb
More file actions
58 lines (53 loc) · 1.82 KB
/
fizzbuzz_generator_spec.rb
File metadata and controls
58 lines (53 loc) · 1.82 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# fizz buzz generator spec
require './fizzbuzz_generator'
describe FizzBuzzGenerator, "#print" do
context 'given 15 as an input'
it "returns fizzbuzz for numbers 1 through 15" do
fizzbuzz = FizzBuzzGenerator.new(15)
fizzbuzz.generate
fizzbuzz.print.should eq(["1","2","3 fizz","4","5 buzz","6 fizz","7","8","9 fizz","10 buzz","11","12 fizz","13","14","15 fizzbuzz"])
end
context 'given 0 as input'
it "returns 'not supported message' if 0 supplied" do
fizzbuzz = FizzBuzzGenerator.new(0)
fizzbuzz.generate
fizzbuzz.print.should eq(["Zero, negative numbers, and nil not supported"])
end
context 'given negative input'
it "returns 'not supported message' if 0 supplied" do
fizzbuzz = FizzBuzzGenerator.new(-5)
fizzbuzz.generate
fizzbuzz.print.should eq(["Zero, negative numbers, and nil not supported"])
end
context 'given nil input'
it "returns 'not supported message' if nothing supplied" do
fizzbuzz = FizzBuzzGenerator.new()
fizzbuzz.generate
fizzbuzz.print.should eq(["Zero, negative numbers, and nil not supported"])
end
end
describe FizzBuzzGenerator, "#html" do
it "returns fomatted html for numbers 1 through 10" do
fizzbuzz = FizzBuzzGenerator.new(10)
fizzbuzz.generate
fizzbuzz.html.should eq("<ul>
<li> 1 </li>
<li> 2 </li>
<li> 3 fizz </li>
<li> 4 </li>
<li> 5 buzz </li>
<li> 6 fizz </li>
<li> 7 </li>
<li> 8 </li>
<li> 9 fizz </li>
<li> 10 buzz </li>
</ul>")
end
end
describe FizzBuzzGenerator, "#json" do
it "returns json output for numbers 1 through 12" do
fizzbuzz = FizzBuzzGenerator.new(12)
fizzbuzz.generate
fizzbuzz.json.should eq("\"[\\\"1\\\",\\\"2\\\",\\\"3 fizz\\\",\\\"4\\\",\\\"5 buzz\\\",\\\"6 fizz\\\",\\\"7\\\",\\\"8\\\",\\\"9 fizz\\\",\\\"10 buzz\\\",\\\"11\\\",\\\"12 fizz\\\"]\"")
end
end