exercism 0.0.4 → 0.0.5
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.
- checksums.yaml +8 -8
- data/lib/cli.rb +15 -3
- data/lib/exercism.rb +10 -2
- data/lib/exercism/api.rb +3 -3
- data/lib/exercism/assignment.rb +11 -16
- data/lib/exercism/config.rb +11 -2
- data/lib/exercism/version.rb +1 -1
- data/test/exercism/api_test.rb +16 -16
- data/test/exercism/assignment_test.rb +7 -18
- data/test/exercism/config_test.rb +12 -2
- data/test/exercism_test.rb +2 -2
- data/test/fixtures/home/.exercism +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
M2U0NDc4ZmQ5NmI4NjJjNGQzYjY3YjUyMWQxZGM5ZDE4NWUxOGJiMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDYwYTkxYzkyNGRlN2I0YjVmYzIwYmNlMGQwZTgzYTY2MDY5OWJlNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2UwY2VmMjNiZDI4N2Y2MjM0YTE1Y2U3YjNlOWMwZThkYTViMzZiMTkyZTZl
|
10
|
+
NGViZWVkMDk2ZjY5NDg1NjE3MGIzZTU2NjYxYzc4ODQzZTMyNDllNzc0MGUw
|
11
|
+
OWY3ODgyN2ZkNTU3YmNkY2FhYjk1NmVkZjczMTJlYWEwZGQzZDQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Njg5NjM1Y2FkMGJkYjA1ZGM4ZWYwY2ZhNjhkNDdlOTQyYmZiOTVlZTJjZGU2
|
14
|
+
ZWUwZGM0MmQ2ZTViZWU2M2Y3OTZlMmJiYjBiODI3YWIwMjdkMjIxMTExN2Qw
|
15
|
+
NjU2YmI4OTFjOTNjNWY4YzkwOTQxZWQ0NTljZDRmYWY2MTYyNjQ=
|
data/lib/cli.rb
CHANGED
@@ -7,14 +7,21 @@ class Exercism
|
|
7
7
|
def fetch
|
8
8
|
require 'exercism'
|
9
9
|
|
10
|
-
Exercism::Api.fetch_for(Exercism.user)
|
10
|
+
assignments = Exercism::Api.fetch_for(Exercism.user, Exercism.project_dir)
|
11
|
+
if assignments.empty?
|
12
|
+
puts "No assignments fetched."
|
13
|
+
else
|
14
|
+
assignments.each do |assignment|
|
15
|
+
puts "Fetched #{File.join(assignment.assignment_dir)}"
|
16
|
+
end
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
20
|
desc "submit FILE", "Submit code to exercism.io on your current assignment"
|
14
21
|
def submit(file)
|
15
22
|
require 'exercism'
|
16
23
|
|
17
|
-
Exercism::Api.submit(file, {for: Exercism.user})
|
24
|
+
Exercism::Api.submit(File.join(FileUtils.pwd, file), {for: Exercism.user})
|
18
25
|
end
|
19
26
|
|
20
27
|
desc "login", "Save exercism.io api credentials"
|
@@ -23,7 +30,12 @@ class Exercism
|
|
23
30
|
|
24
31
|
username = ask("Your GitHub username:")
|
25
32
|
key = ask("Your exercism.io API key:")
|
26
|
-
|
33
|
+
default_path = FileUtils.pwd
|
34
|
+
path = ask("What is your exercism exercises project path? (#{default_path})")
|
35
|
+
if path.empty?
|
36
|
+
path = default_path
|
37
|
+
end
|
38
|
+
Exercism.login(username, key, path)
|
27
39
|
|
28
40
|
say("Your credentials have been written to #{Exercism.config.file}")
|
29
41
|
end
|
data/lib/exercism.rb
CHANGED
@@ -23,8 +23,12 @@ class Exercism
|
|
23
23
|
Dir.home(Etc.getlogin)
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.login(github_username, key)
|
27
|
-
data = {
|
26
|
+
def self.login(github_username, key, dir)
|
27
|
+
data = {
|
28
|
+
'github_username' => github_username,
|
29
|
+
'key' => key,
|
30
|
+
'project_dir' => dir
|
31
|
+
}
|
28
32
|
Config.write(home, data)
|
29
33
|
User.new(github_username, key)
|
30
34
|
end
|
@@ -38,4 +42,8 @@ class Exercism
|
|
38
42
|
User.new(c.github_username, c.key)
|
39
43
|
end
|
40
44
|
|
45
|
+
def self.project_dir
|
46
|
+
config.project_dir
|
47
|
+
end
|
48
|
+
|
41
49
|
end
|
data/lib/exercism/api.rb
CHANGED
@@ -6,18 +6,18 @@ class Exercism
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.fetch_for(user)
|
9
|
+
def self.fetch_for(user, path)
|
10
10
|
response = conn.get do |req|
|
11
11
|
req.url '/api/v1/user/assignments/current'
|
12
12
|
req.headers['User-Agent'] = "exercism-CLI v#{Exercism::VERSION}"
|
13
13
|
req.params['key'] = user.key
|
14
14
|
end
|
15
|
-
Assignment.save(JSON.parse(response.body))
|
15
|
+
Assignment.save(JSON.parse(response.body), path)
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.submit(filename, options)
|
19
19
|
user = options[:for]
|
20
|
-
path = File.join(
|
20
|
+
path = File.join(filename)
|
21
21
|
contents = File.read path
|
22
22
|
response = conn.post do |req|
|
23
23
|
req.url '/api/v1/user/assignments'
|
data/lib/exercism/assignment.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
class Exercism
|
2
2
|
class Assignment
|
3
3
|
|
4
|
-
def self.save(data)
|
4
|
+
def self.save(data, path)
|
5
|
+
assignments = []
|
5
6
|
data['assignments'].each do |attributes|
|
6
|
-
Assignment.new(attributes).save
|
7
|
+
assignments << Assignment.new(attributes.merge('project_dir' => path)).save
|
7
8
|
end
|
9
|
+
assignments
|
8
10
|
end
|
9
11
|
|
10
|
-
attr_reader :track, :slug, :readme, :test_file, :tests
|
12
|
+
attr_reader :track, :slug, :readme, :test_file, :tests, :project_dir
|
11
13
|
|
12
14
|
def initialize(attributes)
|
13
15
|
@track = attributes['track']
|
@@ -15,6 +17,7 @@ class Exercism
|
|
15
17
|
@readme = attributes['readme']
|
16
18
|
@test_file = attributes['test_file']
|
17
19
|
@tests = attributes['tests']
|
20
|
+
@project_dir = attributes['project_dir']
|
18
21
|
end
|
19
22
|
|
20
23
|
def save
|
@@ -23,6 +26,11 @@ class Exercism
|
|
23
26
|
f.write readme
|
24
27
|
end
|
25
28
|
File.write tests_path, tests
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def assignment_dir
|
33
|
+
@assignment_dir ||= File.join(project_dir, track, slug)
|
26
34
|
end
|
27
35
|
|
28
36
|
private
|
@@ -34,19 +42,6 @@ class Exercism
|
|
34
42
|
def tests_path
|
35
43
|
File.join(assignment_dir, test_file)
|
36
44
|
end
|
37
|
-
|
38
|
-
def assignment_dir
|
39
|
-
File.join(project_dir, track, slug)
|
40
|
-
end
|
41
|
-
|
42
|
-
def project_dir
|
43
|
-
dir = FileUtils.pwd
|
44
|
-
if File.basename(dir) == track
|
45
|
-
dir.gsub(/#{track}\z/, '')
|
46
|
-
else
|
47
|
-
dir
|
48
|
-
end
|
49
|
-
end
|
50
45
|
end
|
51
46
|
end
|
52
47
|
|
data/lib/exercism/config.rb
CHANGED
@@ -9,11 +9,12 @@ class Exercism
|
|
9
9
|
config = new(path)
|
10
10
|
config.github_username = data['github_username']
|
11
11
|
config.key = data['key']
|
12
|
+
config.project_dir = data['project_dir']
|
12
13
|
config.save
|
13
14
|
end
|
14
15
|
|
15
16
|
attr_reader :file
|
16
|
-
attr_writer :github_username, :key
|
17
|
+
attr_writer :github_username, :key, :project_dir
|
17
18
|
|
18
19
|
def initialize(path)
|
19
20
|
@file = File.join(path, '.exercism')
|
@@ -27,9 +28,17 @@ class Exercism
|
|
27
28
|
@key ||= from_yaml['key']
|
28
29
|
end
|
29
30
|
|
31
|
+
def project_dir
|
32
|
+
@project_dir ||= from_yaml['project_dir']
|
33
|
+
end
|
34
|
+
|
30
35
|
def save
|
31
36
|
File.open file, 'w' do |f|
|
32
|
-
data = {
|
37
|
+
data = {
|
38
|
+
'github_username' => github_username,
|
39
|
+
'key' => key,
|
40
|
+
'project_dir' => project_dir
|
41
|
+
}
|
33
42
|
f.write data.to_yaml
|
34
43
|
end
|
35
44
|
self
|
data/lib/exercism/version.rb
CHANGED
data/test/exercism/api_test.rb
CHANGED
@@ -16,25 +16,27 @@ end
|
|
16
16
|
|
17
17
|
class ApiTest < MiniTest::Unit::TestCase
|
18
18
|
|
19
|
-
def
|
20
|
-
|
19
|
+
def project_dir
|
20
|
+
'/tmp'
|
21
|
+
end
|
22
|
+
|
23
|
+
def home
|
24
|
+
'test/fixtures/home'
|
21
25
|
end
|
22
26
|
|
23
27
|
def teardown
|
24
|
-
FileUtils.
|
25
|
-
FileUtils.rm_rf File.join(
|
26
|
-
FileUtils.rm_rf File.join(@project_dir, 'test/fixtures/home/javascript')
|
28
|
+
FileUtils.rm_rf File.join(project_dir, 'ruby')
|
29
|
+
FileUtils.rm_rf File.join(project_dir, 'javascript')
|
27
30
|
end
|
28
31
|
|
29
32
|
def test_fetch_assignment_from_api
|
30
|
-
|
31
|
-
readme_path = File.join(
|
32
|
-
tests_path = File.join(
|
33
|
+
assignment_dir = File.join(project_dir, 'ruby', 'bob')
|
34
|
+
readme_path = File.join(assignment_dir, 'README.md')
|
35
|
+
tests_path = File.join(assignment_dir, 'test.rb')
|
33
36
|
|
34
37
|
Exercism.stub(:home, home) do
|
35
|
-
FileUtils.cd home
|
36
38
|
VCR.use_cassette('alice-gets-bob') do
|
37
|
-
Exercism::Api.fetch_for(Exercism.user)
|
39
|
+
Exercism::Api.fetch_for(Exercism.user, project_dir)
|
38
40
|
|
39
41
|
Approvals.verify(File.read(readme_path), name: 'alice_gets_bob_readme')
|
40
42
|
Approvals.verify(File.read(tests_path), name: 'alice_gets_bob_tests')
|
@@ -43,18 +45,16 @@ class ApiTest < MiniTest::Unit::TestCase
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def test_send_assignment_to_api
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
submission = File.join(assignment_path, 'bob.rb')
|
48
|
+
assignment_dir = File.join(project_dir, 'ruby', 'bob')
|
49
|
+
FileUtils.mkdir_p(assignment_dir)
|
50
|
+
submission = File.join(assignment_dir, 'bob.rb')
|
50
51
|
File.open(submission, 'w') do |f|
|
51
52
|
f.write "puts 'hello world'"
|
52
53
|
end
|
53
54
|
|
54
55
|
Exercism.stub(:home, home) do
|
55
|
-
FileUtils.cd assignment_path
|
56
56
|
VCR.use_cassette('alice-submits-bob') do
|
57
|
-
response = Exercism::Api.submit(
|
57
|
+
response = Exercism::Api.submit(submission, {for: Exercism.user})
|
58
58
|
assert_equal 201, response.status
|
59
59
|
end
|
60
60
|
end
|
@@ -2,21 +2,20 @@ require './test/test_helper'
|
|
2
2
|
|
3
3
|
class AssignmentTest < MiniTest::Unit::TestCase
|
4
4
|
|
5
|
-
def
|
6
|
-
|
5
|
+
def project_dir
|
6
|
+
'/tmp'
|
7
7
|
end
|
8
8
|
|
9
9
|
def teardown
|
10
|
-
FileUtils.
|
11
|
-
FileUtils.rm_rf File.join(@project_dir, 'test/fixtures/ruby')
|
10
|
+
FileUtils.rm_rf File.join(project_dir, 'ruby')
|
12
11
|
end
|
13
12
|
|
14
13
|
def readme_path
|
15
|
-
File.join(
|
14
|
+
File.join(project_dir, 'ruby', 'queens', 'README.md')
|
16
15
|
end
|
17
16
|
|
18
17
|
def tests_path
|
19
|
-
File.join(
|
18
|
+
File.join(project_dir, 'ruby', 'queens', 'test.rb')
|
20
19
|
end
|
21
20
|
|
22
21
|
def assignment_data
|
@@ -25,22 +24,12 @@ class AssignmentTest < MiniTest::Unit::TestCase
|
|
25
24
|
'slug' => 'queens',
|
26
25
|
'readme' => 'Do it',
|
27
26
|
'test_file' => 'test.rb',
|
28
|
-
'tests' => 'assert true'
|
27
|
+
'tests' => 'assert true',
|
28
|
+
'project_dir' => project_dir
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_write_assignment_from_project_directory
|
33
|
-
FileUtils.cd 'test/fixtures'
|
34
|
-
assignment = Exercism::Assignment.new(assignment_data)
|
35
|
-
assignment.save
|
36
|
-
|
37
|
-
assert_equal "Do it", File.read(readme_path)
|
38
|
-
assert_equal "assert true", File.read(tests_path)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_write_assignment_from_language_directory
|
42
|
-
FileUtils.mkdir File.join(@project_dir, 'test/fixtures/ruby')
|
43
|
-
FileUtils.cd 'test/fixtures/ruby'
|
44
33
|
assignment = Exercism::Assignment.new(assignment_data)
|
45
34
|
assignment.save
|
46
35
|
|
@@ -14,21 +14,31 @@ class ConfigTest < MiniTest::Unit::TestCase
|
|
14
14
|
config = Exercism::Config.read(path)
|
15
15
|
assert_equal 'alice', config.github_username
|
16
16
|
assert_equal key, config.key
|
17
|
+
assert_equal '/tmp', config.project_dir
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_write_config_file
|
20
21
|
path = './test/fixtures'
|
21
22
|
key = '7a7096c'
|
22
|
-
data = {
|
23
|
+
data = {
|
24
|
+
'github_username' => 'bob',
|
25
|
+
'key' => key,
|
26
|
+
'project_dir' => '/dev/null'
|
27
|
+
}
|
23
28
|
config = Exercism::Config.write(path, data)
|
24
29
|
assert_equal 'bob', config.github_username
|
25
30
|
assert_equal key, config.key
|
31
|
+
assert_equal '/dev/null', config.project_dir
|
26
32
|
end
|
27
33
|
|
28
34
|
def test_delete_config_file
|
29
35
|
path = './test/fixtures'
|
30
36
|
key = '7a7096c'
|
31
|
-
data = {
|
37
|
+
data = {
|
38
|
+
'github_username' => 'bob',
|
39
|
+
'key' => key,
|
40
|
+
'project_dir' => '/tmp'
|
41
|
+
}
|
32
42
|
config = Exercism::Config.write(path, data)
|
33
43
|
filename = config.file
|
34
44
|
config.delete
|
data/test/exercism_test.rb
CHANGED
@@ -20,7 +20,7 @@ class ExercismTest < MiniTest::Unit::TestCase
|
|
20
20
|
def test_login_gives_you_a_user
|
21
21
|
Exercism.stub(:home, './test/fixtures') do
|
22
22
|
key = '97e9975'
|
23
|
-
user = Exercism.login('bob', key)
|
23
|
+
user = Exercism.login('bob', key, '/dev/null')
|
24
24
|
assert_equal 'bob', user.github_username
|
25
25
|
assert_equal key, user.key
|
26
26
|
end
|
@@ -29,7 +29,7 @@ class ExercismTest < MiniTest::Unit::TestCase
|
|
29
29
|
def test_login_writes_the_config_file
|
30
30
|
Exercism.stub(:home, './test/fixtures') do
|
31
31
|
key = '97e9975'
|
32
|
-
Exercism.login('bob', key)
|
32
|
+
Exercism.login('bob', key, '/tmp')
|
33
33
|
user = Exercism.user
|
34
34
|
assert_equal 'bob', user.github_username
|
35
35
|
assert_equal key, user.key
|