2016-08-02 13 views
0

So bekomme ich derzeit den folgenden Fehler, wenn ich meinen Code ausführen. Ich habe eine Funktion in einer anderen Funktion verwendet, von der ich glaube, dass sie die Wurzel des Problems ist, aber sie wurde von den Anweisungen dazu aufgefordert.conference_badges #printer sollte die Liste der Badges und room_assignments setzen

Hinweis: Denken Sie daran, dass Methoden andere Methoden aufrufen können. Wenn der Rückgabewert von assign_rooms ein Array von Raumzuweisungen ist, wie können Sie jede Zuweisung ausdrucken? Sie müssen über Ihr Array von Raumzuweisungen iterieren, um die einzelnen Aufgaben zu verteilen.

Failures: 
 

 
    1) conference_badges #printer should puts the list of badges and room_assignments 
 
    Failure/Error: expect($stdout).to receive(:puts).with(line.chomp) 
 
     
 
     (#<IO:<STDOUT>>).puts("Hello, my name is Edsger.") 
 
      expected: 1 time with arguments: ("Hello, my name is Edsger.") 
 
      received: 0 times 
 
    # ./spec/conference_badges_spec.rb:98:in `block (4 levels) in <top (required)>' 
 

 
Finished in 0.02707 seconds (files took 0.28753 seconds to load) 
 
4 examples, 1 failure

Welche geben wird, wenn ich den folgenden Code ausführen:

def badge_maker(name) 
 
    return "Hello, my name is #{name}." 
 
end 
 

 
def batch_badge_creator(names) 
 
    greetings = [] # initialize greetings as an empty array 
 
    names.each do |name| # for each name in the names array 
 
    greetings << badge_maker(name)# add a greeting for that name 
 
    end 
 
    return greetings # return the array of all greetings, at the end 
 
end 
 

 
def assign_rooms(speakers) 
 
    greet = [] 
 
    speakers.each_with_index{ |speakers, index| greet << "Hello, #{speakers}! You'll be assigned to room #{index+1}!"} 
 
    return greet 
 
    end 
 

 
def printer(inputOne) 
 
    batch_badge_creator(inputOne) 
 
    assign_rooms(inputOne) 
 

 
end

Aber ich nicht, warum nicht ist passend zu den Ausgangs von Rspec:

# Question 4 
 
    # The method `printer` should output first the results of the batch_badge_creator method and then of the assign_rooms method to the screen - this way you can output 
 
    # the badges and room assignments one at a time. 
 
    # To make this test pass, make sure you are iterating through your badges and room assignments lists. 
 

 

 
    it 'should puts the list of badges and room_assignments' do 
 
     badges_and_room_assignments.each_line do |line| 
 
     # $stdout is a Ruby global varibale that represents the current standard output. 
 
     # In this case, the standard output is your terminal screen. This test, then, 
 
     # is checking to see whether or not your terminal screen receives the correct 
 
     # printed output. 
 
     expect($stdout).to receive(:puts).with(line.chomp) 
 
     end 
 
     printer(attendees) 
 
    end 
 

 
    end 
 

 
end

Antwort

0

Dieses es fest:

def badge_maker(name) 
 
    return "Hello, my name is #{name}." 
 
end 
 

 
def batch_badge_creator(names) 
 
    greetings = [] # initialize greetings as an empty array 
 
    names.each do |name| # for each name in the names array 
 
    greetings << badge_maker(name)# add a greeting for that name 
 
    end 
 
    return greetings # return the array of all greetings, at the end 
 
end 
 

 
def assign_rooms(speakers) 
 
    greet = [] 
 
    speakers.each_with_index{ |speakers, index| greet << "Hello, #{speakers}! You'll be assigned to room #{index+1}!"} 
 
    return greet 
 
    end 
 

 
def printer(attendees) 
 
    resultOne = batch_badge_creator(attendees) 
 
    resultOne.each do |x| 
 
    puts x 
 
    end 
 
    result = assign_rooms(attendees) 
 
    result.each do |x| 
 
    puts x 
 
    end 
 
end