Module: MiniTestMustNot
- Defined in:
- lib/minitest-must_not/core.rb,
lib/minitest-must_not/version.rb
Overview
When this module is included, it provides a method_missing implementation that catches all methods that look like ‘must_not_’ and delegates them to the equivalent ‘wont_’ method (if it exists).
Constant Summary
collapse
- METHOD_NAME_REGEX =
/^must_not_(.*)$/
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Catches all method calls that look like ‘must_not_’ and delegates them to the equivalent ‘wont_’
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/minitest-must_not/core.rb', line 11
def method_missing name, *args, &block
if name.to_s =~ METHOD_NAME_REGEX
wont_method_name = "wont_#{$1}"
begin
self.class.send :alias_method, name, wont_method_name rescue NameError
return super
end
send wont_method_name, *args, &block
else
super
end
end
|
Instance Method Details
#respond_to?(name) ⇒ Boolean
Catches all method calls that look like ‘must_not_’ and returns whether this object responds to ‘wont_’
33
34
35
36
37
38
39
|
# File 'lib/minitest-must_not/core.rb', line 33
def respond_to? name
if name.to_s =~ METHOD_NAME_REGEX
respond_to? "wont_#{$1}"
else
super
end
end
|