-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinformal_tests.rb
More file actions
34 lines (27 loc) · 837 Bytes
/
informal_tests.rb
File metadata and controls
34 lines (27 loc) · 837 Bytes
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
# These examples written for samples of code in the documentation
$: << File.dirname(__FILE__)+"/lib"
require 'wrapr'
require 'logger'
log = Logger.new(STDOUT)
w = Wrapr::Wrapr.new(Exception)
# #before can mutate the instance and args as well
w.before(:initialize) do |this,*args|
args[0].upcase!
args
end
puts Exception.new("foo").to_s # FOO
w.around(:to_s) do |this,method,*args|
puts "Before to_s"
result = method.call()
result+=" "
end
puts Exception.new("foo").to_s # FOO, "Before to_s OOF "
w.after(:to_s) do |this,result|
result.downcase
end
puts Exception.new("foo").to_s # FOO, "Before to_s foo"
Wrapr::Wrapr.new(Exception).before(:initialize) do |this,*args|
log.debug("New exception is being created "+args.inspect)
args
end
5/0