Created
September 8, 2010 17:36
-
-
Save bkaney/570467 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
describe Committee do | |
it { should link_one(:municipality) } | |
end |
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
Rspec::Matchers.define :link_one do |expected| | |
match do |actual| | |
(actual.should include_association(expected)) && | |
(actual.should associate_one(expected)) | |
end | |
end | |
# "lower-level" matchers | |
Rspec::Matchers.define :associate_one do |expected| | |
match do |actual| | |
actual.class.associations[expected.to_sym].try(:one?) | |
end | |
failure_message_for_should do |actual| | |
"expected #{ actual.class.associations[expected.to_sym].inspect} to associate one" | |
end | |
failure_message_for_should_not do |actual| | |
"expected #{ actual.class.associations[expected.to_sym].inspect} to not associate one" | |
end | |
end | |
Rspec::Matchers.define :include_association do |expected| | |
match do |actual| | |
actual.class.associations.keys.map(&:to_sym).include?(expected.to_sym) | |
end | |
failure_message_for_should do |actual| | |
"expected #{actual.class.associations.keys.map(&:to_sym)} to include #{expected.to_sym}" | |
end | |
failure_message_for_should_not do |actual| | |
"expected #{actual.class.associations.keys} to not include #{expected}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment