Module: Remarkable::Default::Helpers

Included in:
ActiveRecord::Helpers, Controller::Helpers
Defined in:
lib/remarkable/helpers.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#assert_contains(collection, x) ⇒ Object

Asserts that the given collection contains item x. If x is a regular expression, ensure that at least one element from the collection matches x. extra_msg is appended to the error message if the assertion fails.

assert_contains(['a', '1'], /\d/) => passes
assert_contains(['a', '1'], 'a') => passes
assert_contains(['a', '1'], /not there/) => fails


10
11
12
13
14
15
16
17
18
19
# File 'lib/remarkable/helpers.rb', line 10

def assert_contains(collection, x) # :nodoc:
  collection = [collection] unless collection.is_a?(Array)

  case x
  when Regexp
    collection.detect { |e| e =~ x }
  else         
    collection.include?(x)
  end
end

#assert_does_not_contain(collection, x) ⇒ Object

Asserts that the given collection does not contain item x. If x is a regular expression, ensure that none of the elements from the collection match x.



23
24
25
# File 'lib/remarkable/helpers.rb', line 23

def assert_does_not_contain(collection, x) # :nodoc:
  !assert_contains(collection, x)
end