evalhook 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,99 @@
1
+ require "rubygems"
2
+ require "evalhook"
3
+
4
+ describe EvalHook::MultiHookHandler, "multiple hook handler" do
5
+
6
+
7
+ it "should instance empty MultiHookHandler" do
8
+ EvalHook::MultiHookHandler.new.should be_an_instance_of(EvalHook::MultiHookHandler)
9
+ end
10
+
11
+ exprlist = ["1+1", "[1,2,3].map{|x| x*2}"]
12
+
13
+ exprlist.each do |expr|
14
+ it "should eval expresion '#{expr}' same as eval" do
15
+ mhh = EvalHook::MultiHookHandler.new
16
+ expected = eval(expr)
17
+ mhh.evalhook(expr).should be == expected
18
+
19
+ end
20
+ end
21
+
22
+ class X
23
+ def foo
24
+
25
+ end
26
+ end
27
+
28
+ it "should allow method calls" do
29
+ hook_handler = EvalHook::HookHandler.new
30
+ hook_handler.evalhook("X.new.foo").should be X.new.foo
31
+ end
32
+
33
+ it "should capture method calls" do
34
+ hook_handler = EvalHook::MultiHookHandler.new
35
+
36
+ hook_handler.should_receive(:handle_method).with(X.class,X,:new)
37
+ hook_handler.should_receive(:handle_method).with(X,anything(),:foo)
38
+
39
+ hook_handler.evalhook("X.new.foo")
40
+ end
41
+
42
+ it "should capture constant assignment" do
43
+ hook_handler = EvalHook::MultiHookHandler.new
44
+
45
+ hook_handler.should_receive(:handle_cdecl).with(Object,:TEST_CONSTANT,4)
46
+ hook_handler.evalhook("TEST_CONSTANT = 4")
47
+
48
+ end
49
+
50
+ it "should capture global assignment" do
51
+ hook_handler = EvalHook::MultiHookHandler.new
52
+
53
+ hook_handler.should_receive(:handle_gasgn).with(:$test_global_variable,4)
54
+ hook_handler.evalhook("$test_global_variable = 4")
55
+
56
+ end
57
+
58
+ it "should add nested hook handlers" do
59
+ hook_handler = EvalHook::MultiHookHandler.new
60
+
61
+ hook_handler.add EvalHook::HookHandler.new
62
+ hook_handler.add EvalHook::HookHandler.new
63
+ end
64
+
65
+ it "should recall handle_method to nested hook handler" do
66
+ hook_handler = EvalHook::MultiHookHandler.new
67
+
68
+ nested_handler = EvalHook::HookHandler.new
69
+ hook_handler.add nested_handler
70
+
71
+ nested_handler.should_receive(:handle_method).with(X.class,X,:new)
72
+ nested_handler.should_receive(:handle_method).with(X,anything(),:foo)
73
+
74
+ hook_handler.evalhook("X.new.foo")
75
+ end
76
+
77
+ it "should recall handle_cdecl to nested hook handler" do
78
+ hook_handler = EvalHook::MultiHookHandler.new
79
+
80
+ nested_handler = EvalHook::HookHandler.new
81
+ hook_handler.add nested_handler
82
+
83
+ nested_handler.should_receive(:handle_cdecl).with(Object,:TEST_CONSTANT,4)
84
+
85
+ hook_handler.evalhook("TEST_CONSTANT = 4")
86
+ end
87
+
88
+ it "should recall handle_gasgn to nested hook handler" do
89
+ hook_handler = EvalHook::MultiHookHandler.new
90
+
91
+ nested_handler = EvalHook::HookHandler.new
92
+ hook_handler.add nested_handler
93
+
94
+ nested_handler.should_receive(:handle_gasgn).with(:$test_global_variable,4)
95
+
96
+ hook_handler.evalhook("$test_global_variable = 4")
97
+ end
98
+
99
+ end
@@ -0,0 +1,47 @@
1
+ require "rubygems"
2
+ require "evalhook"
3
+
4
+ describe EvalHook::HookHandler, "hook handler ruby basics" do
5
+
6
+ class X
7
+ def foo
8
+
9
+ end
10
+ end
11
+
12
+ def test_hook_handler
13
+ EvalHook::HookHandler.new
14
+ end
15
+
16
+ it "should call singleton methods" do
17
+
18
+ test_hook_handler.evalhook("
19
+ x = X.new
20
+ def x.bar
21
+ end
22
+ x.bar
23
+ ")
24
+ end
25
+
26
+ it "should call 'global' functions" do
27
+
28
+ test_hook_handler.evalhook("
29
+ def bar
30
+ end
31
+ bar
32
+ ", binding)
33
+ end
34
+
35
+ it "should allow creation of locals" do
36
+ # FAILED due an incompatibility of default ruby with rspec
37
+ # test_hook_handler.evalhook("local_test = 1")
38
+ # local_test.should be == 1
39
+ end
40
+
41
+ it "should allow assignment of locals" do
42
+ local_test = nil
43
+ test_hook_handler.evalhook("local_test = 1", binding)
44
+ local_test.should be == 1
45
+ end
46
+
47
+ end
@@ -0,0 +1,103 @@
1
+ require "rubygems"
2
+ require "evalhook"
3
+
4
+ describe EvalHook::HookHandler, "hook handler visitor" do
5
+
6
+ class X
7
+ def foo
8
+
9
+ end
10
+ end
11
+
12
+ def self.visitor_it(code, name)
13
+ it name do
14
+ x = X.new
15
+ hh = EvalHook::HookHandler.new
16
+
17
+ hh.should_receive(:handle_method).with(X,x,:foo)
18
+
19
+ hh.evalhook(code)
20
+
21
+ entry_point(x)
22
+ end
23
+ end
24
+
25
+ it "should capture inside method" do
26
+ x = X.new
27
+ hh = EvalHook::HookHandler.new
28
+
29
+ hh.should_receive(:handle_method).with(X,x,:foo)
30
+
31
+ hh.evalhook("
32
+ def bar(x)
33
+ x.foo
34
+ end
35
+ ", binding)
36
+ bar(x)
37
+
38
+ end
39
+
40
+ it "should capture inside class" do
41
+ x = X.new
42
+ hh = EvalHook::HookHandler.new
43
+
44
+ hh.should_receive(:handle_method).with(X,x,:foo)
45
+
46
+ hh.evalhook("
47
+ class Y2
48
+ def bar(x)
49
+ x.foo
50
+ end
51
+ end
52
+ ", binding
53
+ )
54
+
55
+ y2 = Y2.new
56
+ y2.bar(x)
57
+
58
+ end
59
+
60
+ it "should capture inside class and yield" do
61
+ x = X.new
62
+ hh = EvalHook::HookHandler.new
63
+
64
+ hh.should_receive(:handle_method)
65
+ hh.should_receive(:handle_method).with(X,x,:foo)
66
+
67
+ hh.evalhook("
68
+ class Y3
69
+ def bar_(x)
70
+ yield(x)
71
+ end
72
+
73
+ def bar(x)
74
+ bar_(x) do |x_|
75
+ x_.foo
76
+ end
77
+ end
78
+ end
79
+ ", binding
80
+ )
81
+
82
+ y3 = Y3.new
83
+ y3.bar(x)
84
+
85
+ end
86
+
87
+ it "should capture inside a proc" do
88
+ x = X.new
89
+ hh = EvalHook::HookHandler.new
90
+
91
+ hh.should_receive(:handle_method).with(Kernel, anything(),:proc)
92
+ hh.should_receive(:handle_method).with(X,x,:foo)
93
+
94
+ c = nil
95
+ hh.evalhook("
96
+ c = proc do |x| x.foo end
97
+ ", binding
98
+ )
99
+ c.call(x)
100
+
101
+ end
102
+
103
+ end
@@ -0,0 +1,19 @@
1
+ require "rubygems"
2
+ require "evalhook"
3
+
4
+ describe EvalHook::HookHandler, "hook handler flaws" do
5
+
6
+ it "should validate invalid syntax" do
7
+
8
+ hh = EvalHook::HookHandler.new
9
+
10
+ lambda {
11
+ hh.evalhook("
12
+ 0
13
+ end
14
+ if (true)
15
+ ")
16
+ }.should raise_error(SyntaxError)
17
+
18
+ end
19
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evalhook
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dario Seminara
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-22 00:00:00 -03:00
18
+ date: 2011-04-03 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: evalmimic
22
+ name: partialruby
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
@@ -34,12 +34,28 @@ dependencies:
34
34
  version: 0.1.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: ruby_parser
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 6
50
+ version: 2.0.6
51
+ type: :runtime
52
+ version_requirements: *id002
37
53
  description:
38
54
  email: robertodarioseminara@gmail.com
39
55
  executables: []
40
56
 
41
- extensions:
42
- - ext/evalhook_base/extconf.rb
57
+ extensions: []
58
+
43
59
  extra_rdoc_files:
44
60
  - README
45
61
  files:
@@ -49,10 +65,18 @@ files:
49
65
  - examples/example4.rb
50
66
  - examples/example2.rb
51
67
  - lib/evalhook/multi_hook_handler.rb
68
+ - lib/evalhook/hook_handler.rb
52
69
  - lib/evalhook/redirect_helper.rb
70
+ - lib/evalhook/hook_context.rb
53
71
  - lib/evalhook.rb
54
- - ext/evalhook_base/evalhook_base.c
55
- - ext/evalhook_base/extconf.rb
72
+ - spec/hook_handler/hook_handler_arguments_spec.rb
73
+ - spec/hook_handler/hook_handler_hook_spec.rb
74
+ - spec/hook_handler/hook_handler_multiple_redirect_spec.rb
75
+ - spec/hook_handler/hook_handler_multiple_spec.rb
76
+ - spec/hook_handler/hook_handler_visitor_spec.rb
77
+ - spec/hook_handler/hook_handler_ruby_spec.rb
78
+ - spec/hook_handler/hook_handler_defaults_spec.rb
79
+ - spec/validation/hook_handler_spec.rb
56
80
  - LICENSE
57
81
  - AUTHORS
58
82
  - CHANGELOG