Skip to content

Commit 0a530a0

Browse files
committed
added test/function for any string
code now returns "I need to know how many bottles to sing!" if input was a string
1 parent a850d2a commit 0a530a0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

bin/beer_on_the_wall.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
puts "How many bottles?"
22

33
beer = gets.chomp
4-
if beer == ""
4+
beer_as_int = beer.to_i
5+
if beer != beer_as_int.to_s
56
puts "I need to know how many bottles to sing!"
67
else
7-
beer = Integer(beer)
8+
beer=beer.to_i
89
end
910

1011
def firstBeer(be)

spec/beer_on_the_wall_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@
5050
expect(all_output).to_not include("1 bottle of beer on the wall, 1 bottle of beer.\nTake one down and pass it around, no bottles of beer on the wall.\n")
5151
end
5252

53+
it "throws an error if it does not know how many number of bottles" do
54+
run_script("beer_on_the_wall.rb")
55+
type("no")
56+
57+
expect(all_output).to match("I need to know how many bottles to sing!")
58+
expect(all_output).to_not include("1 bottle of beer on the wall, 1 bottle of beer.\nTake one down and pass it around, no bottles of beer on the wall.\n")
59+
end
60+
5361
end

0 commit comments

Comments
 (0)