Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created April 22, 2015 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayfix/be12a46004bf2aececa5 to your computer and use it in GitHub Desktop.
Save rayfix/be12a46004bf2aececa5 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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