O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining the Ledger

We’ll start with an empty Ledger class. In your project directory, create a new file called app/ledger.rb with the following contents:

 module​ ExpenseTracker
  RecordResult = Struct.new(​:success?​, ​:expense_id​, ​:error_message​)
 
 class​ Ledger
 end
 end

Notice we’ve also moved the temporary RecordResult struct definition from earlier into its permanent home here. Don’t forget to delete the old version of RecordResult from spec/unit/app/api_spec.rb.

You’ll need to require this new file from app/api.rb:

 require_relative ​'ledger'

The specs you have so far are still using the fake ledger. They passed without a real Ledger ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required