Last active
January 4, 2016 09:39
-
-
Save laser/8603966 to your computer and use it in GitHub Desktop.
Table based testing
This file contains hidden or 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
| # 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