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
142 143 144 |
# File 'lib/assert/macros/methods.rb', line 142 def _methods_macro_class_methods @_methods_macro_class_methods ||= [] end |
#_methods_macro_instance_methods ⇒ Object
134 135 136 |
# File 'lib/assert/macros/methods.rb', line 134 def _methods_macro_instance_methods @_methods_macro_instance_methods ||= [] end |
#_methods_macro_not_class_methods ⇒ Object
146 147 148 |
# File 'lib/assert/macros/methods.rb', line 146 def _methods_macro_not_class_methods @_methods_macro_not_class_methods ||= [] end |
#_methods_macro_not_instance_methods ⇒ Object
138 139 140 |
# File 'lib/assert/macros/methods.rb', line 138 def _methods_macro_not_instance_methods @_methods_macro_not_instance_methods ||= [] end |
#_methods_macro_test(called_from) ⇒ Object
private
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/assert/macros/methods.rb', line 102 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
84 85 86 87 88 89 |
# File 'lib/assert/macros/methods.rb', line 84 def have_accessor(*methods) called = methods.last.kind_of?(Array) ? methods.pop : caller_locations accessor_meths = methods.collect{|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
34 35 36 37 38 39 40 |
# File 'lib/assert/macros/methods.rb', line 34 def have_class_method(*methods) called_from = (methods.last.kind_of?(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 |
# File 'lib/assert/macros/methods.rb', line 12 def have_instance_method(*methods) called_from = (methods.last.kind_of?(Array) ? methods.pop : caller_locations).first Assert::Macro.new do methods.each{ |m| _methods_macro_instance_methods << [m, called_from] } _methods_macro_test called_from end end |
#have_reader(*methods) ⇒ Object Also known as: have_readers
56 57 58 59 |
# File 'lib/assert/macros/methods.rb', line 56 def have_reader(*methods) methods << caller_locations if !methods.last.kind_of?(Array) have_instance_methods(*methods) end |
#have_writer(*methods) ⇒ Object Also known as: have_writers
68 69 70 71 72 73 |
# File 'lib/assert/macros/methods.rb', line 68 def have_writer(*methods) called = methods.last.kind_of?(Array) ? methods.pop : caller_locations writer_meths = methods.collect{|m| "#{m}="} writer_meths << called have_instance_methods(*writer_meths) end |
#not_have_accessor(*methods) ⇒ Object Also known as: not_have_accessors
92 93 94 95 96 97 |
# File 'lib/assert/macros/methods.rb', line 92 def not_have_accessor(*methods) called = methods.last.kind_of?(Array) ? methods.pop : caller_locations accessor_meths = methods.collect{|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
45 46 47 48 49 50 51 |
# File 'lib/assert/macros/methods.rb', line 45 def not_have_class_method(*methods) called_from = (methods.last.kind_of?(Array) ? methods.pop : caller_locations).first Assert::Macro.new do methods.each{ |m| _methods_macro_not_class_methods << [m, called_from] } _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
23 24 25 26 27 28 29 |
# File 'lib/assert/macros/methods.rb', line 23 def not_have_instance_method(*methods) called_from = (methods.last.kind_of?(Array) ? methods.pop : caller_locations).first Assert::Macro.new do methods.each{ |m| _methods_macro_not_instance_methods << [m, called_from] } _methods_macro_test called_from end end |
#not_have_reader(*methods) ⇒ Object Also known as: not_have_readers
62 63 64 65 |
# File 'lib/assert/macros/methods.rb', line 62 def not_have_reader(*methods) methods << caller_locations if !methods.last.kind_of?(Array) not_have_instance_methods(*methods) end |
#not_have_writer(*methods) ⇒ Object Also known as: not_have_writers
76 77 78 79 80 81 |
# File 'lib/assert/macros/methods.rb', line 76 def not_have_writer(*methods) called = methods.last.kind_of?(Array) ? methods.pop : caller_locations writer_meths = methods.collect{|m| "#{m}="} writer_meths << called not_have_instance_methods(*writer_meths) end |