Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Error #45

Merged
merged 3 commits into from

2 participants

@EmilyVoukelatos

I started addressing issue 7 using exceptions. So this commit :

  • Fixes issue 7 #7
  • Adds cucumber features for issue 7
  • Adds exception classes
  • Bypasses thor banner in order to avoid duplicate code
@dathompson
Collaborator

When I ran the new cucumber tests @usage-error scenarios were causing the later Build scenarios to fail, I think because they clobbered the test_book build. I moved the @usage-error scenarios to the end and it seemed to fix the problem. We could simply add @no-clobber to each of the new scenarios, but I was thinking that it might read more easily if we put error handling toward the end. What do you think?

Nice work!

@EmilyVoukelatos

Yeah sure! :)

@dathompson dathompson merged commit 0f3262b into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 1, 2012
  1. Added exceptions and fixed generator error/usage messages

    Stratos Voukelatos authored
Commits on May 2, 2012
  1. Added bookshop usage-error features

    Stratos Voukelatos authored
  2. Fixed usage-error features breaking other features

    Stratos Voukelatos authored
This page is out of date. Refresh to see the latest.
View
15 features/bookshop.feature
@@ -22,8 +22,8 @@ Feature: We can create a new book project and build books
| builds/html |
| builds/pdf |
| builds/mobi |
-
- @no-clobber
+
+ @no-clobber
Scenario: Build a new pdf book
Given a file named "test_book/script/bookshop" should exist
When I cd to "test_book"
@@ -92,4 +92,13 @@ Feature: We can create a new book project and build books
| builds/mobi/book.mobi |
And the file "builds/mobi/OEBPS/book.html" should match /stylesheet.mobi.css/
And the file "builds/mobi/OEBPS/content.opf" should match /stylesheet.mobi.css/
-
+
+
+ @usage-error
+ Scenario: Run bookshop without arguments
+ When I run `bookshop`
+ Then the output should contain "Usage:\n bookshop new BOOK_NAME [options]"
+ @usage-error
+ Scenario: Run bookshop new without path
+ When I run `bookshop new`
+ Then the output should contain "Usage:\n bookshop new BOOK_NAME [options]"
View
8 lib/bookshop.rb
@@ -1,4 +1,5 @@
require 'rbconfig'
+require 'bookshop/error'
require 'bookshop/script_bookshop_loader'
# If we are inside a Bookshop project this method performs an exec and thus
@@ -10,5 +11,8 @@
require 'bookshop/ruby_version_check'
Signal.trap("INT") { puts; exit }
-
-require 'bookshop/commands/application'
+begin
+require 'bookshop/commands/application'
+rescue Bookshop::Error => e
+ puts e.message
+end
View
22 lib/bookshop/error.rb
@@ -0,0 +1,22 @@
+
+module Bookshop
+
+ class Error< StandardError
+
+ end
+
+ class ArgumentsError< Error
+
+ def to_s
+ " bookshop new BOOK_NAME [options]"
+ end
+
+ end
+
+ class GeneratorArgumentsError < ArgumentsError
+ def to_s
+ "Usage:\n" + super
+ end
+ end
+
+end
View
50 lib/bookshop/generators/bookshop/app/app_generator.rb
@@ -9,38 +9,42 @@ class AppGenerator < Thor::Group
include Thor::Actions
# Define arguments and options
- argument :app_path, :type => :string
+ argument :app_path, :optional=> true, :type => :string
# Define source root of application
def self.source_root
File.dirname(__FILE__)
end
- # Create the project from templates
- def create_base_project
- puts "creating base project"
- directory "templates", "#{app_path}"
- end
-
- # Adds third-party tools
- # def add_tools
- # directory "tools/", "#{app_path}/tools/"
- # end
-
- #Change the permissions so tools are executable
- def chmod_tools
- chmod "#{app_path}/script/epubcheck/epubcheck.jar", 0755
- chmod "#{app_path}/script/epubcheck/lib/jing.jar", 0755
- chmod "#{app_path}/script/epubcheck/lib/saxon.jar", 0755
- chmod "#{app_path}/script/kindlegen/kindlegen.exe", 0755
- chmod "#{app_path}/script/kindlegen/kindlegen_mac", 0755
- chmod "#{app_path}/script/kindlegen/kindlegen_linux", 0755
- end
-
+
+ # Create the project from templates
+ def create_base_project
+ raise GeneratorArgumentsError if app_path.nil?
+ puts "creating base project"
+ directory "templates", "#{app_path}"
+ end
+
+ # Adds third-party tools
+ # def add_tools
+ # directory "tools/", "#{app_path}/tools/"
+ # end
+
+ #Change the permissions so tools are executable
+ def chmod_tools
+ chmod "#{app_path}/script/epubcheck/epubcheck.jar", 0755
+ chmod "#{app_path}/script/epubcheck/lib/jing.jar", 0755
+ chmod "#{app_path}/script/epubcheck/lib/saxon.jar", 0755
+ chmod "#{app_path}/script/kindlegen/kindlegen.exe", 0755
+ chmod "#{app_path}/script/kindlegen/kindlegen_mac", 0755
+ chmod "#{app_path}/script/kindlegen/kindlegen_linux", 0755
+ end
+
+
+
protected
def self.banner
- "bookshop new #{self.arguments.map(&:usage).join(' ')} [options]"
+ raise ArgumentsError
end
end
Something went wrong with that request. Please try again.