Skip to content

Paul Kilgarriff - Birthdays TDD Challenge#28

Open
PKilgarriff wants to merge 13 commits intomakersacademy:masterfrom
PKilgarriff:master
Open

Paul Kilgarriff - Birthdays TDD Challenge#28
PKilgarriff wants to merge 13 commits intomakersacademy:masterfrom
PKilgarriff:master

Conversation

@PKilgarriff
Copy link
Copy Markdown

Paul Kilgarriff

Request for Code Review

  • Personal goals were:
    • to extract one class from another
    • to isolate tests for each class from one another
    • successfully decouple two classes

Blockers were around the initial design of the code (if it were done now I would spend more time in the design phase, with tools gained from Domain Modelling workshop) and the correct use of doubles to isolate class tests from one another without adding functionality not present in the mocked class. I struggled with mocking Date objects to the point where I abandoned the attempt, and the code as stands depends heavily on features of the Date class.

I'd appreciate feedback particularly on the current code's achievement of the above personal goals, but general feedback would be welcome too!

README checklist

Does your README contains instructions for

  • how to install,
  • how to run,
  • and how to test your code?

- ignore all .lock files
 - add methods
   - initialize
   - add(birthday)
   - print_all_birthdays
 - add attr_reader for birthdays
 - test storing a birthday
 - test printing all birthdays
 - add test for storing a name on initialisation
 - add initialize method that takes a name argument
   - defaults to "Unknown"
 - add methods
   - birthdate
   - age
   - birthday_today?
   - name attr_reader
   - same_month? private
   - same_day? private
 - remove attr_reader birthdays
 - add methods
   - size
   - birthday_check
 - update print_all_birthdays to out put string
 - add private methods
   - friendly_date
   - pad_number
   - print_reminder
 - then make formatting corrections based on suggestions
 - then make formatting corrections based on suggestions
 - change birthdate method to print_birthdate
 - add attr_reader for birthdate
 - reorganize spec file to use context and method decripions
 - print_reminder now takes two arguments
   - birthday object and today's date
 - print_reminder remove unnecessary local variable
- include SimpleCov in Gemfile and spec_helper
- Run SimpleCov
- remove print_birthdate method
- add test to cover add method
Rewrite readme file provided for the challenge.
Include sections:
- approach to the challenge
- running the program
- next steps
Copy link
Copy Markdown

@JohnForster JohnForster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a good solution, especially your mocked tests and readme. 👍

Comment thread lib/birthday.rb
end

def birthday_today?(today)
@today = today
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than storing @today as an instance variable, it's better to pass it directly to same_month and same_day as an argument. You should try to store as little in state (instance variables) as possible, as it means you have less to keep track of and update.

Today especially can be accessed with Date.today, so doesn't need to be an argument. If you want to make your method more flexible, I'd recommend using a default value:

def birthday?(day = Date.today)
  same_month?(day) && same_day?(day)
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same can be done for the age method above.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really useful to know - I'll update that now. I'm assuming it's still fine to have that dependency on Date, as it's being injected at the point of calling the method, and so can be mocked as needed.

Comment thread lib/birthday_list.rb
end

def size
@birthdays.count
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@birthdays.length would be the normal way of doing this, as #count has other functionality.

Comment thread lib/birthday_list.rb

def print_all_birthdays
@birthdays.each do |birthday|
puts "#{birthday.name} - #{friendly_date(birthday.birthdate)}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the printing functions be encapsulated in their own class, a BirthdayPrinter class for example?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hadn't thought of that - would make the Birthday class much neater, I will give that a go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants