Commit 2bdea8651fa3bd82418986ada84828c22d451405
1 parent
9e7d77ce
Exists in
master
and in
4 other branches
Add is_within method for shoulda's EnsureLengthOf matcher
Showing
1 changed file
with
14 additions
and
0 deletions
Show diff stats
spec/support/matchers.rb
@@ -67,3 +67,17 @@ module UrlAccess | @@ -67,3 +67,17 @@ module UrlAccess | ||
67 | login_with(user) if user | 67 | login_with(user) if user |
68 | end | 68 | end |
69 | end | 69 | end |
70 | + | ||
71 | +# Extend shoulda-matchers | ||
72 | +module Shoulda::Matchers::ActiveModel | ||
73 | + class EnsureLengthOfMatcher | ||
74 | + # Shortcut for is_at_least and is_at_most | ||
75 | + def is_within(range) | ||
76 | + if range.exclude_end? | ||
77 | + is_at_least(range.first) && is_at_most(range.last - 1) | ||
78 | + else | ||
79 | + is_at_least(range.first) && is_at_most(range.last) | ||
80 | + end | ||
81 | + end | ||
82 | + end | ||
83 | +end |