Module: Assert::Macros::Methods::ClassMethods
- Defined in:
- lib/assert/macros/methods.rb
Instance Method Summary collapse
- #have_accessor(*methods) ⇒ Object (also: #have_accessors)
- #have_class_method(*methods) ⇒ Object (also: #have_class_methods)
- #have_instance_method(*methods) ⇒ Object (also: #have_instance_methods)
- #have_reader(*methods) ⇒ Object (also: #have_readers)
- #have_writer(*methods) ⇒ Object (also: #have_writers)
Instance Method Details
#have_accessor(*methods) ⇒ Object Also known as: have_accessors
52 53 54 55 56 57 |
# File 'lib/assert/macros/methods.rb', line 52 def have_accessor(*methods) called = methods.last.kind_of?(Array) ? methods.pop : caller 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
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/assert/macros/methods.rb', line 24 def have_class_method(*methods) called_from = (methods.last.kind_of?(Array) ? methods.pop : caller).first Assert::Macro.new do methods.each do |method| should "respond to class method ##{method}", called_from do assert_respond_to method, subject.class, "#{subject.class.name} does not have class method ##{method}" end end end end |
#have_instance_method(*methods) ⇒ Object Also known as: have_instance_methods
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.kind_of?(Array) ? methods.pop : caller).first Assert::Macro.new do methods.each do |method| should "respond to instance method ##{method}", called_from do assert_respond_to method, subject, "#{subject.class.name} does not have instance method ##{method}" end end end end |
#have_reader(*methods) ⇒ Object Also known as: have_readers
36 37 38 39 40 41 |
# File 'lib/assert/macros/methods.rb', line 36 def have_reader(*methods) unless methods.last.kind_of?(Array) methods << caller end have_instance_methods(*methods) end |
#have_writer(*methods) ⇒ Object Also known as: have_writers
44 45 46 47 48 49 |
# File 'lib/assert/macros/methods.rb', line 44 def have_writer(*methods) called = methods.last.kind_of?(Array) ? methods.pop : caller writer_meths = methods.collect{|m| "#{m}="} writer_meths << called have_instance_methods(*writer_meths) end |