Don’t assert return types | Jared Norman
12-Jan-2024 784
When done well, tests can serve as documentation describing how consumers of the object should interact with it. It’s not the primary goal of testing, but it’s worth considering when writing tests. What does a type assertion on the return value of our factory method tell us about the method? Not much, especially if our factory method never returns any other kind of object.Instead, the return value of the factory method should be tested for the behaviours it exposes. If we change the structure of the code later so that it returns some other kind of object, we want our tests to check that this new object works the way our consumers will expect it to. We don’t really care about its class.
Don’t assert return types | Jared Norman #ruby #rubydeveloper #rubyonrails #Don’t #assert #return #types #Jared #Norman #types https://rubyonrails.ba/link/don-t-assert-return-types-jared-norman