首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >conference_badges #打印机应该放置徽章和room_assignments的列表

conference_badges #打印机应该放置徽章和room_assignments的列表
EN

Stack Overflow用户
提问于 2016-08-02 01:25:47
回答 1查看 453关注 0票数 0

因此,当我运行我的代码时,我目前正在得到以下错误。我在另一个函数中使用了一个函数,我认为这是问题的根源,但是指令要求它这样做。

提示:请记住,方法可以调用其他方法。如果assign_rooms的返回值是一个房间分配数组,那么如何打印每个赋值?您将需要迭代您的房间分配数组,以便完成每个单独的任务。

代码语言:javascript
复制
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

这是在运行以下代码时给出的:

代码语言:javascript
复制
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

但我不明白为什么不匹配Rspec的输出:

代码语言:javascript
复制
 # 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

EN

回答 1

Stack Overflow用户

发布于 2016-08-02 02:20:39

这个问题解决了:

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38710435

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档