et 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/et/api.rb +5 -5
- data/lib/et/challenge.rb +5 -4
- data/lib/et/config.rb +3 -1
- data/lib/et/runner.rb +1 -1
- data/lib/et/version.rb +1 -1
- data/spec/cli/list_challenges_spec.rb +3 -8
- data/spec/data/challenge.json +1 -0
- data/spec/data/challenges.json +1 -1
- data/spec/lib/api_spec.rb +19 -4
- data/spec/lib/challenge_spec.rb +5 -6
- data/spec/support/helpers/sample_files.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b39aed635bf95f14c089d17488dcde13d1a85ea2
|
4
|
+
data.tar.gz: 680174f609918e638266301b381d5ac5d74d8f84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efca6c830ff04b4be2414c83c062462a9d0d532c1b0621693d6f97f52f7d156b681421a3bf25ed0760a4548c0fa40ef36d0c21e6c151e8fb2f8026f6237bf72b
|
7
|
+
data.tar.gz: 5a52aa3f094bc58460a9834c7a2f09a004e834a53f0e580f344d71ddb538f7b168f029732921a2013fba2fa5235b76c29d71ea206c9c0993a240a161026fcd7e
|
data/lib/et/api.rb
CHANGED
@@ -15,13 +15,13 @@ module ET
|
|
15
15
|
|
16
16
|
def list_challenges
|
17
17
|
response = RestClient.get(challenges_url)
|
18
|
-
JSON.parse(response, symbolize_names: true)
|
18
|
+
JSON.parse(response, symbolize_names: true)[:lessons]
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_challenge(slug)
|
22
22
|
response = RestClient.get(challenge_url(slug))
|
23
23
|
body = JSON.parse(response, symbolize_names: true)
|
24
|
-
body[:
|
24
|
+
body[:lesson]
|
25
25
|
end
|
26
26
|
|
27
27
|
def download_file(url)
|
@@ -51,15 +51,15 @@ module ET
|
|
51
51
|
private
|
52
52
|
|
53
53
|
def challenge_url(slug)
|
54
|
-
URI.join(host, "
|
54
|
+
URI.join(host, "lessons/#{slug}.json").to_s
|
55
55
|
end
|
56
56
|
|
57
57
|
def challenges_url
|
58
|
-
URI.join(host, "
|
58
|
+
URI.join(host, "lessons.json?type=challenge").to_s
|
59
59
|
end
|
60
60
|
|
61
61
|
def submission_url(slug)
|
62
|
-
URI.join(host, "
|
62
|
+
URI.join(host, "lessons/#{slug}/submissions.json").to_s
|
63
63
|
end
|
64
64
|
|
65
65
|
def random_filename
|
data/lib/et/challenge.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "pathname"
|
1
2
|
require "securerandom"
|
2
3
|
|
3
4
|
module ET
|
@@ -43,13 +44,13 @@ module ET
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def ignored_files
|
46
|
-
(config["ignore"] || []) + [".
|
47
|
+
(config["ignore"] || []) + [".lesson.yml"]
|
47
48
|
end
|
48
49
|
|
49
50
|
private
|
50
51
|
|
51
52
|
def config
|
52
|
-
@config ||= YAML.load(File.read(File.join(dir, ".
|
53
|
+
@config ||= YAML.load(File.read(File.join(dir, ".lesson.yml")))
|
53
54
|
end
|
54
55
|
|
55
56
|
def random_archive_path
|
@@ -57,11 +58,11 @@ module ET
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def find_challenge_dir(current_dir)
|
60
|
-
path = File.join(current_dir, ".
|
61
|
+
path = File.join(current_dir, ".lesson.yml")
|
61
62
|
|
62
63
|
if File.exists?(path)
|
63
64
|
current_dir
|
64
|
-
elsif current_dir == "
|
65
|
+
elsif current_dir == "." || Pathname.new(current_dir).root?
|
65
66
|
nil
|
66
67
|
else
|
67
68
|
find_challenge_dir(File.dirname(current_dir))
|
data/lib/et/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
module ET
|
2
4
|
class Config
|
3
5
|
attr_reader :current_dir
|
@@ -50,7 +52,7 @@ module ET
|
|
50
52
|
|
51
53
|
if File.exists?(config_path)
|
52
54
|
config_path
|
53
|
-
elsif dir == "
|
55
|
+
elsif dir == "." || Pathname.new(dir).root?
|
54
56
|
nil
|
55
57
|
else
|
56
58
|
find_config_file(File.dirname(dir))
|
data/lib/et/runner.rb
CHANGED
@@ -40,7 +40,7 @@ module ET
|
|
40
40
|
desc "List available challenges."
|
41
41
|
command :list do |c|
|
42
42
|
c.action do |_global_options, _options, _cmdargs|
|
43
|
-
Formatter.print_table(api.list_challenges
|
43
|
+
Formatter.print_table(api.list_challenges, :slug, :title)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
data/lib/et/version.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
describe "list challenges" do
|
2
2
|
let(:sample_challenges) do
|
3
|
-
|
4
|
-
challenges: [
|
5
|
-
{ title: "Guess the Number", slug: "guess-the-number" },
|
6
|
-
{ title: "Blackjack", slug: "blackjack" }
|
7
|
-
]
|
8
|
-
}
|
3
|
+
JSON.parse(File.read("spec/data/challenges.json"), symbolize_names: true)[:lessons]
|
9
4
|
end
|
10
5
|
|
11
6
|
it "prints the titles and slug" do
|
@@ -23,8 +18,8 @@ describe "list challenges" do
|
|
23
18
|
expect(stdout).to include("Guess the Number")
|
24
19
|
expect(stdout).to include("guess-the-number")
|
25
20
|
|
26
|
-
expect(stdout).to include("
|
27
|
-
expect(stdout).to include("
|
21
|
+
expect(stdout).to include("Auto-Guesser")
|
22
|
+
expect(stdout).to include("auto-guesser")
|
28
23
|
end
|
29
24
|
end
|
30
25
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"lesson":{"slug":"rock-paper-scissors","title":"Rock, Paper, Scissors","body":"body goes here...","archive_url":"http://example.com/rock-paper-scissors.tar.gz"}}
|
data/spec/data/challenges.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"
|
1
|
+
{"lessons":[{"title":"Auto-Guesser","slug":"auto-guesser"},{"title":"Guess the Number","slug":"guess-the-number"}]}
|
data/spec/lib/api_spec.rb
CHANGED
@@ -8,14 +8,29 @@ describe ET::API do
|
|
8
8
|
|
9
9
|
it "queries for a list of challenges" do
|
10
10
|
expect(RestClient).to receive(:get).
|
11
|
-
with("http://localhost:3000/
|
11
|
+
with("http://localhost:3000/lessons.json?type=challenge").
|
12
12
|
and_return(challenges_response)
|
13
13
|
|
14
14
|
results = api.list_challenges
|
15
15
|
|
16
|
-
expect(results
|
17
|
-
expect(results[
|
18
|
-
expect(results[
|
16
|
+
expect(results.count).to eq(2)
|
17
|
+
expect(results[0][:title]).to eq("Auto-Guesser")
|
18
|
+
expect(results[0][:slug]).to eq("auto-guesser")
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:challenge_response) do
|
22
|
+
File.read("spec/data/challenge.json")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "queries for a single challenge" do
|
26
|
+
expect(RestClient).to receive(:get).
|
27
|
+
with("http://localhost:3000/lessons/rock-paper-scissors.json").
|
28
|
+
and_return(challenge_response)
|
29
|
+
|
30
|
+
result = api.get_challenge("rock-paper-scissors")
|
31
|
+
|
32
|
+
expect(result[:title]).to eq("Rock, Paper, Scissors")
|
33
|
+
expect(result[:archive_url]).to eq("http://example.com/rock-paper-scissors.tar.gz")
|
19
34
|
end
|
20
35
|
end
|
21
36
|
end
|
data/spec/lib/challenge_spec.rb
CHANGED
@@ -4,7 +4,6 @@ describe ET::Challenge do
|
|
4
4
|
let(:challenge_info) do
|
5
5
|
{
|
6
6
|
"title" => "Guess the Number",
|
7
|
-
"slug" => "guess-the-number",
|
8
7
|
"ignore" => ["README.md"]
|
9
8
|
}
|
10
9
|
end
|
@@ -12,7 +11,7 @@ describe ET::Challenge do
|
|
12
11
|
describe "#dir" do
|
13
12
|
it "selects the directory containing the challenge file" do
|
14
13
|
Dir.mktmpdir do |challenge_dir|
|
15
|
-
challenge_path = File.join(challenge_dir, ".
|
14
|
+
challenge_path = File.join(challenge_dir, ".lesson.yml")
|
16
15
|
File.write(challenge_path, challenge_info.to_yaml)
|
17
16
|
|
18
17
|
challenge = ET::Challenge.new(challenge_dir)
|
@@ -22,7 +21,7 @@ describe ET::Challenge do
|
|
22
21
|
|
23
22
|
it "checks parent directories for the challenge file" do
|
24
23
|
Dir.mktmpdir do |parent_dir|
|
25
|
-
challenge_path = File.join(parent_dir, ".
|
24
|
+
challenge_path = File.join(parent_dir, ".lesson.yml")
|
26
25
|
File.write(challenge_path, challenge_info.to_yaml)
|
27
26
|
|
28
27
|
child_dir = File.join(parent_dir, "foobar")
|
@@ -44,7 +43,7 @@ describe ET::Challenge do
|
|
44
43
|
|
45
44
|
begin
|
46
45
|
Dir.mktmpdir do |challenge_dir|
|
47
|
-
challenge_path = File.join(challenge_dir, ".
|
46
|
+
challenge_path = File.join(challenge_dir, ".lesson.yml")
|
48
47
|
File.write(challenge_path, challenge_info.to_yaml)
|
49
48
|
|
50
49
|
file_path = File.join(challenge_dir, "file.rb")
|
@@ -68,7 +67,7 @@ describe ET::Challenge do
|
|
68
67
|
|
69
68
|
begin
|
70
69
|
Dir.mktmpdir do |dir|
|
71
|
-
File.write(File.join(dir, ".
|
70
|
+
File.write(File.join(dir, ".lesson.yml"), challenge_info.to_yaml)
|
72
71
|
File.write(File.join(dir, "file.rb"), "2 + 2 == 5")
|
73
72
|
File.write(File.join(dir, "README.md"), "Ignore me!")
|
74
73
|
|
@@ -79,7 +78,7 @@ describe ET::Challenge do
|
|
79
78
|
|
80
79
|
expect(files).to include("./file.rb")
|
81
80
|
expect(files).to_not include("./README.md")
|
82
|
-
expect(files).to_not include("./.
|
81
|
+
expect(files).to_not include("./.lesson.yml")
|
83
82
|
end
|
84
83
|
ensure
|
85
84
|
if archive_path && File.exist?(archive_path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: et
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Sheehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- spec/cli/init_spec.rb
|
112
112
|
- spec/cli/list_challenges_spec.rb
|
113
113
|
- spec/cli/submit_challenge_spec.rb
|
114
|
+
- spec/data/challenge.json
|
114
115
|
- spec/data/challenges.json
|
115
116
|
- spec/data/some-challenge.tar.gz
|
116
117
|
- spec/lib/api_spec.rb
|