boca-golf 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +88 -0
- data/boca-golf.gemspec +1 -1
- data/lib/boca_golf/command_line.rb +14 -0
- data/lib/boca_golf/version.rb +1 -1
- data/spec/command_line_spec.rb +18 -0
- metadata +5 -4
data/README.rdoc
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
== Boca Golf
|
2
|
+
|
3
|
+
A simple command line utility for playing ruby golf with problems defined via RSpec examples.
|
4
|
+
|
5
|
+
In ruby golf, you need to write a function that passes the provided specs in the fewest characters you can.
|
6
|
+
|
7
|
+
== Install
|
8
|
+
|
9
|
+
gem install boca-golf
|
10
|
+
|
11
|
+
== Get Some Problems
|
12
|
+
|
13
|
+
git clone git://github.com/flipstone/boca-golf-problems.git
|
14
|
+
|
15
|
+
== Write a File
|
16
|
+
|
17
|
+
in my_solution.rb:
|
18
|
+
|
19
|
+
def sanitize(word, string)
|
20
|
+
... your implementation ...
|
21
|
+
end
|
22
|
+
|
23
|
+
then:
|
24
|
+
|
25
|
+
boca-golf my_solution.rb boca-golf-problems/sanitize/spec.rb
|
26
|
+
|
27
|
+
|
28
|
+
and see:
|
29
|
+
|
30
|
+
Testing my_solution.rb against specs:
|
31
|
+
- boca-golf-problems/sanitize/spec.rb
|
32
|
+
|
33
|
+
...
|
34
|
+
|
35
|
+
Finished in 0.0007 seconds
|
36
|
+
3 examples, 0 failures
|
37
|
+
|
38
|
+
Code:
|
39
|
+
def sanitize(word, string)
|
40
|
+
... your implementation ...
|
41
|
+
end
|
42
|
+
|
43
|
+
Score:
|
44
|
+
<# of characters in your solution>
|
45
|
+
|
46
|
+
|
47
|
+
== Upload your answer
|
48
|
+
|
49
|
+
Go to https://gist.github.com and create a gist with your solution
|
50
|
+
|
51
|
+
then someone can run it with:
|
52
|
+
|
53
|
+
boca-golf <your gist url> boca-golf-problems/sanitize/spec.rb
|
54
|
+
|
55
|
+
== Create your own problems!
|
56
|
+
|
57
|
+
Simply create an rspec examples file, decide on what coders should
|
58
|
+
name the method, and call it!
|
59
|
+
|
60
|
+
in my_spec.rb:
|
61
|
+
|
62
|
+
describe "reverse" do
|
63
|
+
it "reverses the string" do
|
64
|
+
reverse("foo").should == "oof"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
then:
|
69
|
+
|
70
|
+
boca-golf solution.rb my_spec.rb
|
71
|
+
|
72
|
+
And send your problems in and we'll give you credit in the boca-golf-problems
|
73
|
+
repo!
|
74
|
+
|
75
|
+
Happy Golfing!
|
76
|
+
|
77
|
+
== Security
|
78
|
+
|
79
|
+
boca-golf runs all code from potential solutions at $SAFE = 4, so you
|
80
|
+
don't need to worry about someone's gist wrecking your system. That
|
81
|
+
being said, we are not liable for any damage caused to your system by
|
82
|
+
untrusted code. Always run untrusted code at your own risk.
|
83
|
+
|
84
|
+
Problem definitions, on the other hand, are run at $SAFE = 0, so you
|
85
|
+
can access any part of ruby you want within the RSpec examples you
|
86
|
+
write for your problems. That also means you should be sure you trust
|
87
|
+
whomever is defining the problems you're running with boca-golf.
|
88
|
+
|
data/boca-golf.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["david@flipstone.com"]
|
11
11
|
s.homepage = "https://github.com/flipstone/boca-golf"
|
12
12
|
s.summary = %q{A simple rspec-based engine for playing ruby golf coding problems}
|
13
|
-
s.description = %q{boca-golf
|
13
|
+
s.description = %q{boca-golf securely loads and runs code from the filesystem or a gist url,
|
14
14
|
execute a user-specified set of rspec examples against it, and also print of the score
|
15
15
|
(# number of charaters - lower == better!). It was built for playing ruby golf at the
|
16
16
|
Boca Ruby Meetup sessions.
|
@@ -3,6 +3,14 @@ class BocaGolf
|
|
3
3
|
def run(args, stdout, stderr)
|
4
4
|
::Rspec::Core::Runner.disable_autorun!
|
5
5
|
|
6
|
+
if args.size > 1
|
7
|
+
run_with_checked_args args, stdout, stderr
|
8
|
+
else
|
9
|
+
show_usage stdout, stderr
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def run_with_checked_args(args, stdout, stderr)
|
6
14
|
gist_location, *specs = *args
|
7
15
|
stdout.puts "Testing #{gist_location} against specs:"
|
8
16
|
specs.each do |spec|
|
@@ -16,6 +24,12 @@ class BocaGolf
|
|
16
24
|
stdout.puts result.gist.code
|
17
25
|
stdout.puts "\nScore:"
|
18
26
|
stdout.puts result.score
|
27
|
+
rescue => e
|
28
|
+
stderr.puts e.message
|
29
|
+
end
|
30
|
+
|
31
|
+
def show_usage(stdout, stderr)
|
32
|
+
stderr.puts "Usage: boca-golf file_or_gist_url spec_file ..."
|
19
33
|
end
|
20
34
|
end
|
21
35
|
end
|
data/lib/boca_golf/version.rb
CHANGED
data/spec/command_line_spec.rb
CHANGED
@@ -24,4 +24,22 @@ def reverse\(a\) a.reverse; end
|
|
24
24
|
Score:
|
25
25
|
29|
|
26
26
|
end
|
27
|
+
|
28
|
+
it "prints usage when not enough arguments are supplied" do
|
29
|
+
stdout, stderr = StringIO.new, StringIO.new
|
30
|
+
sandboxed do
|
31
|
+
BocaGolf::CommandLine.new.run([], stdout, stderr)
|
32
|
+
end
|
33
|
+
|
34
|
+
stderr.string.should =~ %r{Usage: boca-golf file_or_gist_url spec_file \.\.\.}
|
35
|
+
end
|
36
|
+
|
37
|
+
it "prints useful error when file does not exist" do
|
38
|
+
stdout, stderr = StringIO.new, StringIO.new
|
39
|
+
sandboxed do
|
40
|
+
BocaGolf::CommandLine.new.run(["boca-golf-foobar.rb", "spec/infrastructure/reverse_specs/spec.rb"], stdout, stderr)
|
41
|
+
end
|
42
|
+
|
43
|
+
stderr.string.should =~ %r{No such file or directory - boca-golf-foobar.rb}
|
44
|
+
end
|
27
45
|
end
|
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
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Vollbracht
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-08 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
21
|
-
description: "boca-golf
|
21
|
+
description: "boca-golf securely loads and runs code from the filesystem or a gist url,\n\
|
22
22
|
execute a user-specified set of rspec examples against it, and also print of the score\n\
|
23
23
|
(# number of charaters - lower == better!). It was built for playing ruby golf at the\n\
|
24
24
|
Boca Ruby Meetup sessions.\n "
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- .gitignore
|
35
35
|
- Gemfile
|
36
36
|
- Gemfile.lock
|
37
|
+
- README.rdoc
|
37
38
|
- Rakefile
|
38
39
|
- bin/boca-golf
|
39
40
|
- boca-golf.gemspec
|