Skip to content

@wuputah /aaaa.md secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

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
Something went wrong with that request. Please try again.