boca-golf 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 CHANGED
@@ -1,4 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem 'fakeweb'
4
- gem 'rspec', require: 'spec'
4
+ gem 'rspec', :require => 'spec'
data/Rakefile CHANGED
@@ -5,4 +5,9 @@ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- task default: :spec
8
+ task :default => :spec_on_supported_ruby_versions
9
+
10
+ task :spec_on_supported_ruby_versions do
11
+ sh "rvm 1.9.2 exec rake spec"
12
+ sh "rvm 1.8.7 exec rake spec"
13
+ end
@@ -34,10 +34,10 @@ class BocaGolf
34
34
  protected
35
35
 
36
36
  def insecure_module
37
- -> do
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
- -> do
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
@@ -1,7 +1,11 @@
1
1
  class BocaGolf
2
2
  class Scorer
3
3
  def score(gist)
4
- gist.code.length
4
+ if RUBY_VERSION >= "1.9"
5
+ gist.code.length
6
+ else
7
+ gist.code.unpack("U*").length
8
+ end
5
9
  end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  class BocaGolf
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,4 +1,4 @@
1
- require_relative 'spec_helper'
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("def reverse(a) a.reverse; end")
14
- .score.should == 29
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: gist
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
- require_relative 'spec_helper'
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
- -> { foobar '1' }.should raise_error NoMethodError
14
+ lambda { foobar '1' }.should raise_error NoMethodError
15
15
  end
16
16
 
17
17
  def run_specs_on_gist(code)
@@ -1,9 +1,9 @@
1
- require_relative 'spec_helper'
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: gist
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
- require_relative 'spec_helper'
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
- -> do
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
- -> { o.foo }.should raise_error(SecurityError)
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: code
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: code
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
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require_relative 'spec_helper'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
3
3
 
4
4
  describe BocaGolf::Scorer do
5
5
  describe "score" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
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-08 00:00:00 -05:00
17
+ date: 2011-01-11 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20