Module: Inspector::Constraints

Includes:
Constraint
Included in:
Metadata
Defined in:
lib/inspector/constraints.rb,
lib/inspector/constraints/eq.rb,
lib/inspector/constraints/have.rb,
lib/inspector/constraints/true.rb,
lib/inspector/constraints/email.rb,
lib/inspector/constraints/empty.rb,
lib/inspector/constraints/false.rb,
lib/inspector/constraints/valid.rb,
lib/inspector/constraints/predicate.rb

Defined Under Namespace

Modules: Have Classes: Email, Empty, Eq, False, Predicate, True, Valid

Instance Method Summary collapse

Methods included from Constraint

#negate!, #positive?, #validator

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

be_empty => value.empty? be_nil => value.nil?



53
54
55
56
57
58
59
# File 'lib/inspector/constraints.rb', line 53

def method_missing(method, *args, &block)
  prefix, *predicate = method.to_s.split("_")
  predicate.shift if ["a", "an"].include?(predicate.first)
  return Inspector::Constraints::Predicate.new(predicate.join("_"), *args, &block) if prefix == "be"
  # return Inspector::Constraints::Has.new(method, *args, &block) if method.to_s =~ /^have_/
  super
end

Instance Method Details

#be_emailObject Also known as: be_an_email



38
39
40
# File 'lib/inspector/constraints.rb', line 38

def be_email
  Email.new
end

#be_emptyObject



21
22
23
# File 'lib/inspector/constraints.rb', line 21

def be_empty
  Empty.new
end

#be_falseObject



13
14
15
# File 'lib/inspector/constraints.rb', line 13

def be_false
  False.new
end

#be_trueObject



17
18
19
# File 'lib/inspector/constraints.rb', line 17

def be_true
  True.new
end

#eq(expected) ⇒ Object



43
44
45
# File 'lib/inspector/constraints.rb', line 43

def eq(expected)
  Eq.new(expected)
end

#have(n) ⇒ Object Also known as: have_exactly



33
34
35
# File 'lib/inspector/constraints.rb', line 33

def have(n)
  Have::Exactly.new(n)
end

#have_at_least(n) ⇒ Object



25
26
27
# File 'lib/inspector/constraints.rb', line 25

def have_at_least(n)
  Have::AtLeast.new(n)
end

#have_at_most(n) ⇒ Object



29
30
31
# File 'lib/inspector/constraints.rb', line 29

def have_at_most(n)
  Have::AtMost.new(n)
end

#validate(options = {}) ⇒ Object



47
48
49
# File 'lib/inspector/constraints.rb', line 47

def validate(options = {})
  Valid.new(options[:as])
end