下面是我为一小段 Ruby 代码编写的单元测试。
subject { AutoShop.new 'Mr. Fix It', 'WA987654321', Employee.new('Sue', 'Owner', 0) }
it '#employee_list returns list of employee names' do
# setup
input = [Employee.new('Lou', 'Receptionist', 90_000)]
subject.append_employees input
subject.employee_list.should eq "Sue\nLou"
end
这是该课程的代码。但是,我无法让名称在employee_list
方法中正确显示。我是 Ruby 的新手,所以任何建议都将不胜感激。
class AutoShop < Business
attr_accessor :employees
def initialize(name, tax_id, employee)
super(name, tax_id)
@employees = []
@employees << employee
end
def append_employees(input)
input.map { |x| @employees << x }
end
def employee_list
@employees.map {|x| x.name}
end
end