inchworm

inchworms

Summer of Coding, one inch at a time...

Don't Unleash the Stubs!

inchworms -

Today we watched the rest of Part 2 of PeepCode’s excellent RSpec video tutorial. This one covered:

The three stages of testing

  • Automated testing with RSpec
  • Manual Testing with QA testing
  • Production deployment with customers

API discovery

  • Writing an example to describe expected output
  • Learning how an API works by writing examples
  • Using XPath syntax with Nokogiri (although @svenfuchs suggested using CSS instead)
  • Extracting the author name from an RSS feed

Custom Matcher

  • Extracting a post’s publication date
  • Parsing an XML date into a Ruby object
  • Writing a custom matcher (see David Chelimsky’s wiki)
  • Verifying the parsing of the date object

Configuration Options

  • Creating a .rpsec file
  • Understanding the options in the rspec command
  • Using an alternate report formatter
  • Setting custom options as the default

Retrieving Data

  • Retreiving data from an external server
  • Organising network code for easier testing

Stubs & Mocks

  • Understanding stubs and mocks
  • Using paceholder code to make your examples faster and more consistent
  • Intercepting network calls with a stub
  • Expecting specific methods to be called with a mock

Stub Syntax:

	# Syntax
	my_object.stub(:my_method).and_return(my_data)

	# Usage in this tutorial
	client.stub(:get).and_return(xml)

But don’t forget:

stubs

Context, Edge Cases, Corner Cases

  • Writing examples for non-successful edge and corner cases
  • Organising examples into success and error contexts
  • Learning to think about ways things could go wrong
  • Discovering errors and anticipating them in your code