hanging_methods 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/hanging_methods/version.rb +1 -1
- data/lib/hanging_methods.rb +1 -1
- data/spec/hanging_methods_spec.rb +24 -9
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/lib/hanging_methods.rb
CHANGED
@@ -30,7 +30,7 @@ module HangingMethods
|
|
30
30
|
def add_hanging_method_name_and_args_invocation(hanging_method_name, method_name_and_args)
|
31
31
|
hanging_method_invocations(hanging_method_name) << method_name_and_args
|
32
32
|
|
33
|
-
ret = if after_invocation = self.
|
33
|
+
ret = if after_invocation = self.method(hanging_method_name).owner.hanging_method_options(hanging_method_name)[:after_invocation]
|
34
34
|
send(after_invocation, method_name_and_args)
|
35
35
|
end
|
36
36
|
end
|
@@ -19,6 +19,9 @@ describe HangingMethods do
|
|
19
19
|
method_name_and_args.size
|
20
20
|
end
|
21
21
|
end
|
22
|
+
|
23
|
+
class SubTestObject < TestObject
|
24
|
+
end
|
22
25
|
|
23
26
|
describe "#hanging_method_invocations" do
|
24
27
|
let(:client) { TestObject.new }
|
@@ -39,17 +42,29 @@ describe HangingMethods do
|
|
39
42
|
end
|
40
43
|
|
41
44
|
context "with after_invocation" do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
context "with no subclassing" do
|
46
|
+
let!(:method_1_return) { client.add_more.a_method }
|
47
|
+
let!(:method_2_return) { client.add_more.another_method('arg1', 'arg2') }
|
48
|
+
|
49
|
+
it "should add invocation" do
|
50
|
+
subject
|
51
|
+
expect(client.add_more_invocations).to eq [[:a_method], [:another_method, 'arg1', 'arg2']]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return the value of the after_invocation method" do
|
55
|
+
expect(method_1_return).to eq 1
|
56
|
+
expect(method_2_return).to eq 3
|
57
|
+
end
|
48
58
|
end
|
49
59
|
|
50
|
-
|
51
|
-
|
52
|
-
|
60
|
+
context "with subclass object" do
|
61
|
+
let(:client) { SubTestObject.new }
|
62
|
+
let!(:method_1_return) { client.add_more.a_method }
|
63
|
+
|
64
|
+
it "should add invocation to the hanging method name owner class, not the sublcass" do
|
65
|
+
subject
|
66
|
+
expect(client.add_more_invocations).to eq [[:a_method]]
|
67
|
+
end
|
53
68
|
end
|
54
69
|
end
|
55
70
|
end
|