GildedRose-Refactoring-Kata/js-jasmine
2020-12-04 09:20:21 +00:00
..
spec Add conjured items 2020-12-04 09:10:18 +00:00
src Add eslint and apply fixes 2020-12-04 09:20:21 +00:00
.eslintrc.json Add eslint and apply fixes 2020-12-04 09:20:21 +00:00
.gitignore Splits JS Jasmine and Mocha starting points into separate toplevel folders similar to Java and Java-Spock. 2018-12-02 20:59:38 +01:00
package-lock.json Add eslint and apply fixes 2020-12-04 09:20:21 +00:00
package.json Add eslint and apply fixes 2020-12-04 09:20:21 +00:00
README.md Add eslint and apply fixes 2020-12-04 09:20:21 +00:00

Gilded Rose

The task

Take existing legacy code and add a new feature.

Approach

  1. Write tests for existing functionality.

This allowed me to refactor the code while knowing I wasn't breaking any functionality.

  1. Refactor existing code incrementally.

It is valuable to have the code formatted using best practices. In order not to break existing functionality I refactored incrementally, running tests and commiting after each small change. This refactor made it much easier to add my feature, but will also improve long term reliability of the code, and future proof it for future feature additions.

  1. TDD new feature.

Having performed the previous two steps, this one was very easy.

Limitations

The test spec required that I did not alter the Item class. This made it more difficult to apply OOD principles. I have instead created a module for each item type, which still allows for encapsulation.

My tests verged on state driven rather than behaviour driven. I could not find an equivalent of RSpec's "change by" matcher for Jasmine. Any tips would be appreciated.

With more time I would add a 'sellInChange' function to each item type to mirror the qualityChange. The different sellIn change for Sulfurus is still handled by exception.