Which do you prefer? You have seen three different forms:
- First, you saw Examples simply using the calculator.
- Second, you saw Examples using a combination of support methods and using the calculator.
- Now, you see an Example only using support methods.
The first form gives a concrete example of how the RpnCalculator should be used. The last form makes the Example easy to read and moves the writing of the examples into the way a user might speak about using the calculator.
Here is just he Basic Math Operators context updated:
Here’s a side-by-side comparison between the two styles:
|
|
Before thinking that one style is the “right” style, consider the audience and even the author. If the audience is the user, then the style on the right is more appropriate. If the audience is another developer, then the left side might be more appropriate.</span>
You might think that using the methods names on the right for your calculator is an option. However, that won’t look correct:
The method names do not make sense being sent to a calculator. So the method names make sense on the left when sent to a calculator. The method names on the right make sense when reading an example.
While this tutorial will not cover it, RSpec has the notion of “story tests”, or tests that are meant to be written by the same people who write user stories, your customer, product owner, QA person or even developers. That’s coming up in a later tutorial, so this subject will come up again.
Comments