Module: Assert::Macros::Methods::ClassMethods

Defined in:
lib/assert/macros/methods.rb

Instance Method Summary collapse

Instance Method Details

#have_accessor(*methods) ⇒ Object Also known as: have_accessors



100
101
102
103
104
105
# File 'lib/assert/macros/methods.rb', line 100

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, have_cmeth, have_cmeths



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/assert/macros/methods.rb', line 42

def have_class_method(*methods)
  called_from = (methods.last.kind_of?(Array) ? methods.pop : caller).first
  name = "have class methods: #{methods.map{|m| "'#{m}'"}.join(', ')}"
  Assert::Macro.new(name) 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, have_imeth, have_imeths



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/assert/macros/methods.rb', line 12

def have_instance_method(*methods)
  called_from = (methods.last.kind_of?(Array) ? methods.pop : caller).first
  name = "have instance methods: #{methods.map{|m| "'#{m}'"}.join(', ')}"
  Assert::Macro.new(name) 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



72
73
74
75
# File 'lib/assert/macros/methods.rb', line 72

def have_reader(*methods)
  methods << caller if !methods.last.kind_of?(Array)
  have_instance_methods(*methods)
end

#have_writer(*methods) ⇒ Object Also known as: have_writers



84
85
86
87
88
89
# File 'lib/assert/macros/methods.rb', line 84

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

#not_have_accessor(*methods) ⇒ Object Also known as: not_have_accessors



108
109
110
111
112
113
# File 'lib/assert/macros/methods.rb', line 108

def not_have_accessor(*methods)
  called = methods.last.kind_of?(Array) ? methods.pop : caller
  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



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/assert/macros/methods.rb', line 57

def not_have_class_method(*methods)
  called_from = (methods.last.kind_of?(Array) ? methods.pop : caller).first
  name = "not have class methods: #{methods.map{|m| "'#{m}'"}.join(', ')}"
  Assert::Macro.new(name) do
    methods.each do |method|
      should "not respond to class method ##{method}", called_from do
        assert_not_respond_to method, subject.class, "#{subject.class.name} has class method ##{method}"
      end
    end
  end
end

#not_have_instance_method(*methods) ⇒ Object Also known as: not_have_instance_methods, not_have_imeth, not_have_imeths



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/assert/macros/methods.rb', line 27

def not_have_instance_method(*methods)
  called_from = (methods.last.kind_of?(Array) ? methods.pop : caller).first
  name = "not have instance methods: #{methods.map{|m| "'#{m}'"}.join(', ')}"
  Assert::Macro.new(name) do
    methods.each do |method|
      should "not respond to instance method ##{method}", called_from do
        assert_not_respond_to method, subject, "#{subject.class.name} has instance method ##{method}"
      end
    end
  end
end

#not_have_reader(*methods) ⇒ Object Also known as: not_have_readers



78
79
80
81
# File 'lib/assert/macros/methods.rb', line 78

def not_have_reader(*methods)
  methods << caller if !methods.last.kind_of?(Array)
  not_have_instance_methods(*methods)
end

#not_have_writer(*methods) ⇒ Object Also known as: not_have_writers



92
93
94
95
96
97
# File 'lib/assert/macros/methods.rb', line 92

def not_have_writer(*methods)
  called = methods.last.kind_of?(Array) ? methods.pop : caller
  writer_meths = methods.collect{|m| "#{m}="}
  writer_meths << called
  not_have_instance_methods(*writer_meths)
end