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
140 141 142 |
# File 'lib/assert/macros/methods.rb', line 140 def _methods_macro_class_methods @_methods_macro_class_methods ||= [] end |
#_methods_macro_instance_methods ⇒ Object
132 133 134 |
# File 'lib/assert/macros/methods.rb', line 132 def _methods_macro_instance_methods @_methods_macro_instance_methods ||= [] end |
#_methods_macro_not_class_methods ⇒ Object
144 145 146 |
# File 'lib/assert/macros/methods.rb', line 144 def _methods_macro_not_class_methods @_methods_macro_not_class_methods ||= [] end |
#_methods_macro_not_instance_methods ⇒ Object
136 137 138 |
# File 'lib/assert/macros/methods.rb', line 136 def _methods_macro_not_instance_methods @_methods_macro_not_instance_methods ||= [] end |
#_methods_macro_test(called_from) ⇒ Object
private
100 101 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 |
# File 'lib/assert/macros/methods.rb', line 100 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
82 83 84 85 86 87 |
# File 'lib/assert/macros/methods.rb', line 82 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
32 33 34 35 36 37 38 |
# File 'lib/assert/macros/methods.rb', line 32 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
10 11 12 13 14 15 16 |
# File 'lib/assert/macros/methods.rb', line 10 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
54 55 56 57 |
# File 'lib/assert/macros/methods.rb', line 54 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
66 67 68 69 70 71 |
# File 'lib/assert/macros/methods.rb', line 66 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
90 91 92 93 94 95 |
# File 'lib/assert/macros/methods.rb', line 90 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
43 44 45 46 47 48 49 |
# File 'lib/assert/macros/methods.rb', line 43 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
21 22 23 24 25 26 27 |
# File 'lib/assert/macros/methods.rb', line 21 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
60 61 62 63 |
# File 'lib/assert/macros/methods.rb', line 60 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
74 75 76 77 78 79 |
# File 'lib/assert/macros/methods.rb', line 74 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 |