Create a Ruby Gem. Real World, play by play. Part 3
Part 3 of the Gem creation tutorial that follows the conception of a real Gem.
I left off in Part 2 creating a way to configure the persistent locations of the Intuit company id and OAuth information. In Part 3, I need to wire up the
oauth_client method to retrieve the configuration settings. As in Part 2, these objectives will pose some interesting challenges.
- Back in
base.rbI create 3 methods:
send_chainto handle acquiring persistent information.
- Next, I want to start testing my design but I need to go back to the
configuration.rbcode as I haven't verified that it does what it is supposed to do.
- Next, I spec the default configuration values, which are 2 association levels deep. (
- The previous step's spec passes. Lastly, I test a 1-level-deep association.
- I modify the
oauth_clientmethod to use the new
- I go back to finish the
create_service_formethod now that the
oauth_clientmethod is completed.
- I spec
create_service_for, which will also test the
retrievemethod returns a string back from the configuration code (say "
settings.qb_token"). It then splits the string into an array (
[ 'settings', 'qb_token' ]). The array is fed into the
send_chainmethod that will create a 'send_chain' if the array is size is greater than 1. (e.g.
Hey Minimul, that is a lot of code with no tests? Where are the tests?
There coming next but let me say that I mostly write tests or specs last, not first. I design and architect the application code first. Then I write automated tests to confirm my design. I also generally do not write many finely granular tests but write at a "courser" or higher level, testing many methods in one spec.
I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence. — Kent Beck
If you find your testers splitting up functions to support the testing process, you’re destroying your system architecture and code comprehension along with it. Test at a coarser level of granularity. — James O Coplien
oauth_clientmodifications and testing start at the 13:55 mark in the screencast.
Great, finished and verified the 'oauth_client' and 'create_service_for' methods. This is a good place to stop for Part 3.
In the next installment I will finish and publish the Gem. Please note that the last screencast is already completed so check it out:
- Pushed on 05/06/2014 by Christian