Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9288685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:58:07+00:00 2026-06-18T19:58:07+00:00

Below is the unit test I wrote for a small piece of Ruby code.

  • 0

Below is the unit test I wrote for a small piece of Ruby code.

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

And here is the code for the class. However, I cannot get the names to display properly in the employee_list method. I’m brand new to Ruby, so any suggestions would be greatly appreciated.

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     
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:58:08+00:00Added an answer on June 18, 2026 at 7:58 pm

    Your employee_list method, based on your unit test, should output each name separated by a linebreak \n. So, add a .join("\n") to produce a string from the array.

    def employee_list
      @employees.map {|x| x.name }.join("\n")
    end  
    

    The .map can be done with a “pretzel-colon” shorthand too:

    @employees.map(&:name).join("\n")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote below unit for a sample component : unit Test; interface uses System.SysUtils,
I want to unit test the code below. I've been working with MSTest and
I wrote below code, try to test if a jquery dialog get excused and
Below I have some code that that I cannot Unit test because it tries
The below Unit Test fails, and I am looking for a valid reason for
I have the below class I want to unit test: public class MyClass {
I have the below route. In unit test, since I doesn't have the FTP
I am creating unit test py file (tests.py) then i received the below error
I'm working on unit-tests for an application and below is a unit-test I just
How do I convert the below piece of java code to C++. I know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.