From 0d5cf111f3070994c0e80ef764d1bd4b9e4936b1 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 21 Jul 2015 22:09:58 -0400 Subject: Move custom matchers to their own files under spec/support/matchers --- spec/support/matchers/include_module.rb | 13 +++++++++++++ spec/support/matchers/is_within.rb | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 spec/support/matchers/include_module.rb create mode 100644 spec/support/matchers/is_within.rb (limited to 'spec/support/matchers') diff --git a/spec/support/matchers/include_module.rb b/spec/support/matchers/include_module.rb new file mode 100644 index 00000000000..0a78af1e90e --- /dev/null +++ b/spec/support/matchers/include_module.rb @@ -0,0 +1,13 @@ +RSpec::Matchers.define :include_module do |expected| + match do + described_class.included_modules.include?(expected) + end + + description do + "includes the #{expected} module" + end + + failure_message do + "expected #{described_class} to include the #{expected} module" + end +end diff --git a/spec/support/matchers/is_within.rb b/spec/support/matchers/is_within.rb new file mode 100644 index 00000000000..0c35fc7e899 --- /dev/null +++ b/spec/support/matchers/is_within.rb @@ -0,0 +1,9 @@ +# Extend shoulda-matchers +module Shoulda::Matchers::ActiveModel + class ValidateLengthOfMatcher + # Shortcut for is_at_least and is_at_most + def is_within(range) + is_at_least(range.min) && is_at_most(range.max) + end + end +end -- cgit v1.2.3