0
構建新客戶在進入熟食店時將使用的方法。 take_a_number方法應該接受兩個參數,即當前行的數組(katz_deli)和包含想要加入行的人的名稱的字符串。該方法應該返回該人的姓名以及他們的位置。我該如何安排,以便當前行的數組等於names數組的數量?
katz_deli = []
def line(array)
if array[0] == nil
puts "The line is currently empty."
end
end
def take_a_number(array, name)
i=0
counter = 1
while array.count != name.length
array[i] = counter
i+=1
counter +=1
end
if array.count > 1
puts "The line is currently:"
end
name.each_with_index {|val, index| puts "#{index+1}. #{val}"}
end
這裏是Rspec的文件:
describe 'Deli Counter' do
let(:katz_deli) { [] }
let(:other_deli) { ["Logan", "Avi", "Spencer"] }
describe "#line" do
context "there is nobody in line" do
it "should say the line is empty" do
# This line checks the current standard output (your terminal screen)
# to make sure the correct output has been puts'ed.
expect($stdout).to receive(:puts).with("The line is currently empty.")
line(katz_deli)
end
end
context "there are people in line" do
it "should display the current line" do
expect($stdout).to receive(:puts).with("The line is currently: 1. Logan 2. Avi 3. Spencer")
line(other_deli)
end
end
end