Don’t assert return types | Jared Norman

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 #types https://rubyonrails.ba/single/don-t-assert-return-types-jared-norman

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles