Skip to content

Commit

Permalink
Create a shared example for Numercial Submatchers.
Browse files Browse the repository at this point in the history
* Verify that all submatchers respond to the necessary interface
* See: #357 for a reason why this is necessary
  • Loading branch information
drapergeek committed Sep 16, 2013
1 parent 90364bf commit 7a00f1d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/shoulda/matchers/active_model/comparison_matcher_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/support/shared_examples/numerical_submatcher_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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
end

0 comments on commit 7a00f1d

Please sign in to comment.