Created
August 3, 2010 14:08
-
-
Save jaz303/506426 to your computer and use it in GitHub Desktop.
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
# constructor = lambda { build_valid_user } | |
# truth_table = [ | |
# [ :account_admin=, :can_upload=, :"account.public_uploads_allowed=", :can_upload_files?, :can_upload_public_files?], | |
# [ false, false, false, false, false], | |
# [ true, false, false, true, true], | |
# [ false, true, false, true, false], | |
# [ true, true, false, true, true], | |
# [ false, false, true, false, false], | |
# [ true, false, true, true, true], | |
# [ false, true, true, true, true], | |
# [ true, true, true, true, true] | |
# ] | |
# | |
# assert_truth_table(constructor, truth_table) | |
# | |
def assert_truth_table(constructor, matrix) | |
field_list = matrix.shift.map(&:to_s) | |
matrix.each do |row| | |
instance = constructor.call | |
field_list.each_with_index do |fields,index| | |
next unless fields =~ /=$/ | |
chain = fields.split('.') | |
method, tmp = chain.pop, instance | |
chain.each { |m| tmp = tmp.send(m) } | |
tmp.send(method, row[index]) | |
end | |
field_list.each_with_index do |fields,index| | |
next if fields =~ /=$/ | |
chain = fields.split('.') | |
method, tmp = chain.pop, instance | |
chain.each { |m| tmp = tmp.send(m) } | |
assert_equal(row[index], tmp.send(method)) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Creating a “truth table” is not hard, you can use an useful tool (CKod, at http://ckod.sourceforge.net/_/) to make a “truth table”.
Good luck to you!