Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiple expect invocations inside a single test example
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
@rayfix

This comment has been minimized.

Copy link
Owner Author

@rayfix rayfix commented Apr 22, 2015

Oops ... I forgot to freeze with Timecop. Left as an exercise for the reader. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment