bloc 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/bloc CHANGED
@@ -5,7 +5,7 @@ require "bloc"
5
5
 
6
6
  commands = {
7
7
  # user commands
8
- 'authenticate' => proc { Bloc::Command::Authenticate.run },
8
+ 'authenticate' => proc { Bloc::Command::Authenticate.run },
9
9
  'tasks' => proc { Bloc::Command::Tasks.run },
10
10
 
11
11
  # author commands
@@ -3,24 +3,22 @@ module Bloc::Command
3
3
  USAGE = <<eos
4
4
  Usage:
5
5
 
6
- bloc add-chapter <"name"> <"markdown"> <"command">
6
+ bloc add-chapter ["name"]
7
7
 
8
8
  Example:
9
9
 
10
- bloc add-chapter "Stacks and Queues" "markdown/chapter4.md" "rspec spec -t ch4 -f j"
10
+ bloc add-chapter "Stacks and Queues"
11
11
  eos
12
12
  def self.run(*args)
13
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
-
14
+ raise USAGE unless ARGV.size == 2
15
+ name = ARGV[1]
19
16
  manifest = Bloc::Manifest.parse
17
+ number = manifest.chapters.size + 1
20
18
  manifest.add_chapter(
21
19
  :name => name,
22
- :markdown => markdown,
23
- :command => command
20
+ :markdown => "chapters/chapter#{number}.md",
21
+ :command => ""
24
22
  )
25
23
  end
26
24
  end
@@ -1,9 +1,46 @@
1
+ require "colorize"
2
+
1
3
  module Bloc
2
4
  module Command
3
5
  class Tasks
4
6
  module Formatter
5
- def self.format(results)
6
- results.to_yaml
7
+ def self.format(tests)
8
+ output = ""
9
+ tests.each_with_index do |test, index|
10
+ if test["passed"]
11
+ output << format_passed(test, index)
12
+ else
13
+ output << format_failed(test, index)
14
+ end
15
+ end
16
+
17
+ output
18
+ end
19
+
20
+ def self.format_passed(test, index)
21
+ %Q(
22
+ #{index+1}. #{indent(test["name"].green)}
23
+ #{indent(test["description"])}
24
+ )
25
+ end
26
+
27
+ def self.format_failed(test, index)
28
+ %Q(
29
+ #{index+1}. #{indent(test["name"].red)}
30
+ #{indent(test["description"])}
31
+ #{indent(test["failed_line"])}
32
+ #{indent(test["backtrace"].join("\n"))}
33
+
34
+ #{indent(test["code"].light_cyan)}
35
+ #{indent(test["stdout"])}
36
+ )
37
+ end
38
+
39
+ def self.indent(text, options={})
40
+ tab_level = options[:level] || 1
41
+ tabs = "\t"*tab_level
42
+ lines = text.split("\n")
43
+ lines.map {|line| tabs + line }.join("\n")
7
44
  end
8
45
  end
9
46
  end
@@ -1,22 +1,40 @@
1
1
  module Bloc
2
2
  module Command
3
3
  class Validate
4
- NO_DEFAULT_COURSE_FILE = "No default file for course specified (OK)".green
5
- VALID_DEFAULT_COURSE_FILE = "Default file for course exists (OK)".green
4
+ LESSON_NOT_SPECIFIED = "No markdown was specified for: '%s'".red
5
+ LESSON_NOT_FOUND = "Missing markdown file: %s".red
6
+ LESSON_EXISTS = "(OK) Markdown exists: %s".green
7
+ NO_DEFAULT_COURSE_FILE = "(OK) No default file for course specified".green
8
+ VALID_DEFAULT_COURSE_FILE = "(OK) Default file for course exists".green
6
9
  INVALID_DEFAULT_COURSE_FILE = "Default file for course does not exist (expected %s)".red
7
- NO_DEFAULT_CHAPTER_FILE = "No default file for chapter specified (OK): %s".green
8
- VALID_DEFAULT_CHAPTER_FILE = "Default file for chapter exists (OK): %s".green
10
+ NO_DEFAULT_CHAPTER_FILE = "(OK) No default file for chapter specified: %s".green
11
+ VALID_DEFAULT_CHAPTER_FILE = "(OK) Default file for chapter exists: %s".green
9
12
  INVALID_DEFAULT_CHAPTER_FILE = "Default file for chapter does not exist: %s (expected %s)".red
10
13
  NO_SUCH_PATCH = "Patch not found: %s".red
11
- PATCH_EXISTS = "Patch exists: %s".green
14
+ PATCH_EXISTS = "(OK) Patch exists: %s".green
12
15
 
13
16
  def self.run(*args)
14
- manifest = Manifest.parse
17
+ manifest = Bloc::Manifest.parse
18
+ check_markdown_files manifest
15
19
  check_course_default_file manifest
16
20
  check_chapter_default_files manifest
17
21
  check_patches manifest
18
22
  end
19
23
 
24
+ def self.check_markdown_files(manifest)
25
+ manifest.chapters.each do |chapter|
26
+ begin
27
+ if File.exists?("bloc/#{chapter.markdown}")
28
+ puts LESSON_EXISTS % chapter.markdown
29
+ else
30
+ raise LESSON_NOT_FOUND % chapter.markdown
31
+ end
32
+ rescue NoMethodError => e
33
+ raise LESSON_NOT_SPECIFIED % chapter.name
34
+ end
35
+ end
36
+ end
37
+
20
38
  def self.check_course_default_file(manifest)
21
39
  course_default_file = manifest.course.default_file
22
40
  if course_default_file.nil?
@@ -1,3 +1,3 @@
1
1
  module Bloc
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -11,24 +11,38 @@ module Bloc::Command
11
11
  },
12
12
  :chapters => []
13
13
  }
14
+ $verbose = $VERBOSE
15
+ $VERBOSE = nil
16
+ $argv = ARGV
17
+ ARGV = ['add-chapter', 'stacks and queues']
18
+ end
19
+
20
+ after do
21
+ ARGV = $argv
22
+ $VERBOSE = $verbose
14
23
  end
15
24
 
16
25
  it "raises an exception if a manifest doesn't exist" do
17
- lambda { AddChapter.run() }.should raise_error(Bloc::Manifest::MANIFEST_NOT_FOUND)
26
+ FakeFS do
27
+ lambda { AddChapter.run() }.should raise_error(Bloc::Manifest::MANIFEST_NOT_FOUND)
28
+ end
18
29
  end
19
30
 
20
31
  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)
32
+ FakeFS do
33
+ $tmp = ARGV
34
+ ARGV = ['add-chapter']
35
+ Bloc::Manifest.new(@options).write
36
+ lambda { AddChapter.run() }.should raise_error(AddChapter::USAGE)
37
+ ARGV = $tmp
38
+ end
23
39
  end
24
40
 
25
41
  it "adds a chapter to an existing manifest" do
26
42
  FakeFS do
27
-
28
43
  manifest = Bloc::Manifest.new(@options)
29
44
  manifest.write
30
45
  chapter_count = manifest.chapters.size
31
- ARGV = ['stacks and queues', 'markdown/chapter4.md', 'rspec spec -t ch4 -f j']
32
46
  AddChapter.run
33
47
  Bloc::Manifest.parse.chapters.size.should be(chapter_count + 1)
34
48
  end
@@ -8,7 +8,7 @@ module Bloc
8
8
  let(:enrollment) { Client::Enrollment.new("id" => 1, "current_step" => 1, "completed" => false) }
9
9
  let(:course) { Client::Course.new({"id" => "1", "slug" => "url-shortener" }) }
10
10
  let(:git_remote) { "git://github.com/Bloc/URL-Shortener.git" }
11
- let(:passed_results) { { "tests" => [{"passed" => true }, { "passed" => true }] } }
11
+ let(:passed_results) { { "tests" => [{"passed" => true }, { "passed" => true }] } }
12
12
  let(:failed_results) { { "tests" => [{"passed" => false }, { "passed" => true }] } }
13
13
 
14
14
  before do
@@ -23,6 +23,7 @@ module Bloc
23
23
  Runner.stub(:run).and_return(failed_results)
24
24
 
25
25
  $stdout = StringIO.new
26
+ Command::Tasks::Formatter.stub(:format)
26
27
  end
27
28
 
28
29
  after do
@@ -36,7 +37,7 @@ module Bloc
36
37
  end
37
38
 
38
39
  context "if the tests pass" do
39
- before do
40
+ before do
40
41
  Runner.stub(:run).and_return(passed_results)
41
42
  Client::Course.stub(:find).with(:scaffold_clone_url => git_remote).and_return(course)
42
43
  Client::Enrollment.stub(:create).with(:course_id => course.id).and_return(enrollment)
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.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-10 00:00:00.000000000Z
13
+ date: 2012-03-13 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &70272016576460 !ruby/object:Gem::Requirement
17
+ requirement: &70329855606340 !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: *70272016576460
25
+ version_requirements: *70329855606340
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: fakefs
28
- requirement: &70272016576040 !ruby/object:Gem::Requirement
28
+ requirement: &70329855605920 !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: *70272016576040
36
+ version_requirements: *70329855605920
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: ruby-debug19
39
- requirement: &70272016575620 !ruby/object:Gem::Requirement
39
+ requirement: &70329855605500 !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: *70272016575620
47
+ version_requirements: *70329855605500
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: json
50
- requirement: &70272016575200 !ruby/object:Gem::Requirement
50
+ requirement: &70329855605080 !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: *70272016575200
58
+ version_requirements: *70329855605080
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: colorize
61
- requirement: &70272016574780 !ruby/object:Gem::Requirement
61
+ requirement: &70329855604660 !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: *70272016574780
69
+ version_requirements: *70329855604660
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rest-client
72
- requirement: &70272016574360 !ruby/object:Gem::Requirement
72
+ requirement: &70329855604240 !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: *70272016574360
80
+ version_requirements: *70329855604240
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: hashie
83
- requirement: &70272016573940 !ruby/object:Gem::Requirement
83
+ requirement: &70329855603820 !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: *70272016573940
91
+ version_requirements: *70329855603820
92
92
  description: A command-line tool for Bloc
93
93
  email:
94
94
  - roshan.choxi@gmail.com