Skip to content

Instantly share code, notes, and snippets.

@laser
Last active January 4, 2016 09:39
Show Gist options
  • Select an option

  • Save laser/8603966 to your computer and use it in GitHub Desktop.

Select an option

Save laser/8603966 to your computer and use it in GitHub Desktop.
Table based testing
# Account = Struct.new(:id, :last_active)
describe 'pruning expired accounts' do
let(:f) {
# an account factory
lambda do |id, last_active=Date.today|
Account.new(id, last_active)
end
}
it 'prunes accounts based on last_active and id' do
cases = [
{
input: [f.(1), f.(2), f.(3)],
output: [f.(1), f.(2), f.(3)],
message: 'all three are valid'
}, {
input: [f.(1), f.(2), f.(3, Date.today-30)],
output: [f.(1), f.(2)],
message: 'third is expired'
}, {
input: [f.(1), f.(2, Date.today-30), f.(3, Date.today-30)],
output: [f.(1)],
message: 'second and third are expired'
}, {
input: [f.(-1), f.(2), f.(3)],
output: [f.(2), f.(3)],
message: 'first has invalid id'
}
]
# ...
cases.each do |c|
expect(AccountPruner.prune(*c[:input])).to eq(c[:output]), c[:message]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment