Created
April 22, 2015 01:37
-
-
Save rayfix/be12a46004bf2aececa5 to your computer and use it in GitHub Desktop.
Multiple expect invocations inside a single test example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/all' | |
class Subscription | |
def initialize(created_at:) | |
@created_at = created_at | |
end | |
attr_reader :created_at | |
def months_subscribed | |
((Date.today - created_at.to_date) / 30).round | |
end | |
end | |
describe "#months_subscribed" do | |
it "should compute the correct number of rounded months" do | |
test_vector = [[0,0], [10,0], [14,0], [15, 1], [16,1], [32,1], [44,1], [46,2]] | |
test_vector.each do |test_case| | |
subscription = Subscription.new(created_at: test_case[0].days.ago) | |
expect(subscription.months_subscribed).to eq test_case[1] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oops ... I forgot to freeze with Timecop. Left as an exercise for the reader. :)