Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Â
Can you TDD Rails?
1. Can you TDD Rails?
@andrzejkrzywda
(in love/hate relationship with Rails, since 2004)
Arkency
2. ⢠âWhat does this code really do?â
⢠âCan I safely remove it?â
⢠âI see dead codeâ
⢠âIâm afraid to change this codeâ
⢠âThis code is uglyâ
⢠âOh, itâs a mock that returns a mock that returns
a mockâ
Things developers say
4. ⢠âWhere do I start with this feature?â
⢠âWill I break anything?â
⢠âIâll just add a bool parameter here and an if
thereâ
⢠âChanging this will break dozens of testsâ
7. ⢠âWhat does this code really do?â
⢠âCan I safely remove it?â
⢠âI see dead codeâ
⢠âIâm afraid to change this codeâ
⢠âThis code is uglyâ
⢠âOh, itâs a mock that returns a mock that returns
a mockâ
Things developers say
8. ⢠âWhere do I start with this feature?â
⢠âWill I break anything?â
⢠âIâll just add a bool parameter here and an if
thereâ
⢠âChanging this will break dozens of testsâ
28. TDD hard skills
⢠tools - rspec, xunit, guard
⢠automatic run
⢠full suite vs partial suite
⢠TDD JavaScript tools
⢠IDEs
29. TDD soft skills
⢠spikes
⢠GTD
⢠Continuous delivery (commit after every cycle)
⢠triangulation
⢠isolate from the framework (aka the Rails sandwich)
⢠tests refactoring
⢠when to mock?
30. Spikes
⢠âItâs not clear to me, what I need to doâ
⢠a prototype
⢠throw-away code
⢠cowboy hacking
⢠timeboxed
⢠make notes
⢠can be temporarily deployed, if itâs âsecureâ just to feel it
31. Getting Things Done
⢠âI know what to do, now just do itâ
⢠checklists
⢠Pomodoro
⢠procrastination
32. Continuous Delivery
⢠Commit/push after every red/green/refactor
cycle
⢠push == deploy
⢠small steps
⢠donât break the existing code
⢠always green
33. TDD triangulation
⢠the simplest possible test
⢠make it green in the stupid way
⢠next test
⢠implement with an âifâ
⢠next test
⢠refactor and implement the right way
34. Framework isolation
⢠controller? - extract service object or a query
object, as early as possible
⢠model? - move logic to service object
⢠no need to test ActiveRecord
⢠extract repository object
⢠render views with locals
35. tests refactoring
⢠test is code too
⢠make it short, elegant, easy to read
⢠apply Clean Code rules
⢠feel free to remove some tests
38. exercising TDD
⢠code kata
⢠YouTube: TDD
⢠extract business logic as a gem, TDD that
⢠âdomain spikeâ - what if all objects can live in
memory (no db) and thereâs no boundaries (http,
api), just objects
⢠15 minutes a day
39. Itâs all up to you to
learn how to TDD Rails
Thanks!
http://rails-refactoring.com/