@@ -39,54 +39,69 @@ def turn_of_laptop;end
39
39
40
40
it "should be able to define block callback" do
41
41
stub_const 'Foo' , Class . new
42
- proc_a = Proc . new { }
43
- proc_b = Proc . new { }
44
42
Foo . class_eval do
45
43
include React ::Callbacks
44
+ attr_accessor :a
45
+ attr_accessor :b
46
+
46
47
define_callback :before_dinner
47
48
48
- before_dinner ( &proc_a )
49
- before_dinner ( &proc_b )
49
+ before_dinner do
50
+ self . a = 10
51
+ end
52
+ before_dinner do
53
+ self . b = 20
54
+ end
50
55
end
51
56
52
- expect ( proc_a ) . to receive ( :call )
53
- expect ( proc_b ) . to receive ( :call )
54
- Foo . new . run_callback ( :before_dinner )
57
+ foo = Foo . new
58
+ foo . run_callback ( :before_dinner )
59
+ expect ( foo . a ) . to eq ( 10 )
60
+ expect ( foo . b ) . to eq ( 20 )
55
61
end
56
62
57
63
it "should be able to define multiple callback group" do
58
- proc_a = Proc . new { }
59
64
stub_const 'Foo' , Class . new
60
65
Foo . class_eval do
61
66
include React ::Callbacks
62
67
define_callback :before_dinner
63
68
define_callback :after_dinner
69
+ attr_accessor :a
64
70
65
- before_dinner ( &proc_a )
71
+ before_dinner do
72
+ self . a = 10
73
+ end
66
74
end
67
75
68
- expect ( proc_a ) . to receive ( :call )
69
- Foo . new . run_callback ( :before_dinner )
70
- Foo . new . run_callback ( :after_dinner )
76
+ foo = Foo . new
77
+ foo . run_callback ( :before_dinner )
78
+ foo . run_callback ( :after_dinner )
79
+
80
+ expect ( foo . a ) . to eq ( 10 )
71
81
end
72
82
73
83
it "should be able to receive args as callback" do
74
- a_proc = Proc . new { }
75
84
stub_const 'Foo' , Class . new
76
85
Foo . class_eval do
77
86
include React ::Callbacks
78
87
define_callback :before_dinner
79
88
define_callback :after_dinner
80
89
81
- before_dinner ( &a_proc )
90
+ attr_accessor :lorem
91
+
92
+ before_dinner do |a , b |
93
+ self . lorem = "#{ a } -#{ b } "
94
+ end
95
+
82
96
after_dinner :eat_ice_cream
83
97
def eat_ice_cream ( a , b , c ) ; end
84
98
end
85
99
86
- expect ( a_proc ) . to receive ( :call ) . with ( 1 , 2 )
87
100
expect_any_instance_of ( Foo ) . to receive ( :eat_ice_cream ) . with ( 4 , 5 , 6 )
88
101
89
- Foo . new . run_callback ( :before_dinner , 1 , 2 )
90
- Foo . new . run_callback ( :after_dinner , 4 , 5 , 6 )
102
+ foo = Foo . new
103
+ foo . run_callback ( :before_dinner , 1 , 2 )
104
+ foo . run_callback ( :after_dinner , 4 , 5 , 6 )
105
+ expect ( foo . lorem ) . to eq ( '1-2' )
91
106
end
92
107
end
0 commit comments