Simplifying Tests by Extracting Side-Effects
Test-driven development, object-oriented design, and functional programming converge on some similar ideas.Functional programming gives us a mental model that can be helpful when looking at unit testing our object-oriented code. In particular, it gives us two terms:Pure functions - these are deterministic methods with explicit inputs and outputs (e.g. no implicit dependency on the system clock). This kind of method is the easiest to test.Side-effects - Any source of inputs or outputs for a method that are not part of the arguments or return value. Examples include calls to Time.now, or writing the output to a file. These types of methods are non-deterministic, which makes them trickier to test and usually involves some mocking or stubbing.
Simplifying Tests by Extracting Side-Effects #ruby #rails #rubyonrails #bosnia #programming #tutorials #rubydeveloper #railsdeveloper