Skip to content

Instantly share code, notes, and snippets.

@zbrock
Created October 7, 2010 21:53
Show Gist options
  • Save zbrock/615961 to your computer and use it in GitHub Desktop.
Save zbrock/615961 to your computer and use it in GitHub Desktop.
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