Module: HigherExpectations::InstanceMethods
- Included in:
- Fixnum
- Defined in:
- lib/instance_methods.rb
Defined Under Namespace
Classes: HigherExpectationException
Instance Method Summary collapse
-
#must_be(*values) ⇒ Object
(also: #and_must_be)
argument must be the given value.
-
#must_be_a(*klasses) ⇒ Object
(also: #must_be_an)
value(s) must be a specific class or in given set of classes.
-
#must_be_in_range(range) ⇒ Object
(also: #and_must_be_in_range)
value(s) must be in a specific numeric range.
-
#must_be_nil ⇒ Object
(also: #and_must_be_nil)
value must be nil, or must not be nil respectively.
- #must_match(pattern) ⇒ Object (also: #and_must_match)
-
#must_not_be(*values) ⇒ Object
(also: #and_must_not_be)
argument must NOT be the given value.
-
#must_not_be_a(*klasses) ⇒ Object
(also: #must_not_be_an, #and_must_not_be_a, #and_must_not_be_an)
value(s) must not be in a specific class or set of klasses.
-
#must_not_be_in_range(range) ⇒ Object
(also: #and_must_not_be_in_range)
value(s) must be in a specific numeric range.
- #must_not_be_nil ⇒ Object (also: #and_must_not_be_nil)
- #must_not_match(pattern) ⇒ Object (also: #and_must_not_match)
- #must_not_respond_to(*meths) ⇒ Object (also: #and_must_not_respond_to)
- #must_respond_to(*meths) ⇒ Object (also: #and_must_respond_to)
-
#raise_ae(message) ⇒ Object
raise ArgumentError exception.
Instance Method Details
#must_be(*values) ⇒ Object Also known as: and_must_be
argument must be the given value
28 29 30 31 |
# File 'lib/instance_methods.rb', line 28 def must_be(*values) values.each {|value| raise_ae(" must equal #{value}") unless self == value; } self # allow for method concatonation "foo.must_be(String).and_must_not_be_nil end |
#must_be_a(*klasses) ⇒ Object Also known as: must_be_an
value(s) must be a specific class or in given set of classes
42 43 44 45 46 47 |
# File 'lib/instance_methods.rb', line 42 def must_be_a(*klasses) klasses.each do |klass| raise_ae(" should be #{klass.to_s}") unless self.kind_of?(klass) end self end |
#must_be_in_range(range) ⇒ Object Also known as: and_must_be_in_range
value(s) must be in a specific numeric range
64 65 66 67 68 |
# File 'lib/instance_methods.rb', line 64 def must_be_in_range(range) raise HigherExpectationException.new("Must pass in two values ('foo.must_be_in_range(0,5)')") unless range.kind_of?(Range) || range.kind_of?(Array) raise_ae("'s value to be in the range of #{range.first} to #{range.last} (it was #{self.to_s})") unless self >= range.first && self <= range.last self end |
#must_be_nil ⇒ Object Also known as: and_must_be_nil
value must be nil, or must not be nil respectively
17 |
# File 'lib/instance_methods.rb', line 17 def must_be_nil; raise_ae(" to be nil") unless self == nil; end |
#must_match(pattern) ⇒ Object Also known as: and_must_match
79 80 81 82 |
# File 'lib/instance_methods.rb', line 79 def must_match(pattern) raise_ae(" to match pattern #{pattern.to_s}") unless self =~ pattern self end |
#must_not_be(*values) ⇒ Object Also known as: and_must_not_be
argument must NOT be the given value
35 36 37 38 |
# File 'lib/instance_methods.rb', line 35 def must_not_be(*values) values.each {|value| raise_ae(" must NOT equal #{value}") unless self != value; } self end |
#must_not_be_a(*klasses) ⇒ Object Also known as: must_not_be_an, and_must_not_be_a, and_must_not_be_an
value(s) must not be in a specific class or set of klasses
53 54 55 56 57 58 |
# File 'lib/instance_methods.rb', line 53 def must_not_be_a(*klasses) klasses.each do |klass| raise_ae(" should NOT be #{klass.to_s}") if self.kind_of?(klass) end self end |
#must_not_be_in_range(range) ⇒ Object Also known as: and_must_not_be_in_range
value(s) must be in a specific numeric range
72 73 74 75 76 |
# File 'lib/instance_methods.rb', line 72 def must_not_be_in_range(range) raise HigherExpectationException.new("Must pass in two values ('foo.must_be_in_range(0,5)')") unless range.kind_of?(Range) || range.kind_of?(Array) raise_ae("'s value NOT to be in the range of #{range.first} to #{range.last} (it was #{self.to_s})") if self >= range.first && self <= range.last self end |
#must_not_be_nil ⇒ Object Also known as: and_must_not_be_nil
19 |
# File 'lib/instance_methods.rb', line 19 def must_not_be_nil; raise_ae(" to be nil") unless self != nil; end |
#must_not_match(pattern) ⇒ Object Also known as: and_must_not_match
85 86 87 88 |
# File 'lib/instance_methods.rb', line 85 def must_not_match(pattern) raise_ae(" to match pattern #{pattern.to_s}") if self =~ pattern self end |
#must_not_respond_to(*meths) ⇒ Object Also known as: and_must_not_respond_to
99 100 101 102 103 104 |
# File 'lib/instance_methods.rb', line 99 def must_not_respond_to(*meths) meths.each do |meth| raise_ae(" to respond to #{meth}") if self.respond_to?(meth.to_s) end self end |
#must_respond_to(*meths) ⇒ Object Also known as: and_must_respond_to
91 92 93 94 95 96 |
# File 'lib/instance_methods.rb', line 91 def must_respond_to(*meths) meths.each do |meth| raise_ae(" to respond to #{meth}") unless self.respond_to?(meth.to_s) end self end |
#raise_ae(message) ⇒ Object
raise ArgumentError exception
23 24 25 |
# File 'lib/instance_methods.rb', line 23 def raise_ae() raise ArgumentError.new("Method expects this argument" + .to_s) end |