Skip to content
Browse files

Implement CLI

  • Loading branch information...
1 parent 159dff0 commit 0df3d665e563f55ef6b71ddd179aa114eed43c3c @radar committed Jun 27, 2012
Showing with 86 additions and 5 deletions.
  1. +6 −1 bin/mdv
  2. +74 −0 features/cli.feature
  3. +1 −0 features/support/env.rb
  4. +1 −0 manning-docbook-validator.gemspec
  5. +4 −4 spec/validator_spec.rb
View
7 bin/mdv
@@ -16,6 +16,11 @@ end
if validator.errors.empty?
green("Chapter is valid!")
else
- red("There were #{validator.errors.count} errors.")
+ validator.errors.each_with_index do |error, i|
+ puts "#{i+1}. #{error}"
+ end
+ count = validator.errors.count
+ word = count == 1 ? "error" : "errors"
+ red("#{count} #{word} encountered.")
end
View
74 features/cli.feature
@@ -0,0 +1,74 @@
+Feature: MDV CLI
+
+ Scenario: Reports duplicated id attributes
+ Given a file named "ch01.xml" with:
+ """
+ <chapter>
+ <para id='ch01_1'>content</para>
+ <para id='ch01_1'>other content</para>
+ <para id='ch01_1'>more content</para>
+ </chapter>
+ """
+ When I run `mdv ch01.xml`
+ Then the output should contain:
+ """
+ 1. Line #3 - Duplicate id located: ch01_1. First seen on line #2.
+ 2. Line #4 - Duplicate id located: ch01_1. First seen on line #2.
+ """
+ And the output should contain:
+ """
+ 2 errors encountered.
+ """
+
+ Scenario: Reports listing lines over 72 characters:
+ Given a file named "ch01.xml" with:
+ """
+ <chapter>
+ <informalexample id='ch01_1'>
+ <programlisting>
+73 stars.
+*************************************************************************
+ </programlisting>
+ </informalexample>
+
+ <example id='ch01_2'>
+ <programlisting>
+73 stars.
+*************************************************************************
+ </programlisting>
+ </example>
+
+ <informalexample id='ch01_3'>
+ <programlisting>
+72 stars.
+************************************************************************
+ </programlisting>
+ </informalexample>
+
+ <example id='ch01_4'>
+ <programlisting>
+72 stars.
+************************************************************************
+ </programlisting>
+ </example>
+
+ <example id='ch01_5'>
+ <programlisting>
+72 stars. With callout.
+************************************************************************ <co id='ch01_5_1' />
+************************************************************************
+ </programlisting>
+ </example>
+ </chapter>
+ """
+
+ When I run `mdv ch01.xml`
+ Then the output should contain:
+ """
+ 1. Line #2 - Code on line 3 of informalexample#ch01_1 is too long. Line limit is 72 characters.
+ 2. Line #9 - Code on line 3 of example#ch01_2 is too long. Line limit is 72 characters.
+ """
+ And the output should contain:
+ """
+ 2 errors encountered.
+ """
View
1 features/support/env.rb
@@ -0,0 +1 @@
+require 'aruba/cucumber'
View
1 manning-docbook-validator.gemspec
@@ -17,5 +17,6 @@ Gem::Specification.new do |gem|
gem.add_dependency 'nokogiri', '~> 1.5.5'
gem.add_development_dependency 'rspec', '~> 2.10'
+ gem.add_development_dependency 'aruba', '0.4.11'
end
View
8 spec/validator_spec.rb
@@ -30,8 +30,8 @@
specify do
validator.errors.count.should == 2
- validator.errors[0].message.should == "Line #4 - Duplicate id located: ch01_1. First seen on line #3."
- validator.errors[1].message.should == "Line #5 - Duplicate id located: ch01_1. First seen on line #3."
+ validator.errors[0].should == "Line #4 - Duplicate id located: ch01_1. First seen on line #3."
+ validator.errors[1].should == "Line #5 - Duplicate id located: ch01_1. First seen on line #3."
end
end
@@ -95,8 +95,8 @@
specify do
validator.errors.count.should == 2
- validator.errors[0].message.should == "Line #3 - Code on line 1 of informalexample#ch01_1 is too long. Line limit is 72 characters."
- validator.errors[1].message.should == "Line #6 - Code on line 1 of example#ch01_2 is too long. Line limit is 72 characters."
+ validator.errors[0].should == "Line #3 - Code on line 1 of informalexample#ch01_1 is too long. Line limit is 72 characters."
+ validator.errors[1].should == "Line #6 - Code on line 1 of example#ch01_2 is too long. Line limit is 72 characters."
end

0 comments on commit 0df3d66

Please sign in to comment.
Something went wrong with that request. Please try again.