Develop An RSpec Test Suite (Choose Your Own Test Adventure)

2015-02-10 by Michael Stalker (Meetup)

Tests should not be an excuse for thinking. Rich Hickey

Things Turn Confusing

  • tests interact with database?
  • et cetera...

Dragons

  • never-ending tests
  • excessive setup
  • fragile tests
  • hard to write
  • intermittent failures
  • tests stay broken

Why?

  • tightly-coupled code
  • non-isolated tests
  • over-specified testing

Mocks And Stubs

# mock requires the target to receive some method
expect(User).to receive(:foo).and_return(:bar)
# stub allows the target to receive some method
allow(User).to receive(:foo).and_return(:bar)

Testing awful code

  • do whatever is needed to get the code under test