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



54
55
56
57
58
59
# File 'lib/assert/macros/methods.rb', line 54

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



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

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



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



38
39
40
41
42
43
# File 'lib/assert/macros/methods.rb', line 38

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



46
47
48
49
50
51
# File 'lib/assert/macros/methods.rb', line 46

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