boca-golf 0.0.2 → 0.0.3
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.
- data/Gemfile +1 -1
- data/Rakefile +6 -1
- data/lib/boca_golf/gist.rb +6 -6
- data/lib/boca_golf/scorer.rb +5 -1
- data/lib/boca_golf/version.rb +1 -1
- data/spec/boca_golf_spec.rb +6 -5
- data/spec/checker_spec.rb +2 -2
- data/spec/command_line_spec.rb +2 -2
- data/spec/gist_spec.rb +5 -5
- data/spec/scorer_spec.rb +1 -1
- metadata +3 -3
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/boca_golf/gist.rb
CHANGED
@@ -34,10 +34,10 @@ class BocaGolf
|
|
34
34
|
protected
|
35
35
|
|
36
36
|
def insecure_module
|
37
|
-
|
37
|
+
lambda do
|
38
38
|
$SAFE = 4
|
39
39
|
Module.new.tap do |m|
|
40
|
-
m.module_eval code
|
40
|
+
m.module_eval code, "__GIST__"
|
41
41
|
end
|
42
42
|
end.call
|
43
43
|
end
|
@@ -45,14 +45,14 @@ class BocaGolf
|
|
45
45
|
def proxy_module(mod)
|
46
46
|
Module.new.tap do |proxy|
|
47
47
|
mod.instance_methods.each do |method|
|
48
|
-
proxy.module_eval
|
48
|
+
proxy.module_eval <<-end_code, __FILE__, (__LINE__ + 1)
|
49
49
|
def #{method}(*args, &block)
|
50
|
-
|
50
|
+
lambda do
|
51
51
|
$SAFE = 4
|
52
|
-
super
|
52
|
+
super(*args, &block)
|
53
53
|
end.call
|
54
54
|
end
|
55
|
-
|
55
|
+
end_code
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
data/lib/boca_golf/scorer.rb
CHANGED
data/lib/boca_golf/version.rb
CHANGED
data/spec/boca_golf_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe BocaGolf do
|
4
4
|
it "passes if all specs passed" do
|
@@ -10,15 +10,16 @@ describe BocaGolf do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "scores the gist" do
|
13
|
-
run_specs_on_gist(
|
14
|
-
|
13
|
+
run_specs_on_gist(
|
14
|
+
"def reverse(a) a.reverse; end"
|
15
|
+
).score.should == 29
|
15
16
|
end
|
16
17
|
|
17
18
|
def run_specs_on_gist(gist)
|
18
19
|
gist.taint
|
19
|
-
gist.untrust
|
20
|
+
gist.untrust if RUBY_VERSION >= "1.9"
|
20
21
|
|
21
|
-
FakeWeb.register_uri :get, "https://gist.github.com/746166.txt", body
|
22
|
+
FakeWeb.register_uri :get, "https://gist.github.com/746166.txt", :body => gist
|
22
23
|
stdout, stderr = StringIO.new, StringIO.new
|
23
24
|
sandboxed do
|
24
25
|
BocaGolf.new.run(["https://gist.github.com/746166", "spec/infrastructure/reverse_specs/spec.rb"], stdout, stderr)
|
data/spec/checker_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe BocaGolf::Checker do
|
4
4
|
it "returns true if all specs pass" do
|
@@ -11,7 +11,7 @@ describe BocaGolf::Checker do
|
|
11
11
|
|
12
12
|
it "doesn't make methods available everywhere" do
|
13
13
|
run_specs_on_gist "def foobar(a) a; end"
|
14
|
-
|
14
|
+
lambda { foobar '1' }.should raise_error NoMethodError
|
15
15
|
end
|
16
16
|
|
17
17
|
def run_specs_on_gist(code)
|
data/spec/command_line_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe BocaGolf::CommandLine do
|
4
4
|
it "prints the expected result" do
|
5
5
|
gist = "def reverse(a) a.reverse; end"
|
6
|
-
FakeWeb.register_uri :get, "https://gist.github.com/746166.txt", body
|
6
|
+
FakeWeb.register_uri :get, "https://gist.github.com/746166.txt", :body => gist
|
7
7
|
stdout, stderr = StringIO.new, StringIO.new
|
8
8
|
|
9
9
|
sandboxed do
|
data/spec/gist_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe BocaGolf::Gist do
|
4
4
|
describe "safe_module" do
|
@@ -9,7 +9,7 @@ describe BocaGolf::Gist do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "evals code at safe level 4" do
|
12
|
-
|
12
|
+
lambda do
|
13
13
|
BocaGolf::Gist.new(%{
|
14
14
|
def reverse(a) a.reverse; end;
|
15
15
|
class ::Object; def foo() end; end
|
@@ -26,14 +26,14 @@ describe BocaGolf::Gist do
|
|
26
26
|
}).safe_module
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
lambda { o.foo }.should raise_error(SecurityError)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "load_from_url" do
|
34
34
|
it "requests the .txt version of gist" do
|
35
35
|
code = "def a(); end"
|
36
|
-
FakeWeb.register_uri :get, "https://gist.github.com/746166.txt", body
|
36
|
+
FakeWeb.register_uri :get, "https://gist.github.com/746166.txt", :body => code
|
37
37
|
BocaGolf::Gist.load_from_url("https://gist.github.com/746166").code.should == code
|
38
38
|
end
|
39
39
|
end
|
@@ -48,7 +48,7 @@ describe BocaGolf::Gist do
|
|
48
48
|
describe "load_from_location" do
|
49
49
|
it "loads from url when argument is a valid url" do
|
50
50
|
code = "def a(); end"
|
51
|
-
FakeWeb.register_uri :get, "https://gist.github.com/746166.txt", body
|
51
|
+
FakeWeb.register_uri :get, "https://gist.github.com/746166.txt", :body => code
|
52
52
|
BocaGolf::Gist.load_from_location("https://gist.github.com/746166").code.should == code
|
53
53
|
end
|
54
54
|
|
data/spec/scorer_spec.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Vollbracht
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-11 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|