Skip to content

Instantly share code, notes, and snippets.

@godfat
Created April 24, 2014 14:34
Show Gist options
  • Save godfat/11256842 to your computer and use it in GitHub Desktop.
Save godfat/11256842 to your computer and use it in GitHub Desktop.
require 'bacon'
require 'rubyqc'
Bacon.summary_on_exit
Bacon::Context.include RubyQC::API
class User < Struct.new(:name, :gold)
def self.rubyqc
new(String.rubyqc, (0..99).rubyqc)
end
def give that, amount
if gold >= amount
self.gold -= amount
that.gold += amount
true
else
false
end
end
end
describe User do
should 'Generate random users' do
check(User) do |user|
user .should.kind_of User
user.name.should.kind_of String
user.gold.should.kind_of Fixnum
end
end
should 'Give gold to others' do
check(User, User, 0..99) do |a, b, gold|
total = a.gold + b.gold
agold = a.gold
a.give(b, gold).should == gold <= agold
a.gold.should >= 0
b.gold.should >= 0
(a.gold + b.gold).should == total
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment