serializable_proc 0.1.1 → 0.2.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.
Files changed (41) hide show
  1. data/.gitignore +1 -0
  2. data/HISTORY.txt +9 -0
  3. data/README.rdoc +28 -10
  4. data/VERSION +1 -1
  5. data/lib/serializable_proc/binding.rb +27 -32
  6. data/lib/serializable_proc/fixes.rb +1 -1
  7. data/lib/serializable_proc/isolatable.rb +59 -0
  8. data/lib/serializable_proc/parsers/pt.rb +2 -5
  9. data/lib/serializable_proc/parsers/rp.rb +29 -29
  10. data/lib/serializable_proc/parsers.rb +22 -0
  11. data/lib/serializable_proc.rb +76 -10
  12. data/serializable_proc.gemspec +51 -21
  13. data/spec/bounded_vars/class_vars_spec.rb +60 -0
  14. data/spec/bounded_vars/class_vars_within_block_scope_spec.rb +31 -0
  15. data/spec/bounded_vars/errors_spec.rb +27 -0
  16. data/spec/bounded_vars/global_vars_spec.rb +60 -0
  17. data/spec/bounded_vars/global_vars_within_block_scope_spec.rb +31 -0
  18. data/spec/bounded_vars/instance_vars_spec.rb +60 -0
  19. data/spec/bounded_vars/instance_vars_within_block_scope_spec.rb +31 -0
  20. data/spec/bounded_vars/local_vars_spec.rb +60 -0
  21. data/spec/bounded_vars/local_vars_within_block_scope_spec.rb +31 -0
  22. data/spec/code_block/errors_spec.rb +65 -0
  23. data/spec/{multiple_arities_serializable_proc_spec.rb → code_block/multiple_arities_spec.rb} +2 -2
  24. data/spec/{optional_arity_serializable_proc_spec.rb → code_block/optional_arity_spec.rb} +2 -2
  25. data/spec/code_block/renaming_vars_spec.rb +160 -0
  26. data/spec/{one_arity_serializable_proc_spec.rb → code_block/single_arity_spec.rb} +2 -2
  27. data/spec/{zero_arity_serializable_proc_spec.rb → code_block/zero_arity_spec.rb} +2 -2
  28. data/spec/proc_like/extras_spec.rb +82 -0
  29. data/spec/proc_like/invoking_with_args_spec.rb +58 -0
  30. data/spec/proc_like/invoking_with_class_vars_spec.rb +96 -0
  31. data/spec/proc_like/invoking_with_global_vars_spec.rb +79 -0
  32. data/spec/proc_like/invoking_with_instance_vars_spec.rb +79 -0
  33. data/spec/proc_like/invoking_with_local_vars_spec.rb +79 -0
  34. data/spec/{marshalling_spec.rb → proc_like/marshalling_spec.rb} +1 -1
  35. data/spec/proc_like/others_spec.rb +106 -0
  36. data/spec/spec_helper.rb +10 -0
  37. metadata +52 -22
  38. data/lib/serializable_proc/sandboxer.rb +0 -24
  39. data/spec/extracting_bound_variables_spec.rb +0 -99
  40. data/spec/initializing_errors_spec.rb +0 -95
  41. data/spec/proc_like_spec.rb +0 -191
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Extracting class vars' do
4
+
5
+ extend SerializableProc::Spec::Helpers
6
+
7
+ should 'handle outer-scoped ones if @@_not_isolated_vars excludes :class' do
8
+ @@x, @@y = 'awe', 'some'
9
+ should_have_expected_binding \
10
+ SerializableProc.new {
11
+ @@_not_isolated_vars = nil
12
+ @@x + @@y
13
+ }, {:cvar_x => @@x, :cvar_y => @@y}
14
+ end
15
+
16
+ should "handle inner-scoped ones if @@_not_isolated_vars excludes :class" do
17
+ @@x, @@y = 'awe', 'some'
18
+ should_have_expected_binding \
19
+ SerializableProc.new {
20
+ @@_not_isolated_vars = nil
21
+ @@z = 'wonder'
22
+ %w{a b}.each{ puts @@z, @@x, @@y }
23
+ }, {:cvar_x => @@x, :cvar_y => @@y, :cvar_z => nil}
24
+ end
25
+
26
+ should 'not handle outer-scoped ones if @@_not_isolated_vars includes :class' do
27
+ @@x, @@y = 'awe', 'some'
28
+ should_have_empty_binding \
29
+ SerializableProc.new {
30
+ @@_not_isolated_vars = :class;
31
+ @@x + @@y
32
+ }
33
+ end
34
+
35
+ should "not handle inner-scoped ones if @@_not_isolated_vars includes :class" do
36
+ @@x, @@y = 'awe', 'some'
37
+ should_have_empty_binding \
38
+ SerializableProc.new {
39
+ @@_not_isolated_vars = :class;
40
+ @@z = 'wonder'
41
+ %w{a b}.each{ puts @@z, @@x, @@y }
42
+ }
43
+ end
44
+
45
+ should 'handle outer-scoped ones w @@_not_isolated_vars unspecified' do
46
+ @@x, @@y = 'awe', 'some'
47
+ should_have_expected_binding \
48
+ SerializableProc.new { @@x + @@y }, {:cvar_x => @@x, :cvar_y => @@y}
49
+ end
50
+
51
+ should "handle inner-scoped ones w @@_not_isolated_vars unspecified" do
52
+ @@x, @@y = 'awe', 'some'
53
+ should_have_expected_binding \
54
+ SerializableProc.new {
55
+ @@z = 'wonder'
56
+ %w{a b}.each{ puts @@z, @@x, @@y }
57
+ }, {:cvar_x => @@x, :cvar_y => @@y, :cvar_z => nil}
58
+ end
59
+
60
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Extracting class vars within block scope' do
4
+
5
+ extend SerializableProc::Spec::Helpers
6
+
7
+ should "not handle w @@_not_isolated_vars unspecified" do
8
+ @@x = 'ox'
9
+ should_have_empty_binding \
10
+ SerializableProc.new { def test ; @@x = 'cx' ; end }
11
+ end
12
+
13
+ should "not handle if @@_not_isolated_vars includes :class" do
14
+ @@x = 'ox'
15
+ should_have_empty_binding \
16
+ SerializableProc.new {
17
+ @@_not_isolated_vars = :class
18
+ def test ; @@x = 'cx' ; end
19
+ }
20
+ end
21
+
22
+ should "not handle if @@_not_isolated_vars excludes :class" do
23
+ @@x = 'ox'
24
+ should_have_empty_binding \
25
+ SerializableProc.new {
26
+ @@_not_isolated_vars = nil
27
+ def test ; @@x = 'cx' ; end
28
+ }
29
+ end
30
+
31
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'SerializableProc::CannotSerializeVariableError' do
4
+
5
+ extend SerializableProc::Spec::Helpers
6
+
7
+ should "raise if local variable cannot be marshalled" do
8
+ f = Tempfile.new('fake')
9
+ lambda { SerializableProc.new{ f } }.should.be raising_cannot_serialize_variable_error('f')
10
+ end
11
+
12
+ should "raise if class variable cannot be marshalled" do
13
+ @@f = Tempfile.new('fake')
14
+ lambda { SerializableProc.new{ @@f } }.should.be raising_cannot_serialize_variable_error('@@f')
15
+ end
16
+
17
+ should "raise if instance variable cannot be marshalled" do
18
+ @f = Tempfile.new('fake')
19
+ lambda { SerializableProc.new{ @f } }.should.be raising_cannot_serialize_variable_error('@f')
20
+ end
21
+
22
+ should "raise if global variable cannot be marshalled" do
23
+ $f = Tempfile.new('fake')
24
+ lambda { SerializableProc.new{ $f } }.should.be raising_cannot_serialize_variable_error('$f')
25
+ end
26
+
27
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Extracting global vars' do
4
+
5
+ extend SerializableProc::Spec::Helpers
6
+
7
+ should 'handle outer-scoped ones if @@_not_isolated_vars excludes :global' do
8
+ $x, $y = 'awe', 'some'
9
+ should_have_expected_binding \
10
+ SerializableProc.new {
11
+ @@_not_isolated_vars = nil
12
+ $x + $y
13
+ }, {:gvar_x => $x, :gvar_y => $y}
14
+ end
15
+
16
+ should "handle inner-scoped ones if @@_not_isolated_vars excludes :global" do
17
+ $x, $y = 'awe', 'some'
18
+ should_have_expected_binding \
19
+ SerializableProc.new {
20
+ @@_not_isolated_vars = nil
21
+ $z = 'wonder'
22
+ %w{a b}.each{ puts $z, $x, $y }
23
+ }, {:gvar_x => $x, :gvar_y => $y, :gvar_z => nil}
24
+ end
25
+
26
+ should 'not handle outer-scoped ones if @@_not_isolated_vars includes :global' do
27
+ $x, $y = 'awe', 'some'
28
+ should_have_empty_binding \
29
+ SerializableProc.new {
30
+ @@_not_isolated_vars = :global;
31
+ $x + $y
32
+ }
33
+ end
34
+
35
+ should "not handle inner-scoped ones if @@_not_isolated_vars includes :global" do
36
+ $x, $y = 'awe', 'some'
37
+ should_have_empty_binding \
38
+ SerializableProc.new {
39
+ @@_not_isolated_vars = :global;
40
+ $z = 'wonder'
41
+ %w{a b}.each{ puts $z, $x, $y }
42
+ }
43
+ end
44
+
45
+ should 'handle outer-scoped ones w @@_not_isolated_vars unspecified' do
46
+ $x, $y = 'awe', 'some'
47
+ should_have_expected_binding \
48
+ SerializableProc.new { $x + $y }, {:gvar_x => $x, :gvar_y => $y}
49
+ end
50
+
51
+ should "handle inner-scoped ones w @@_not_isolated_vars unspecified" do
52
+ $x, $y = 'awe', 'some'
53
+ should_have_expected_binding \
54
+ SerializableProc.new {
55
+ $z = 'wonder'
56
+ %w{a b}.each{ puts $z, $x, $y }
57
+ }, {:gvar_x => $x, :gvar_y => $y, :gvar_z => nil}
58
+ end
59
+
60
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Extracting global vars within block scope' do
4
+
5
+ extend SerializableProc::Spec::Helpers
6
+
7
+ should "not handle w @@_not_isolated_vars unspecified" do
8
+ $x = 'ox'
9
+ should_have_empty_binding \
10
+ SerializableProc.new { def test ; $x = 'gx' ; end }
11
+ end
12
+
13
+ should "not handle if @@_not_isolated_vars includes :global" do
14
+ $x = 'ox'
15
+ should_have_empty_binding \
16
+ SerializableProc.new {
17
+ @@_not_isolated_vars = :global
18
+ def test ; $x = 'gx' ; end
19
+ }
20
+ end
21
+
22
+ should "not handle if @@_not_isolated_vars excludes :global" do
23
+ $x = 'ox'
24
+ should_have_empty_binding \
25
+ SerializableProc.new {
26
+ @@_not_isolated_vars = nil
27
+ def test ; $x = 'gx' ; end
28
+ }
29
+ end
30
+
31
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Extracting instance vars' do
4
+
5
+ extend SerializableProc::Spec::Helpers
6
+
7
+ should 'handle outer-scoped ones if @@_not_isolated_vars excludes :instance' do
8
+ @x, @y = 'awe', 'some'
9
+ should_have_expected_binding \
10
+ SerializableProc.new {
11
+ @@_not_isolated_vars = nil
12
+ @x + @y
13
+ }, {:ivar_x => @x, :ivar_y => @y}
14
+ end
15
+
16
+ should "handle inner-scoped ones if @@_not_isolated_vars excludes :instance" do
17
+ @x, @y = 'awe', 'some'
18
+ should_have_expected_binding \
19
+ SerializableProc.new {
20
+ @@_not_isolated_vars = nil
21
+ @z = 'wonder'
22
+ %w{a b}.each{ puts @z, @x, @y }
23
+ }, {:ivar_x => @x, :ivar_y => @y, :ivar_z => nil}
24
+ end
25
+
26
+ should 'not handle outer-scoped ones if @@_not_isolated_vars includes :instance' do
27
+ @x, @y = 'awe', 'some'
28
+ should_have_empty_binding \
29
+ SerializableProc.new {
30
+ @@_not_isolated_vars = :instance;
31
+ @x + @y
32
+ }
33
+ end
34
+
35
+ should "not handle inner-scoped ones if @@_not_isolated_vars includes :instance" do
36
+ @x, @y = 'awe', 'some'
37
+ should_have_empty_binding \
38
+ SerializableProc.new {
39
+ @@_not_isolated_vars = :instance;
40
+ @z = 'wonder'
41
+ %w{a b}.each{ puts @z, @x, @y }
42
+ }
43
+ end
44
+
45
+ should 'handle outer-scoped ones w @@_not_isolated_vars unspecified' do
46
+ @x, @y = 'awe', 'some'
47
+ should_have_expected_binding \
48
+ SerializableProc.new { @x + @y }, {:ivar_x => @x, :ivar_y => @y}
49
+ end
50
+
51
+ should "handle inner-scoped ones w @@_not_isolated_vars unspecified" do
52
+ @x, @y = 'awe', 'some'
53
+ should_have_expected_binding \
54
+ SerializableProc.new {
55
+ @z = 'wonder'
56
+ %w{a b}.each{ puts @z, @x, @y }
57
+ }, {:ivar_x => @x, :ivar_y => @y, :ivar_z => nil}
58
+ end
59
+
60
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Extracting instance vars within block scope' do
4
+
5
+ extend SerializableProc::Spec::Helpers
6
+
7
+ should "not handle w @@_not_isolated_vars unspecified" do
8
+ @x = 'ox'
9
+ should_have_empty_binding \
10
+ SerializableProc.new { def test ; @x = 'ix' ; end }
11
+ end
12
+
13
+ should "not handle if @@_not_isolated_vars includes :instance" do
14
+ @x = 'ox'
15
+ should_have_empty_binding \
16
+ SerializableProc.new {
17
+ @@_not_isolated_vars = :instance
18
+ def test ; @x = 'ix' ; end
19
+ }
20
+ end
21
+
22
+ should "not handle if @@_not_isolated_vars excludes :instance" do
23
+ @x = 'ox'
24
+ should_have_empty_binding \
25
+ SerializableProc.new {
26
+ @@_not_isolated_vars = nil
27
+ def test ; @x = 'ix' ; end
28
+ }
29
+ end
30
+
31
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Extracting local vars' do
4
+
5
+ extend SerializableProc::Spec::Helpers
6
+
7
+ should 'handle outer-scoped ones if @@_not_isolated_vars excludes :local' do
8
+ x, y = 'awe', 'some'
9
+ should_have_expected_binding \
10
+ SerializableProc.new {
11
+ @@_not_isolated_vars = nil
12
+ x + y
13
+ }, {:lvar_x => x, :lvar_y => y}
14
+ end
15
+
16
+ should "handle inner-scoped ones if @@_not_isolated_vars excludes :local" do
17
+ x, y = 'awe', 'some'
18
+ should_have_expected_binding \
19
+ SerializableProc.new {
20
+ @@_not_isolated_vars = nil
21
+ z = 'wonder'
22
+ %w{a b}.each{ puts z, x, y }
23
+ }, {:lvar_x => x, :lvar_y => y, :lvar_z => nil}
24
+ end
25
+
26
+ should 'not handle outer-scoped ones if @@_not_isolated_vars includes :local' do
27
+ x, y = 'awe', 'some'
28
+ should_have_empty_binding \
29
+ SerializableProc.new {
30
+ @@_not_isolated_vars = :local;
31
+ x + y
32
+ }
33
+ end
34
+
35
+ should "not handle inner-scoped ones if @@_not_isolated_vars includes :local" do
36
+ x, y = 'awe', 'some'
37
+ should_have_empty_binding \
38
+ SerializableProc.new {
39
+ @@_not_isolated_vars = :local;
40
+ z = 'wonder'
41
+ %w{a b}.each{ puts z, x, y }
42
+ }
43
+ end
44
+
45
+ should 'handle outer-scoped ones w @@_not_isolated_vars unspecified' do
46
+ x, y = 'awe', 'some'
47
+ should_have_expected_binding \
48
+ SerializableProc.new { x + y }, {:lvar_x => x, :lvar_y => y}
49
+ end
50
+
51
+ should "handle inner-scoped ones w @@_not_isolated_vars unspecified" do
52
+ x, y = 'awe', 'some'
53
+ should_have_expected_binding \
54
+ SerializableProc.new {
55
+ z = 'wonder'
56
+ %w{a b}.each{ puts z, x, y }
57
+ }, {:lvar_x => x, :lvar_y => y, :lvar_z => nil}
58
+ end
59
+
60
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Extracting local vars within block scope' do
4
+
5
+ extend SerializableProc::Spec::Helpers
6
+
7
+ should "not handle w @@_mingle_vars unspecified" do
8
+ x = 'ox'
9
+ should_have_empty_binding \
10
+ SerializableProc.new { def test ; x = 'lx' ; end }
11
+ end
12
+
13
+ should "not handle if @@_mingle_vars includes :local" do
14
+ x = 'ox'
15
+ should_have_empty_binding \
16
+ SerializableProc.new {
17
+ @@_mingle_vars = :local
18
+ def test ; x = 'lx' ; end
19
+ }
20
+ end
21
+
22
+ should "not handle if @@_mingle_vars excludes :local" do
23
+ x = 'ox'
24
+ should_have_empty_binding \
25
+ SerializableProc.new {
26
+ @@_mingle_vars = nil
27
+ def test ; x = 'lx' ; end
28
+ }
29
+ end
30
+
31
+ end
@@ -0,0 +1,65 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'SerializableProc::CannotAnalyseCodeError' do
4
+ unless $parse_tree_installed
5
+
6
+ extend SerializableProc::Spec::Helpers
7
+
8
+ should "raise if line has more than 1 'SerializableProc.new'" do
9
+ lambda {
10
+ SerializableProc.new {} ; SerializableProc.new { |arg| %w{a b}.map{|x| puts x } }
11
+ }.should.be raising_cannot_analyse_error("'SerializableProc.new'")
12
+ end
13
+
14
+ should "raise if line has more than 1 'Proc.new'" do
15
+ lambda {
16
+ p1 = Proc.new {} ; p2 = Proc.new { |arg| %w{a b}.map{|x| puts x } }
17
+ SerializableProc.new(&p2)
18
+ }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
19
+ end
20
+
21
+ should "raise if line has more than 1 'lambda'" do
22
+ lambda {
23
+ p1 = lambda {} ; p2 = lambda { |arg| %w{a b}.map{|x| puts x } }
24
+ SerializableProc.new(&p2)
25
+ }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
26
+ end
27
+
28
+ should "raise if line has more than 1 'proc'" do
29
+ lambda {
30
+ p1 = proc {} ; p2 = proc { |arg| %w{a b}.map{|x| puts x } }
31
+ SerializableProc.new(&p2)
32
+ }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
33
+ end
34
+
35
+ should "raise if line mixes 'lambda' & 'proc'" do
36
+ lambda {
37
+ p1 = lambda {} ; p2 = proc { |arg| %w{a b}.map{|x| puts x } }
38
+ SerializableProc.new(&p2)
39
+ }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
40
+ end
41
+
42
+ should "raise if line mixes 'Proc.new' & 'proc'" do
43
+ lambda {
44
+ p1 = Proc.new {} ; p2 = proc { |arg| %w{a b}.map{|x| puts x } }
45
+ SerializableProc.new(&p2)
46
+ }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
47
+ end
48
+
49
+ should "raise if line mixes 'Proc.new' & 'lambda'" do
50
+ lambda {
51
+ p1 = Proc.new {} ; p2 = lambda { |arg| %w{a b}.map{|x| puts x } }
52
+ SerializableProc.new(&p2)
53
+ }.should.be raising_cannot_analyse_error("'lambda'/'proc'/'Proc.new'")
54
+ end
55
+
56
+ should "raise if line does not have lambda, proc, Proc.new or SerializableProc.new" do
57
+ lambda {
58
+ def create_serializable_proc(&block) ; SerializableProc.new(&block) ; end
59
+ create_serializable_proc { %w{a b}.map{|x| puts x } }
60
+ }.should.raise(SerializableProc::CannotAnalyseCodeError).
61
+ message.should.equal('Cannot find specified initializer !!')
62
+ end
63
+
64
+ end
65
+ end
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
- describe 'Multiple arities serializable proc' do
3
+ describe 'Extracting multiple arities code block' do
4
4
 
5
5
  extend SerializableProc::Spec::Helpers
6
6
 
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
- describe 'Optional arity serializable proc' do
3
+ describe 'Extracting optional arity code block' do
4
4
 
5
5
  extend SerializableProc::Spec::Helpers
6
6
 
@@ -0,0 +1,160 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe 'Renaming variables' do
4
+
5
+ describe '>> wo specified @@_not_isolated_vars' do
6
+ extend SerializableProc::Spec::Helpers
7
+
8
+ should 'handle global, class, instance & local' do
9
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
10
+ SerializableProc.new{ [x, @x, @@x, $x] }.should.be \
11
+ having_runnable_code_as('lambda{ [lvar_x, ivar_x, cvar_x, gvar_x] }')
12
+ end
13
+
14
+ should 'not handle block-scoped ones (single)' do
15
+ (
16
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
17
+ SerializableProc.new do
18
+ [x, @x, @@x, $x]
19
+ def test(x) ; [x, @x, @@x, $x] ; end
20
+ end
21
+ ).should.be having_runnable_code_as('
22
+ lambda do
23
+ [lvar_x, ivar_x, cvar_x, gvar_x]
24
+ def test(x) ; [x, @x, @@x, $x] ; end
25
+ end
26
+ ')
27
+ end
28
+
29
+ should 'not handle block-scoped ones (multiple)' do
30
+ (
31
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
32
+ SerializableProc.new do
33
+ [x, @x, @@x, $x]
34
+ def test1(x) ; [x, @x, @@x, $x] ; end
35
+ def test2(x) ; [x, @x, @@x, $x] ; end
36
+ end
37
+ ).should.be having_runnable_code_as('
38
+ lambda do
39
+ [lvar_x, ivar_x, cvar_x, gvar_x]
40
+ def test1(x) ; [x, @x, @@x, $x] ; end
41
+ def test2(x) ; [x, @x, @@x, $x] ; end
42
+ end
43
+ ')
44
+ end
45
+
46
+ end
47
+
48
+ describe '>> w @@_not_isolated_vars specified' do
49
+ extend SerializableProc::Spec::Helpers
50
+
51
+ should 'handle only class, instance & local w only :global' do
52
+ (
53
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
54
+ SerializableProc.new do
55
+ @@_not_isolated_vars = :global
56
+ [x, @x, @@x, $x]
57
+ end
58
+ ).should.be having_runnable_code_as('
59
+ lambda do
60
+ @@_not_isolated_vars = :global
61
+ [lvar_x, ivar_x, cvar_x, $x]
62
+ end
63
+ ')
64
+ end
65
+
66
+ should 'handle only global, instance & local w only :class' do
67
+ (
68
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
69
+ SerializableProc.new do
70
+ @@_not_isolated_vars = :class
71
+ [x, @x, @@x, $x]
72
+ end
73
+ ).should.be having_runnable_code_as('
74
+ lambda do
75
+ @@_not_isolated_vars = :class
76
+ [lvar_x, ivar_x, @@x, gvar_x]
77
+ end
78
+ ')
79
+ end
80
+
81
+ should 'handle only global, class & local w only :instance' do
82
+ (
83
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
84
+ SerializableProc.new do
85
+ @@_not_isolated_vars = :instance
86
+ [x, @x, @@x, $x]
87
+ end
88
+ ).should.be having_runnable_code_as('
89
+ lambda do
90
+ @@_not_isolated_vars = :instance
91
+ [lvar_x, @x, cvar_x, gvar_x]
92
+ end
93
+ ')
94
+ end
95
+
96
+ should 'handle only global, class & instance w only :local' do
97
+ (
98
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
99
+ SerializableProc.new do
100
+ @@_not_isolated_vars = :local
101
+ [x, @x, @@x, $x]
102
+ end
103
+ ).should.be having_runnable_code_as('
104
+ lambda do
105
+ @@_not_isolated_vars = :local
106
+ [x, ivar_x, cvar_x, gvar_x]
107
+ end
108
+ ')
109
+ end
110
+
111
+ should 'handle only instance & local w :global & :class' do
112
+ (
113
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
114
+ SerializableProc.new do
115
+ @@_not_isolated_vars = :global, :class
116
+ [x, @x, @@x, $x]
117
+ end
118
+ ).should.be having_runnable_code_as('
119
+ lambda do
120
+ @@_not_isolated_vars = :global, :class
121
+ [lvar_x, ivar_x, @@x, $x]
122
+ end
123
+ ')
124
+ end
125
+
126
+ should 'not handle block-scoped ones (single)' do
127
+ (
128
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
129
+ SerializableProc.new do
130
+ @@_not_isolated_vars = :global, :class
131
+ def test(x) ; [x, @x, @@x, $x] ; end
132
+ end
133
+ ).should.be having_runnable_code_as('
134
+ lambda do
135
+ @@_not_isolated_vars = :global, :class
136
+ def test(x) ; [x, @x, @@x, $x] ; end
137
+ end
138
+ ')
139
+ end
140
+
141
+ should 'not handle block-scoped ones (multiple)' do
142
+ (
143
+ x, @x, @@x, $x = 'lx', 'ix', 'cx', 'gx'
144
+ SerializableProc.new do
145
+ @@_not_isolated_vars = :global, :class
146
+ def test1(x) ; [x, @x, @@x, $x] ; end
147
+ def test2(x) ; [x, @x, @@x, $x] ; end
148
+ end
149
+ ).should.be having_runnable_code_as('
150
+ lambda do
151
+ @@_not_isolated_vars = :global, :class
152
+ def test1(x) ; [x, @x, @@x, $x] ; end
153
+ def test2(x) ; [x, @x, @@x, $x] ; end
154
+ end
155
+ ')
156
+ end
157
+
158
+ end
159
+
160
+ end
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
- describe 'One arity serializable proc' do
3
+ describe 'Extracting single arity code block' do
4
4
 
5
5
  extend SerializableProc::Spec::Helpers
6
6
 
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
- describe 'Zero arity serializable proc' do
3
+ describe 'Extracting zero arity code block' do
4
4
 
5
5
  extend SerializableProc::Spec::Helpers
6
6