exercism 0.0.11 → 0.0.12

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzA3Zjk0ZWU3OTU1ZTBmOWRiYTJmZTU4OGYzZjYzYjUxM2M1NTI5Zg==
4
+ MDQ3ODlmYjQ4NWZhMDY4NjE1OGY2NjI1YzhhNWJjOTY5MjU2N2M0OA==
5
5
  data.tar.gz: !binary |-
6
- N2MwN2FlOGEzMjhiYmE2YjQyMzIxNTE0OWE3NDdhZjIzODVlMDhkOQ==
6
+ ZWJhZmIzMWJiYWViZTRiYjA5NTgyNjFjOWQ3ZjVlOTkxYmNiNzQ5MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzI3N2EzYzA1YjE5YzAwYjI0NDNkZmMzNTBjZGZkMTMzODdhMjIyMDMzMDQ3
10
- ODUzMWIzZTM1ZjM0YTI3OTg1ZGU3ZmQ3NDUyMGQ2NWE3MTliNGFmMzBhOTY5
11
- MzViNjk3YmU5NmEzZjZiY2QzM2RiMzlkNzAyOWUwNjAwNTMxMDA=
9
+ ZjNhMTUwNWRlMzY2NDJhMjg0ZDg2ZWNjMTVmOTk5N2ZiYmUzYmM1ODYxN2I2
10
+ NjgyZjg5MjU1NDc5M2Q1OTEyMTQzOTc1OGM5YmY5YjcyMGRjZGExMGUxZDY1
11
+ MTNiYWQ5MzY5Y2E5YjYxOTBkMjgyMTZjYTYwY2YxMjZlMTJiNzc=
12
12
  data.tar.gz: !binary |-
13
- MmFmNjcyZGI5YTVlOGY3ZDMzNGVhYjBjNmRhM2EzMWI5ZmY3M2ZhYmY2OGYw
14
- MDkwODk1ODZhNjU2ZWE2ZTJkMTA0YzcyOWM5N2JkZGI3MGRkMjcxYThiYThj
15
- MmNlNzIxYjlkOGIxYmI3ZGIxODdkZDlkMzdlY2NmNjYyZTRhMzg=
13
+ NDQwOWNmYTUyYmJmOWM2ZDEyOGU1MjczZTE1NDdjMjcxZjUxMDQ5ZTI3MWUz
14
+ ZjFiOTcxM2Y3MjUxMzgxODBiNjAzN2VhZjI4ZGI2ZDQzN2ZlN2I5Yjg4NzYw
15
+ NzNmMmM3ZDc4ZDM5MTEzODRkM2JhM2ZjMGVlMjNjMDQ1YjJjMTE=
data/lib/cli.rb CHANGED
@@ -19,6 +19,22 @@ class Exercism
19
19
  end
20
20
  end
21
21
 
22
+ desc "peek", "Fetch upcoming assignment from exercism.io"
23
+ method_option :host, aliases: '-h', default: 'http://exercism.io', desc: 'the url of the exercism application'
24
+ def peek
25
+ require 'exercism'
26
+
27
+ api = Exercism::Api.new(options[:host], Exercism.user, Exercism.project_dir)
28
+ assignments = api.peek
29
+ if assignments.empty?
30
+ puts "No assignments fetched."
31
+ else
32
+ assignments.each do |assignment|
33
+ puts "Fetched #{File.join(assignment.assignment_dir)}"
34
+ end
35
+ end
36
+ end
37
+
22
38
  desc "submit FILE", "Submit code to exercism.io on your current assignment"
23
39
  method_option :host, aliases: '-h', default: 'http://exercism.io', desc: 'the url of the exercism application'
24
40
  def submit(file)
data/lib/exercism/api.rb CHANGED
@@ -16,25 +16,48 @@ class Exercism
16
16
 
17
17
  def fetch
18
18
  response = conn.get do |req|
19
- req.url '/api/v1/user/assignments/current'
20
- req.headers['User-Agent'] = "exercism-CLI v#{Exercism::VERSION}"
19
+ req.url endpoint('current')
20
+ req.headers['User-Agent'] = user_agent
21
21
  req.params['key'] = user.key
22
22
  end
23
- Assignment.save(JSON.parse(response.body), project_dir)
23
+ save response.body
24
+ end
25
+
26
+ def peek
27
+ response = conn.get do |req|
28
+ req.url endpoint('next')
29
+ req.headers['User-Agent'] = user_agent
30
+ req.params['key'] = user.key
31
+ end
32
+ save response.body
24
33
  end
25
34
 
26
35
  def submit(filename)
27
36
  path = File.join(filename)
28
37
  contents = File.read path
29
38
  response = conn.post do |req|
30
- req.url '/api/v1/user/assignments'
39
+ req.url endpoint
31
40
  req.headers['Accept'] = 'application/json'
32
41
  req.headers['Content-Type'] = 'application/json'
33
- req.headers['User-Agent'] = "exercism-CLI v#{Exercism::VERSION}"
42
+ req.headers['User-Agent'] = user_agent
34
43
  req.body = {code: contents, key: user.key, path: path}.to_json
35
44
  end
36
45
  response
37
46
  end
47
+
48
+ private
49
+
50
+ def user_agent
51
+ "exercism-CLI v#{Exercism::VERSION}"
52
+ end
53
+
54
+ def endpoint(action = nil)
55
+ "/api/v1/user/assignments/#{action}".chomp('/')
56
+ end
57
+
58
+ def save(body)
59
+ Assignment.save(JSON.parse(body), project_dir)
60
+ end
38
61
  end
39
62
  end
40
63
 
@@ -1,3 +1,3 @@
1
1
  class Exercism
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -44,6 +44,21 @@ class ApiTest < MiniTest::Unit::TestCase
44
44
  end
45
45
  end
46
46
 
47
+ def test_fetch_upcoming_assignment_from_api
48
+ assignment_dir = File.join(project_dir, 'ruby', 'word-count')
49
+ readme_path = File.join(assignment_dir, 'README.md')
50
+ tests_path = File.join(assignment_dir, 'test.rb')
51
+
52
+ Exercism.stub(:home, home) do
53
+ VCR.use_cassette('alice-gets-word-count') do
54
+ Exercism::Api.new('http://localhost:4567', Exercism.user, project_dir).peek
55
+
56
+ Approvals.verify(File.read(readme_path), name: 'alice_gets_word_count_readme')
57
+ Approvals.verify(File.read(tests_path), name: 'alice_gets_word_count_tests')
58
+ end
59
+ end
60
+ end
61
+
47
62
  def test_send_assignment_to_api
48
63
  assignment_dir = File.join(project_dir, 'ruby', 'bob')
49
64
  FileUtils.mkdir_p(assignment_dir)
@@ -0,0 +1,17 @@
1
+ # Word Count
2
+
3
+ Write a program that given a string can count the occurrences of each word in that string.
4
+
5
+
6
+ ```ruby
7
+ words = Words.new("olly olly in come free")
8
+ words.count
9
+ # => {"olly" => 2, "in" => 1, "come" => 1, "free" => 1}
10
+ ```
11
+
12
+
13
+
14
+
15
+ ## Source
16
+
17
+ The golang tour [view source](http://tour.golang.org)
@@ -0,0 +1,49 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require_relative 'words'
4
+
5
+ class WordsTest < MiniTest::Unit::TestCase
6
+
7
+ def test_count_one_word
8
+ words = Words.new("word")
9
+ counts = {"word" => 1}
10
+ assert_equal counts, words.count
11
+ end
12
+
13
+ def test_count_one_of_each
14
+ skip
15
+ words = Words.new("one of each")
16
+ counts = {"one" => 1, "of" => 1, "each" => 1}
17
+ assert_equal counts, words.count
18
+ end
19
+
20
+ def test_count_multiple_occurrences
21
+ skip
22
+ words = Words.new("one fish two fish red fish blue fish")
23
+ counts = {"one"=>1, "fish"=>4, "two"=>1, "red"=>1, "blue"=>1}
24
+ assert_equal counts, words.count
25
+ end
26
+
27
+ def test_ignore_punctuation
28
+ skip
29
+ words = Words.new("car : carpet as java : javascript!!&@$%^&")
30
+ counts = {"car"=>1, "carpet"=>1, "as"=>1, "java"=>1, "javascript"=>1}
31
+ assert_equal counts, words.count
32
+ end
33
+
34
+ def test_include_numbers
35
+ skip
36
+ words = Words.new("testing, 1, 2 testing")
37
+ counts = {"testing" => 2, "1" => 1, "2" => 1}
38
+ assert_equal counts, words.count
39
+ end
40
+
41
+ def test_normalize_case
42
+ skip
43
+ words = Words.new("go Go GO")
44
+ counts = {"go" => 3}
45
+ assert_equal counts, words.count
46
+ end
47
+
48
+ end
49
+
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:4567/api/v1/user/assignments/next?key=634abfb095ed621e1c793c9875fcd9fda455ea90
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ user-agent:
11
+ - exercism-CLI v0.0.11
12
+ accept-encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ content-type:
22
+ - text/html;charset=utf-8
23
+ x-xss-protection:
24
+ - 1; mode=block
25
+ x-content-type-options:
26
+ - nosniff
27
+ x-frame-options:
28
+ - SAMEORIGIN
29
+ set-cookie:
30
+ - rack.session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRiJFNGI5Mjk5MGIzZTRhNTg4ZTFhYjk3%0AMTEwMWQxNjFmYWYzZWU0Y2YzNWEwN2NkMGEwZjg2NTlhODhhN2UyZGVkN0ki%0ADXRyYWNraW5nBjsARnsISSIUSFRUUF9VU0VSX0FHRU5UBjsARiItMGRiNzNi%0AZmE2YTU2YTE5ZjBjNGVhMTZiMDI3NThjMDUyMDAwNTZjZEkiGUhUVFBfQUND%0ARVBUX0VOQ09ESU5HBjsARiItZGRkMDk4OTE3NGYxOWE1YjE4NzkxMjEzY2M0%0AMGM1YTYwOWQyNTQ2Y0kiGUhUVFBfQUNDRVBUX0xBTkdVQUdFBjsARiItZGEz%0AOWEzZWU1ZTZiNGIwZDMyNTViZmVmOTU2MDE4OTBhZmQ4MDcwOQ%3D%3D%0A--caf0bdcef72ce7876eda1635779b4e98e6cf1e73;
31
+ path=/; HttpOnly
32
+ connection:
33
+ - close
34
+ content-length:
35
+ - '1704'
36
+ body:
37
+ encoding: US-ASCII
38
+ string: ! '{"assignments":[{"track":"ruby","slug":"word-count","readme":"# Word
39
+ Count\n\nWrite a program that given a string can count the occurrences of
40
+ each word in that string.\n\n\n```ruby\nwords = Words.new(\"olly olly in come
41
+ free\")\nwords.count\n# => {\"olly\" => 2, \"in\" => 1, \"come\" => 1, \"free\"
42
+ => 1}\n```\n\n\n\n\n## Source\n\nThe golang tour [view source](http://tour.golang.org)\n","test_file":"test.rb","tests":"require
43
+ ''minitest/autorun''\nrequire ''minitest/pride''\nrequire_relative ''words''\n\nclass
44
+ WordsTest < MiniTest::Unit::TestCase\n\n def test_count_one_word\n words
45
+ = Words.new(\"word\")\n counts = {\"word\" => 1}\n assert_equal counts,
46
+ words.count\n end\n\n def test_count_one_of_each\n skip\n words =
47
+ Words.new(\"one of each\")\n counts = {\"one\" => 1, \"of\" => 1, \"each\"
48
+ => 1}\n assert_equal counts, words.count\n end\n\n def test_count_multiple_occurrences\n skip\n words
49
+ = Words.new(\"one fish two fish red fish blue fish\")\n counts = {\"one\"=>1,
50
+ \"fish\"=>4, \"two\"=>1, \"red\"=>1, \"blue\"=>1}\n assert_equal counts,
51
+ words.count\n end\n\n def test_ignore_punctuation\n skip\n words =
52
+ Words.new(\"car : carpet as java : javascript!!&@$%^&\")\n counts = {\"car\"=>1,
53
+ \"carpet\"=>1, \"as\"=>1, \"java\"=>1, \"javascript\"=>1}\n assert_equal
54
+ counts, words.count\n end\n\n def test_include_numbers\n skip\n words
55
+ = Words.new(\"testing, 1, 2 testing\")\n counts = {\"testing\" => 2, \"1\"
56
+ => 1, \"2\" => 1}\n assert_equal counts, words.count\n end\n\n def test_normalize_case\n skip\n words
57
+ = Words.new(\"go Go GO\")\n counts = {\"go\" => 3}\n assert_equal counts,
58
+ words.count\n end\n\nend\n\n"}]}'
59
+ http_version: '1.1'
60
+ recorded_at: Fri, 21 Jun 2013 14:57:00 GMT
61
+ recorded_with: VCR 2.5.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exercism
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Owen
@@ -151,8 +151,11 @@ files:
151
151
  - test/exercism_test.rb
152
152
  - test/fixtures/approvals/alice_gets_bob_readme.approved.txt
153
153
  - test/fixtures/approvals/alice_gets_bob_tests.approved.txt
154
+ - test/fixtures/approvals/alice_gets_word_count_readme.approved.txt
155
+ - test/fixtures/approvals/alice_gets_word_count_tests.approved.txt
154
156
  - test/fixtures/home/.exercism
155
157
  - test/fixtures/vcr_cassettes/alice-gets-bob.yml
158
+ - test/fixtures/vcr_cassettes/alice-gets-word-count.yml
156
159
  - test/fixtures/vcr_cassettes/alice-submits-bob.yml
157
160
  - test/test_helper.rb
158
161
  homepage: ''
@@ -187,8 +190,11 @@ test_files:
187
190
  - test/exercism_test.rb
188
191
  - test/fixtures/approvals/alice_gets_bob_readme.approved.txt
189
192
  - test/fixtures/approvals/alice_gets_bob_tests.approved.txt
193
+ - test/fixtures/approvals/alice_gets_word_count_readme.approved.txt
194
+ - test/fixtures/approvals/alice_gets_word_count_tests.approved.txt
190
195
  - test/fixtures/home/.exercism
191
196
  - test/fixtures/vcr_cassettes/alice-gets-bob.yml
197
+ - test/fixtures/vcr_cassettes/alice-gets-word-count.yml
192
198
  - test/fixtures/vcr_cassettes/alice-submits-bob.yml
193
199
  - test/test_helper.rb
194
200
  has_rdoc: