Module: RSpec::DescribeMethod::ClassExtensions

Defined in:
lib/rspec/describe_method/class_extensions.rb

Instance Method Summary collapse

Instance Method Details

#describe_method(method, *args, &block) ⇒ Object Also known as: when_calling



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec/describe_method/class_extensions.rb', line 5

def describe_method( method, *args, &block )
  throw ArgumentError.new 'Supplied method must be a String'      unless method.kind_of? String
  throw ArgumentError.new 'No block supplied to .describe_method' unless block.kind_of? Proc

  describe "when calling #{method}" do
    subject do
      old = super()

      case method[0]
      when '#' # Instance method ---
        if old.kind_of? Class then old.new else old       end
      when '.' # Class method ---
        if old.kind_of? Class then old     else old.class end
      else # Method type not recognized ---
        throw ArgumentError.new 'describe_method expects method name to begin with # or .'
      end.send method[1..-1], *args
    end

    instance_eval &block
  end
end