Skip to content

Instantly share code, notes, and snippets.

@coryschires
Created November 23, 2012 21:49
Show Gist options
  • Save coryschires/4137456 to your computer and use it in GitHub Desktop.
Save coryschires/4137456 to your computer and use it in GitHub Desktop.
# Assumes your `days` method will return an array of hashes where the
# key specifies the month number (i.e. 1-12) and the value is an array
# containing the days of the month (i.e. 1-31) when the streets will
# be cleaned.
#
# Following that scheme then your data might looks something like:
#
# [
# 1: [7, 8], # January 7th and 8th
# 2: [2, 4],
# 3: [9, 10],
# 4: and so on ...
# ]
#
require 'spec_helper'
describeTicketInfo do
describe "days " do
it "should return Feb 2nd and 4th" do
ticket_info = TicketInfo.new(1, 1) # ward 1, section 1
ticket_info.days.should include(3: [2, 4])
end
it "should return March 9th and 10th" do
ticket_info = TicketInfo.new(1, 1) # ward 1, section 1
ticket_info.days.should include(3: [9, 10])
end
# And so on, creating similar tests for different months, wards, sections,
# etc until you feel confident that you're accurately parsing that JSON
# data. You obviously don't need to test nearly every case.
end
end
# From there, I would think about other questions you might want to ask the
# data. For example:
#
# Given a ward, section, and month, what days will the streets be cleaned?
# Given a ward and section, how many days until the next street cleaning?
#
# And you should - if possible - capture those questions in tests as well.
# Rails provides a lot of powerful methods for working with time.
#
# If you do it right, the tests will live on as a permanent part of the project,
# giving you confidence that the days you're emailing are actually correct.
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment