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