bloc 0.1.0 → 0.1.1
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.
- data/CHANGELOG.md +11 -0
- data/Makefile +2 -0
- data/bin/bloc +16 -6
- data/lib/bloc/command.rb +2 -0
- data/lib/bloc/command/add_chapter.rb +27 -0
- data/lib/bloc/command/create.rb +21 -0
- data/lib/bloc/manifest.rb +5 -0
- data/lib/bloc/version.rb +1 -1
- data/spec/command/add_chapter_spec.rb +37 -0
- data/spec/command/create_spec.rb +29 -0
- data/spec/command/tasks_spec.rb +6 -2
- data/spec/command/validate_spec.rb +17 -11
- data/spec/manifest_spec.rb +21 -0
- data/spec/spec_helper.rb +4 -0
- metadata +22 -15
data/CHANGELOG.md
CHANGED
data/Makefile
ADDED
data/bin/bloc
CHANGED
@@ -4,10 +4,15 @@ require "rubygems"
|
|
4
4
|
require "bloc"
|
5
5
|
|
6
6
|
commands = {
|
7
|
+
# user commands
|
8
|
+
'authenticate' => proc { Bloc::Command::Authenticate.run },
|
9
|
+
'tasks' => proc { Bloc::Command::Tasks.run },
|
10
|
+
|
11
|
+
# author commands
|
7
12
|
'validate' => proc { Bloc::Command::Validate.run },
|
8
13
|
'test' => proc { Bloc::Command::Test.run },
|
9
|
-
'
|
10
|
-
'
|
14
|
+
'create' => proc { Bloc::Command::Create.run },
|
15
|
+
'add-chapter' => proc { Bloc::Command::AddChapter.run },
|
11
16
|
}
|
12
17
|
|
13
18
|
if commands.keys.include?(ARGV.first.downcase)
|
@@ -21,12 +26,17 @@ else
|
|
21
26
|
Usage:
|
22
27
|
bloc <command> [options]
|
23
28
|
|
24
|
-
Commands:
|
29
|
+
User Commands:
|
30
|
+
authenticate Authenticate by entering your Bloc email and password
|
31
|
+
tasks Run the tasks for your current chapter
|
32
|
+
|
33
|
+
Author Commands:
|
25
34
|
validate Attempt to parse the manifest and check for the existence of default files
|
26
|
-
create["Course name"] Create a course manifest with the specified name prefilled
|
27
35
|
test [chapter-number] If chapter number is specified, run tests for that chapter. If not, run all tests in order.
|
28
|
-
|
29
|
-
|
36
|
+
create ["Course name"] Create a course manifest with the specified name
|
37
|
+
add-chapter <"name"> <"markdown"> <"command">
|
38
|
+
Add a chapter with the specified attributes
|
39
|
+
|
30
40
|
eos
|
31
41
|
puts helpstring
|
32
42
|
end
|
data/lib/bloc/command.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Bloc::Command
|
2
|
+
class AddChapter
|
3
|
+
USAGE = <<eos
|
4
|
+
Usage:
|
5
|
+
|
6
|
+
bloc add-chapter <"name"> <"markdown"> <"command">
|
7
|
+
|
8
|
+
Example:
|
9
|
+
|
10
|
+
bloc add-chapter "Stacks and Queues" "markdown/chapter4.md" "rspec spec -t ch4 -f j"
|
11
|
+
eos
|
12
|
+
def self.run(*args)
|
13
|
+
raise Bloc::Manifest::MANIFEST_NOT_FOUND unless File.exists?(Bloc::Manifest::MANIFEST_PATH)
|
14
|
+
raise USAGE unless ARGV.size == 3
|
15
|
+
name = ARGV[1] || "New Chapter"
|
16
|
+
markdown = ARGV[2] || ""
|
17
|
+
command = ARGV[3] || ""
|
18
|
+
|
19
|
+
manifest = Bloc::Manifest.parse
|
20
|
+
manifest.add_chapter(
|
21
|
+
:name => name,
|
22
|
+
:markdown => markdown,
|
23
|
+
:command => command
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Bloc
|
2
|
+
module Command
|
3
|
+
class Create
|
4
|
+
MANIFEST_ALREADY_EXISTS = "Found existing bloc manifest, remove and re-run command.".red
|
5
|
+
|
6
|
+
def self.run(*args)
|
7
|
+
raise MANIFEST_ALREADY_EXISTS if File.exists?(Bloc::Manifest::MANIFEST_PATH)
|
8
|
+
name = ARGV[1] || "My Bloc Course"
|
9
|
+
manifest = {
|
10
|
+
:course => {
|
11
|
+
:name => name,
|
12
|
+
:description => ""
|
13
|
+
},
|
14
|
+
:chapters => []
|
15
|
+
}
|
16
|
+
|
17
|
+
Bloc::Manifest.new(manifest).write
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/bloc/manifest.rb
CHANGED
data/lib/bloc/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
require 'fakefs/safe'
|
3
|
+
|
4
|
+
module Bloc::Command
|
5
|
+
describe AddChapter do
|
6
|
+
before do
|
7
|
+
@options = {
|
8
|
+
:course => {
|
9
|
+
:name => "foobar",
|
10
|
+
:description => "foobar"
|
11
|
+
},
|
12
|
+
:chapters => []
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "raises an exception if a manifest doesn't exist" do
|
17
|
+
lambda { AddChapter.run() }.should raise_error(Bloc::Manifest::MANIFEST_NOT_FOUND)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "raises and exception if not all arguments are passed" do
|
21
|
+
Bloc::Manifest.new(@options).write
|
22
|
+
lambda { AddChapter.run() }.should raise_error(AddChapter::USAGE)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "adds a chapter to an existing manifest" do
|
26
|
+
FakeFS do
|
27
|
+
|
28
|
+
manifest = Bloc::Manifest.new(@options)
|
29
|
+
manifest.write
|
30
|
+
chapter_count = manifest.chapters.size
|
31
|
+
ARGV = ['stacks and queues', 'markdown/chapter4.md', 'rspec spec -t ch4 -f j']
|
32
|
+
AddChapter.run
|
33
|
+
Bloc::Manifest.parse.chapters.size.should be(chapter_count + 1)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
require 'fakefs/safe'
|
3
|
+
|
4
|
+
module Bloc::Command
|
5
|
+
describe Create do
|
6
|
+
it "writes a valid bloc manifest" do
|
7
|
+
FakeFS do
|
8
|
+
Create.run()
|
9
|
+
lambda { Bloc::Manifest.parse }.should_not raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises an exception if a manifest already exists", :wip => true do
|
14
|
+
FakeFS do
|
15
|
+
manifest = {
|
16
|
+
:course => {
|
17
|
+
:name => "Fobar",
|
18
|
+
:description => "foobar"
|
19
|
+
},
|
20
|
+
:chapters => []
|
21
|
+
}
|
22
|
+
|
23
|
+
Bloc::Manifest.new(manifest).write
|
24
|
+
File.exists?(Bloc::Manifest::MANIFEST_PATH).should be(true)
|
25
|
+
lambda { Create.run() }.should raise_error(Create::MANIFEST_ALREADY_EXISTS)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/command/tasks_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "./spec/spec_helper"
|
2
2
|
require "stringio"
|
3
|
-
require "fakefs"
|
3
|
+
require "fakefs/safe"
|
4
4
|
|
5
5
|
module Bloc
|
6
6
|
describe Bloc::Command::Tasks do
|
@@ -12,6 +12,7 @@ module Bloc
|
|
12
12
|
let(:failed_results) { { "tests" => [{"passed" => false }, { "passed" => true }] } }
|
13
13
|
|
14
14
|
before do
|
15
|
+
FakeFS.activate!
|
15
16
|
FileUtils.mkdir_p(File.dirname(Manifest::MANIFEST_PATH))
|
16
17
|
File.open(Manifest::MANIFEST_PATH, "w+") do |f|
|
17
18
|
f << %Q({"course": {"name" : "CatNap"}, "chapters": [{ "command": "whatever" }, {"command": "stuff"}]})
|
@@ -24,7 +25,10 @@ module Bloc
|
|
24
25
|
$stdout = StringIO.new
|
25
26
|
end
|
26
27
|
|
27
|
-
after
|
28
|
+
after do
|
29
|
+
$stdout = STDOUT
|
30
|
+
FakeFS.deactivate!
|
31
|
+
end
|
28
32
|
|
29
33
|
it "runs the tasks command for the current chapter" do
|
30
34
|
Runner.should_receive(:run).with("whatever")
|
@@ -1,23 +1,28 @@
|
|
1
1
|
require "./spec/spec_helper"
|
2
|
-
require "fakefs"
|
2
|
+
require "fakefs/safe"
|
3
3
|
require "stringio"
|
4
4
|
|
5
5
|
module Bloc::Command
|
6
6
|
describe Validate do
|
7
7
|
it "raises an exception if the Bloc manifest can not be found" do
|
8
|
-
|
8
|
+
FakeFS do
|
9
|
+
lambda { Validate.run() }.should raise_error(Bloc::Manifest::MANIFEST_NOT_FOUND)
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
13
|
it "raises an exception if the Bloc manifest has invalid JSON" do
|
12
|
-
|
13
|
-
|
14
|
+
FakeFS do
|
15
|
+
FileUtils.mkdir_p("bloc")
|
16
|
+
File.open(Bloc::Manifest::MANIFEST_PATH, 'w+') {|f| f.write "<<invalid json>>" }
|
14
17
|
|
15
|
-
|
18
|
+
lambda { Validate.run() }.should raise_error(Bloc::Manifest::INVALID_MANIFEST)
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
it "prints a success message if the manifest is valid" do
|
19
|
-
|
20
|
-
|
23
|
+
FakeFS do
|
24
|
+
FileUtils.mkdir_p("bloc")
|
25
|
+
File.open(Bloc::Manifest::MANIFEST_PATH, 'w+') {|f| f.write <<-eos
|
21
26
|
{
|
22
27
|
"course": {
|
23
28
|
"name": "Foobar",
|
@@ -28,10 +33,11 @@ module Bloc::Command
|
|
28
33
|
eos
|
29
34
|
}
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
out = StringIO.new
|
37
|
+
$stdout = out
|
38
|
+
Validate.run()
|
39
|
+
$stdout = STDOUT
|
40
|
+
end
|
35
41
|
end
|
36
42
|
end
|
37
43
|
end
|
data/spec/manifest_spec.rb
CHANGED
@@ -3,6 +3,15 @@ require 'fakefs/safe'
|
|
3
3
|
|
4
4
|
module Bloc
|
5
5
|
describe Manifest do
|
6
|
+
before do
|
7
|
+
@options = {
|
8
|
+
:course => {
|
9
|
+
:name => "foobar",
|
10
|
+
:description => "foobar"
|
11
|
+
},
|
12
|
+
:chapters => []
|
13
|
+
}
|
14
|
+
end
|
6
15
|
it "writes valid JSON" do
|
7
16
|
FakeFS do
|
8
17
|
Bloc::Manifest.new(@options).write
|
@@ -35,5 +44,17 @@ module Bloc
|
|
35
44
|
manifest = Bloc::Manifest.new(@options)
|
36
45
|
manifest.to_hash.class.should be(Hash)
|
37
46
|
end
|
47
|
+
|
48
|
+
it "adds chapters correctly" do
|
49
|
+
FakeFS do
|
50
|
+
manifest = Bloc::Manifest.new(@options)
|
51
|
+
manifest.write
|
52
|
+
original_size = manifest.chapters.size
|
53
|
+
|
54
|
+
manifest.add_chapter(:name => "", :markdown => "", :command => "")
|
55
|
+
manifest.write
|
56
|
+
Bloc::Manifest.parse.chapters.size.should be(original_size + 1)
|
57
|
+
end
|
58
|
+
end
|
38
59
|
end
|
39
60
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
$:.push File.expand_path("../lib", __FILE__)
|
2
2
|
|
3
3
|
require "bloc"
|
4
|
+
require "fakefs/safe"
|
4
5
|
|
5
6
|
module Helpers
|
6
7
|
# Replace standard input with faked one StringIO.
|
@@ -18,4 +19,7 @@ end
|
|
18
19
|
|
19
20
|
RSpec.configure do |conf|
|
20
21
|
conf.include(Helpers)
|
22
|
+
conf.after do
|
23
|
+
FakeFS::FileSystem.clear
|
24
|
+
end
|
21
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bloc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-03-10 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70272016576460 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70272016576460
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: fakefs
|
28
|
-
requirement: &
|
28
|
+
requirement: &70272016576040 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70272016576040
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: ruby-debug19
|
39
|
-
requirement: &
|
39
|
+
requirement: &70272016575620 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70272016575620
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: json
|
50
|
-
requirement: &
|
50
|
+
requirement: &70272016575200 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70272016575200
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: colorize
|
61
|
-
requirement: &
|
61
|
+
requirement: &70272016574780 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70272016574780
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rest-client
|
72
|
-
requirement: &
|
72
|
+
requirement: &70272016574360 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70272016574360
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: hashie
|
83
|
-
requirement: &
|
83
|
+
requirement: &70272016573940 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :runtime
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70272016573940
|
92
92
|
description: A command-line tool for Bloc
|
93
93
|
email:
|
94
94
|
- roshan.choxi@gmail.com
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- .rvmrc
|
103
103
|
- CHANGELOG.md
|
104
104
|
- Gemfile
|
105
|
+
- Makefile
|
105
106
|
- README.md
|
106
107
|
- Rakefile
|
107
108
|
- bin/bloc
|
@@ -112,7 +113,9 @@ files:
|
|
112
113
|
- lib/bloc/client/course.rb
|
113
114
|
- lib/bloc/client/enrollment.rb
|
114
115
|
- lib/bloc/command.rb
|
116
|
+
- lib/bloc/command/add_chapter.rb
|
115
117
|
- lib/bloc/command/authenticate.rb
|
118
|
+
- lib/bloc/command/create.rb
|
116
119
|
- lib/bloc/command/tasks.rb
|
117
120
|
- lib/bloc/command/tasks/formatter.rb
|
118
121
|
- lib/bloc/command/test.rb
|
@@ -126,7 +129,9 @@ files:
|
|
126
129
|
- spec/client/authenticate_spec.rb
|
127
130
|
- spec/client/course_spec.rb
|
128
131
|
- spec/client/enrollment_spec.rb
|
132
|
+
- spec/command/add_chapter_spec.rb
|
129
133
|
- spec/command/authenticate_spec.rb
|
134
|
+
- spec/command/create_spec.rb
|
130
135
|
- spec/command/tasks_spec.rb
|
131
136
|
- spec/command/validate_spec.rb
|
132
137
|
- spec/manifest_spec.rb
|
@@ -160,7 +165,9 @@ test_files:
|
|
160
165
|
- spec/client/authenticate_spec.rb
|
161
166
|
- spec/client/course_spec.rb
|
162
167
|
- spec/client/enrollment_spec.rb
|
168
|
+
- spec/command/add_chapter_spec.rb
|
163
169
|
- spec/command/authenticate_spec.rb
|
170
|
+
- spec/command/create_spec.rb
|
164
171
|
- spec/command/tasks_spec.rb
|
165
172
|
- spec/command/validate_spec.rb
|
166
173
|
- spec/manifest_spec.rb
|