Module: Assert::Macros::Methods::ClassMethods
- Defined in:
- lib/assert/macros/methods.rb
Instance Method Summary collapse
- #_methods_macro_class_methods ⇒ Object
- #_methods_macro_instance_methods ⇒ Object
- #_methods_macro_not_class_methods ⇒ Object
- #_methods_macro_not_instance_methods ⇒ Object
-
#_methods_macro_test(called_from) ⇒ Object
private.
- #have_accessor(*methods) ⇒ Object (also: #have_accessors)
- #have_class_method(*methods) ⇒ Object (also: #have_class_methods, #have_cmeth, #have_cmeths)
- #have_instance_method(*methods) ⇒ Object (also: #have_instance_methods, #have_imeth, #have_imeths)
- #have_reader(*methods) ⇒ Object (also: #have_readers)
- #have_writer(*methods) ⇒ Object (also: #have_writers)
- #not_have_accessor(*methods) ⇒ Object (also: #not_have_accessors)
- #not_have_class_method(*methods) ⇒ Object (also: #not_have_class_methods, #not_have_cmeth, #not_have_cmeths)
- #not_have_instance_method(*methods) ⇒ Object (also: #not_have_instance_methods, #not_have_imeth, #not_have_imeths)
- #not_have_reader(*methods) ⇒ Object (also: #not_have_readers)
- #not_have_writer(*methods) ⇒ Object (also: #not_have_writers)
Instance Method Details
#_methods_macro_class_methods ⇒ Object
168 169 170 |
# File 'lib/assert/macros/methods.rb', line 168 def _methods_macro_class_methods @_methods_macro_class_methods ||= [] end |
#_methods_macro_instance_methods ⇒ Object
160 161 162 |
# File 'lib/assert/macros/methods.rb', line 160 def _methods_macro_instance_methods @_methods_macro_instance_methods ||= [] end |
#_methods_macro_not_class_methods ⇒ Object
172 173 174 |
# File 'lib/assert/macros/methods.rb', line 172 def _methods_macro_not_class_methods @_methods_macro_not_class_methods ||= [] end |
#_methods_macro_not_instance_methods ⇒ Object
164 165 166 |
# File 'lib/assert/macros/methods.rb', line 164 def _methods_macro_not_instance_methods @_methods_macro_not_instance_methods ||= [] end |
#_methods_macro_test(called_from) ⇒ Object
private
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/assert/macros/methods.rb', line 112 def _methods_macro_test(called_from) @_methods_macro_test ||= test "should respond to methods", called_from do self .class ._methods_macro_instance_methods .each do |(method, called_from)| msg = "#{subject.class.name} does not have "\ "instance method ##{method}" with_backtrace([called_from]) do assert_that(subject).responds_to(method, msg) end end self .class ._methods_macro_class_methods .each do |(method, called_from)| msg = "#{subject.class.name} does not have class method ##{method}" with_backtrace([called_from]) do assert_that(subject.class).responds_to(method, msg) end end self .class ._methods_macro_not_instance_methods .each do |(method, called_from)| msg = "#{subject.class.name} has instance method ##{method}" with_backtrace([called_from]) do assert_that(subject).does_not_respond_to(method, msg) end end self .class ._methods_macro_not_class_methods .each do |(method, called_from)| msg = "#{subject.class.name} has class method ##{method}" with_backtrace([called_from]) do assert_that(subject.class).does_not_respond_to(method, msg) end end end end |
#have_accessor(*methods) ⇒ Object Also known as: have_accessors
94 95 96 97 98 99 |
# File 'lib/assert/macros/methods.rb', line 94 def have_accessor(*methods) called = methods.last.is_a?(Array) ? methods.pop : caller_locations accessor_meths = methods.map{ |m| [m, "#{m}="] }.flatten accessor_meths << called have_instance_methods(*accessor_meths) end |
#have_class_method(*methods) ⇒ Object Also known as: have_class_methods, have_cmeth, have_cmeths
40 41 42 43 44 45 46 47 |
# File 'lib/assert/macros/methods.rb', line 40 def have_class_method(*methods) called_from = (methods.last.is_a?(Array) ? methods.pop : caller_locations).first Assert::Macro.new do methods.each{ |m| _methods_macro_class_methods << [m, called_from] } _methods_macro_test called_from end end |
#have_instance_method(*methods) ⇒ Object Also known as: have_instance_methods, have_imeth, have_imeths
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/assert/macros/methods.rb', line 12 def have_instance_method(*methods) called_from = (methods.last.is_a?(Array) ? methods.pop : caller_locations).first Assert::Macro.new do methods.each do |m| _methods_macro_instance_methods << [m, called_from] end _methods_macro_test called_from end end |
#have_reader(*methods) ⇒ Object Also known as: have_readers
66 67 68 69 |
# File 'lib/assert/macros/methods.rb', line 66 def have_reader(*methods) methods << caller_locations unless methods.last.is_a?(Array) have_instance_methods(*methods) end |
#have_writer(*methods) ⇒ Object Also known as: have_writers
78 79 80 81 82 83 |
# File 'lib/assert/macros/methods.rb', line 78 def have_writer(*methods) called = methods.last.is_a?(Array) ? methods.pop : caller_locations writer_meths = methods.map{ |m| "#{m}=" } writer_meths << called have_instance_methods(*writer_meths) end |
#not_have_accessor(*methods) ⇒ Object Also known as: not_have_accessors
102 103 104 105 106 107 |
# File 'lib/assert/macros/methods.rb', line 102 def not_have_accessor(*methods) called = methods.last.is_a?(Array) ? methods.pop : caller_locations accessor_meths = methods.map{ |m| [m, "#{m}="] }.flatten accessor_meths << called not_have_instance_methods(*accessor_meths) end |
#not_have_class_method(*methods) ⇒ Object Also known as: not_have_class_methods, not_have_cmeth, not_have_cmeths
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/assert/macros/methods.rb', line 52 def not_have_class_method(*methods) called_from = (methods.last.is_a?(Array) ? methods.pop : caller_locations).first Assert::Macro.new do methods.each do |m| _methods_macro_not_class_methods << [m, called_from] end _methods_macro_test called_from end end |
#not_have_instance_method(*methods) ⇒ Object Also known as: not_have_instance_methods, not_have_imeth, not_have_imeths
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/assert/macros/methods.rb', line 26 def not_have_instance_method(*methods) called_from = (methods.last.is_a?(Array) ? methods.pop : caller_locations).first Assert::Macro.new do methods.each do |m| _methods_macro_not_instance_methods << [m, called_from] end _methods_macro_test called_from end end |
#not_have_reader(*methods) ⇒ Object Also known as: not_have_readers
72 73 74 75 |
# File 'lib/assert/macros/methods.rb', line 72 def not_have_reader(*methods) methods << caller_locations unless methods.last.is_a?(Array) not_have_instance_methods(*methods) end |
#not_have_writer(*methods) ⇒ Object Also known as: not_have_writers
86 87 88 89 90 91 |
# File 'lib/assert/macros/methods.rb', line 86 def not_have_writer(*methods) called = methods.last.is_a?(Array) ? methods.pop : caller_locations writer_meths = methods.map{ |m| "#{m}=" } writer_meths << called not_have_instance_methods(*writer_meths) end |