Created
October 7, 2010 21:53
-
-
Save zbrock/615961 to your computer and use it in GitHub Desktop.
This file contains 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
def should_be_a_subset(all_objects, constrained_scope, &condition) | |
flunk "Your superset is empty" if all_objects.empty? | |
flunk "Your constrained set is empty" if constrained_scope.empty? | |
objects_for_which_condition_is_true, objects_for_which_condition_is_false = all_objects.partition(&condition) | |
objects_for_which_condition_is_true.should_not be_empty | |
objects_for_which_condition_is_false.should_not be_empty | |
constrained_scope.map(&:id).sort.should == objects_for_which_condition_is_true.map(&:id).sort | |
(all_objects.map(&:id) - constrained_scope.map(&:id)).should == objects_for_which_condition_is_false.map(&:id) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment