-
Notifications
You must be signed in to change notification settings - Fork 2
/
overlord_spec.rb
54 lines (41 loc) · 936 Bytes
/
overlord_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require './overlord'
class Foo
include Overlord
def bar(a, b)
[a, b].join(', ')
end
def bar(a)
a.to_s
end
def bar
'wow'
end
end
# define another class with the same method as this was previously
# causing a bug.
class Baz
include Overlord
def bar(a, b); end
end
describe Overlord do
it 'matches on methods with different arities' do
foo = Foo.new
expect(foo.bar()).to eq 'wow'
expect(foo.bar('hi')).to eq 'hi'
expect(foo.bar(1, 2)).to eq '1, 2'
end
it 'raises undefined method when method is not defined' do
foo = Foo.new
expect { foo.bar(1, 2, 3) }.to raise_error(NoMethodError, 'undefined method `bar` with arity 3')
end
it 'works on keyword args' do
class Thing
include Overlord
def bar(baz:, wow:)
[baz, wow].join(', ')
end
end
foo = Thing.new
expect(foo.bar(baz: 'bang', wow: 'yes')).to eq 'bang, yes'
end
end