This exercise is designed to help us discuss designing programs for testability, especially when working with external dependencies such as a required data import task.
.
├── Gemfile
├── Gemfile.lock
├── README.md
├── data
│ └── toppings.csv
├── lib
│ ├── topping.rb
│ └── toppings_menu.rb
└── test
├── topping_test.rb
└── toppings_menu_test.rb
Complete this exercise by building out the following 2 classes:
- A
Topping
class which can be created with three values:name
,price
, and anis_vegetarian
value. The Topping should expose methods for each of these values, and theis_vegetarian
should return a boolean - A
ToppingsMenu
class which can hold a collection ofTopping
objects. TheToppingsMenu
should also feature aload_menu
method which accepts a filepath to a CSV and creates appropriateTopping
objects for each row in the file - The
ToppingsMenu
should provide a methodfind_by_name
which accepts a topping name (a string) and returns theTopping
instance which matches that name
Example Usage
tm = ToppingMenu.new
tm.load_data("./data/toppings.csv")
t = tm.find_by_name("anchovies")
t.name
=> "anchovies"