Skip to content

Instantly share code, notes, and snippets.

@wuputah

wuputah/aaaa.md Secret

Created September 22, 2010 03:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wuputah/6d02163e7c19c6ffeab0 to your computer and use it in GitHub Desktop.
Save wuputah/6d02163e7c19c6ffeab0 to your computer and use it in GitHub Desktop.

Assumptions

  • Assume there are functional specs as well, but they don't need to be changed to add this feature. Marking an invoice as paid is a PUT /invoices/123 with data { 'invoice' => { 'state' => 'paid' } }.
  • The view has been modified to display the "paid" badge, which uses invoice.paid?.

Thoughts

The main issue with this example, to me, is excessive unit testing. Is it worth the time to test Invoice#paid? in this manner? Requiring such test coverage can lead to laziness to avoid tests--you could do this by writing invoice.state == 'paid' in the view. The tests are also closely tied to the implementation (since the implementation is so simple).

class Invoice < ActiveRecord::Base
def paid?
state == 'paid'
end
end
describe Invoice
# normally would use factory_girl here, actually.
let(:invoice) { Invoice.new(:state => state) }
let(:state) { 'unpaid' }
describe '#paid?' do
subject { invoice.paid? }
context 'when state is paid' do
let(:state) { 'paid' }
it { should be_true }
end
context 'when state equals other values' do
let(:state) { 'foo' }
it { should be_false }
end
end
end
Feature: Invoice should appear as paid
Background:
Given I am logged in as a user
And I have created an invoice with ID "123"
And I am on the invoice page for ID "123"
Scenario: Mark bill as paid
When I click on "Mark as paid"
Then I should see a notice that "Invoice #123 has been marked as paid"
And the "Paid" badge should appear over the invoice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment