From d1b2a1d074ea2badc8f68f0fcfc38eda364da372 Mon Sep 17 00:00:00 2001 From: Jason Draper Date: Mon, 16 Sep 2013 09:38:01 -0400 Subject: [PATCH] Create a shared example for Numercial Submatchers. * Verify that all submatchers respond to the necessary interface * See: #357 for a reason why this is necessary --- .../active_model/comparison_matcher_spec.rb | 4 ++++ .../odd_even_number_matcher_spec.rb | 4 ++++ .../active_model/only_integer_matcher_spec.rb | 4 ++++ .../numerical_submatcher_spec.rb | 23 +++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 spec/support/shared_examples/numerical_submatcher_spec.rb diff --git a/spec/shoulda/matchers/active_model/comparison_matcher_spec.rb b/spec/shoulda/matchers/active_model/comparison_matcher_spec.rb index 4194e1ad7..fff3c7af3 100644 --- a/spec/shoulda/matchers/active_model/comparison_matcher_spec.rb +++ b/spec/shoulda/matchers/active_model/comparison_matcher_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe Shoulda::Matchers::ActiveModel::ComparisonMatcher do + it_behaves_like 'a numerical submatcher' do + subject { Shoulda::Matchers::ActiveModel::ComparisonMatcher.new(0, :>) } + end + context 'is_greater_than' do it { instance_with_validations(greater_than: 2).should matcher.is_greater_than(2) } it { instance_without_validations.should_not matcher.is_greater_than(2) } diff --git a/spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb b/spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb index 893a9cfcb..81b1f3633 100644 --- a/spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb +++ b/spec/shoulda/matchers/active_model/odd_even_number_matcher_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe Shoulda::Matchers::ActiveModel::OddEvenNumberMatcher do + it_behaves_like 'a numerical submatcher' do + subject { Shoulda::Matchers::ActiveModel::OddEvenNumberMatcher.new(:attr) } + end + context 'given an attribute that only allows odd number values' do it 'matches' do validating_odd_number.should new_odd_matcher diff --git a/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb b/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb index 1dfd99db5..8fc26c206 100644 --- a/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb +++ b/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb @@ -1,6 +1,10 @@ require 'spec_helper' describe Shoulda::Matchers::ActiveModel::OnlyIntegerMatcher do + it_behaves_like 'a numerical submatcher' do + subject { Shoulda::Matchers::ActiveModel::OnlyIntegerMatcher.new(:attr) } + end + context 'given an attribute that only allows integer values' do it 'matches' do validating_only_integer.should new_matcher diff --git a/spec/support/shared_examples/numerical_submatcher_spec.rb b/spec/support/shared_examples/numerical_submatcher_spec.rb new file mode 100644 index 000000000..73470354e --- /dev/null +++ b/spec/support/shared_examples/numerical_submatcher_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +shared_examples 'a numerical submatcher' do + it 'implements the with_message method' do + subject.should respond_to(:with_message).with(1).arguments + end + + it 'implements the allowed_types method' do + subject.should respond_to(:allowed_types).with(0).arguments + end + + it 'implements the matches? method' do + subject.should respond_to(:matches?).with(1).arguments + end + + it 'implements the failure_message_for_should method' do + subject.should respond_to(:failure_message_for_should).with(0).arguments + end + + it 'implements the failure_message_for_should_not method' do + subject.should respond_to(:failure_message_for_should_not).with(0).arguments + end +end