redrum 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/redrum CHANGED
@@ -1,2 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
+ require File.expand_path("../../lib/redrum", __FILE__)
2
3
 
4
+ Redrum.start
@@ -0,0 +1,15 @@
1
+ Feature: Command Line Interface
2
+ In order to use redrum from the command line
3
+ As a web designer
4
+ I want to be able to use redrum from the command line and have a little help there
5
+
6
+ Scenario: Starting redrum to create a project called MyBlog
7
+ Given there is no directory already existing at "MyBlog"
8
+ When I start redrum with "MyBlog"
9
+ Then I want to get a skeleton project at "MyBlog"
10
+ And I want to see what is beeing created from the command line
11
+
12
+ Scenario: Starting redrum with the -h or --help option
13
+ When I start redrum with "-h" or "--help"
14
+ Then I should be informed about its usage
15
+ And I should be informed about any options avaliable
data/lib/redrum.rb CHANGED
@@ -3,3 +3,5 @@
3
3
 
4
4
  require File.expand_path("../redrum/skeleton", __FILE__)
5
5
  require File.expand_path("../redrum/redrum", __FILE__)
6
+ require File.expand_path("../redrum/cli", __FILE__)
7
+
data/lib/redrum/cli.rb ADDED
@@ -0,0 +1,33 @@
1
+ require "optparse"
2
+
3
+ module Redrum
4
+ class CLI
5
+ def initialize(project, params={})
6
+ params = {:output_to => STDOUT}.merge params
7
+ @skeleton = Skeleton.new(project, params)
8
+ rescue Errno::EEXIST => e
9
+ params[:output_to].puts e.to_s
10
+ end
11
+
12
+ def self.parse(out=STDOUT)
13
+ options = {}
14
+ opt = OptionParser.new do |opts|
15
+ opts.banner = "Usage: redrum project_name [options]"
16
+ opts.on("-h", "--help", "You are reading it right now") do
17
+ out.puts opts
18
+ return false
19
+ end
20
+ opts.on_tail do
21
+ out.puts opts
22
+ end
23
+ end
24
+
25
+ opt.parse!
26
+ options
27
+ rescue OptionParser::InvalidOption => e
28
+ out.puts e.to_s
29
+ out.puts opt.to_s
30
+ false
31
+ end
32
+ end
33
+ end
data/lib/redrum/redrum.rb CHANGED
@@ -8,4 +8,14 @@ module Redrum
8
8
  def self.folder_structure
9
9
  FOLDER_STRUCTURE
10
10
  end
11
+
12
+ def self.start(out=STDOUT)
13
+ project = ARGV[0]
14
+ if (ARGV.size == 1) and (ARGV[0] =~ /^[^-].+/)
15
+ Redrum::CLI.new(project, :output_to => out) if project
16
+ elsif options = Redrum::CLI.parse(out)
17
+ options = { :output_to => out }.merge options
18
+ Redrum::CLI.new(project, options) if project
19
+ end
20
+ end
11
21
  end
@@ -1,9 +1,12 @@
1
1
  module Redrum
2
2
  class Skeleton
3
- def initialize(project_dir)
3
+ def initialize(project_dir, params={})
4
4
  Dir.mkdir(project_dir)
5
+ params[:output_to].puts "Creating " + project_dir if params[:output_to]
5
6
  FOLDER_STRUCTURE.each do |dir|
6
- Dir.mkdir(project_dir + "/" + dir)
7
+ new_folder = project_dir + "/" + dir
8
+ Dir.mkdir(new_folder)
9
+ params[:output_to].puts "Creating " + new_folder if params[:output_to]
7
10
  end
8
11
  end
9
12
  end
@@ -0,0 +1,68 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ describe Redrum::CLI do
4
+ describe "#new" do
5
+ it "creates a new Redrum::Skeleton instance" do
6
+ Redrum::Skeleton.should_receive(:new).with("temp", {:output_to => STDOUT})
7
+ Redrum::CLI.new("temp")
8
+ end
9
+
10
+ it "catches an error raised by Redrum::Skeleton.new if a directory already exists" do
11
+ messenger = StringIO.new
12
+ Redrum::CLI.new("temp", :output_to => messenger)
13
+ messenger.should_receive(:puts).with("File exists - temp")
14
+ Redrum::CLI.new("temp", :output_to => messenger)
15
+ end
16
+ end
17
+
18
+ describe "#self.parse" do
19
+ before do
20
+ no_warnings { ARGV = [] }
21
+ @messenger = StringIO.new
22
+ end
23
+
24
+ context "with valid parameters in ARGV" do
25
+ it "returns a hash with the options" do
26
+ no_warnings { ARGV = ["hmm"] }
27
+ Redrum::CLI.parse(@messenger).should be_kind_of(Hash)
28
+ end
29
+ end
30
+
31
+ context "with invalid parameters in ARGV" do
32
+ before do
33
+ no_warnings { ARGV = ["temp", "--crap"] }
34
+ end
35
+
36
+ it "shows an error message" do
37
+ Redrum::CLI.parse(@messenger)
38
+ @messenger.string.should include('invalid option: --crap')
39
+ end
40
+
41
+ it "shows the help text" do
42
+ Redrum::CLI.parse(@messenger)
43
+ @messenger.string.should include("Usage: redrum project_name [options]")
44
+ end
45
+ end
46
+
47
+ context "with no parameters" do
48
+ it "shows the help page" do
49
+ Redrum::CLI.parse(@messenger)
50
+ @messenger.string.should include("Usage: redrum project_name [options]")
51
+ end
52
+ end
53
+
54
+ context "with -h, --help" do
55
+ before { no_warnings { ARGV = ["-h"] } }
56
+
57
+ it "returns false" do
58
+ Redrum::CLI.parse(@messenger).should == false
59
+ end
60
+
61
+ it "shows the help text" do
62
+ Redrum::CLI.parse(@messenger)
63
+ @messenger.string.should include("Usage: redrum project_name [options]")
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -1,7 +1,11 @@
1
1
  require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  describe Redrum do
4
- before { @target = "temp" }
4
+ before do
5
+ @target = "temp"
6
+ ARGV.stub(:[]) { @target }
7
+ @messenger = StringIO.new
8
+ end
5
9
 
6
10
  describe "#self.make" do
7
11
  it "wraps the Redrum::Skeleton.new call" do
@@ -16,4 +20,32 @@ describe Redrum do
16
20
  Redrum.folder_structure.should include("public", "haml", "public/css")
17
21
  end
18
22
  end
23
+
24
+ describe "#self.start" do
25
+ before { Dir.stub(:mkdir) }
26
+
27
+ it "wraps Redrum::CLI.new" do
28
+ Redrum::CLI.should_receive(:new)
29
+ Redrum.start(@messenger)
30
+ end
31
+
32
+ it "calls Redrum::CLI.parse when there seem to be parameters to parse" do
33
+ Redrum::CLI.should_receive(:parse)
34
+ Redrum::CLI.stub(:new)
35
+ Redrum.start(@messenger)
36
+ end
37
+
38
+ it "does not show the help page when a project name is defined without parameters" do
39
+ no_warnings { ARGV = [ @target ] }
40
+ Redrum.start(@messenger)
41
+ @messenger.string.should include("Creating #{@target}")
42
+ @messenger.string.should_not include("Usage: redrum project_name")
43
+ end
44
+
45
+ it "does not call Redrum::CLI.new if no project name was given" do
46
+ ARGV.stub(:[]) { }
47
+ Redrum::CLI.should_not_receive(:new)
48
+ Redrum.start(@messenger)
49
+ end
50
+ end
19
51
  end
@@ -1,7 +1,12 @@
1
1
  require File.expand_path("../../spec_helper", __FILE__)
2
2
 
3
3
  describe Redrum::Skeleton do
4
- before { @target = "temp" }
4
+ before do
5
+ @target = "temp"
6
+ FileUtils.rm_rf(@target) rescue nil
7
+ end
8
+
9
+ after(:all) { FileUtils.rm_rf("temp") rescue nil }
5
10
 
6
11
  context "#new" do
7
12
  it "creates a new project folder at the target" do
@@ -15,5 +20,20 @@ describe Redrum::Skeleton do
15
20
  end
16
21
  Redrum::Skeleton.new(@target)
17
22
  end
23
+
24
+ it "informs us what folders it creates, if params[:output_to] is defined" do
25
+ STDOUT.as_null_object.should_receive(:puts).with("Creating temp")
26
+ Redrum::Skeleton.new(@target, :output_to => STDOUT)
27
+ end
28
+
29
+ it "does not print what it creates if params[:output_to] is not defined" do
30
+ STDOUT.as_null_object.should_not_receive(:puts).with("Creating temp")
31
+ Redrum::Skeleton.new(@target)
32
+ end
33
+
34
+ it "does raise an error if a directory with the projects name already exists" do
35
+ Redrum::Skeleton.new(@target)
36
+ lambda { Redrum::Skeleton.new(@target) }.should raise_error(Errno::EEXIST)
37
+ end
18
38
  end
19
39
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,11 @@
1
1
  require File.expand_path( "../../lib/redrum", __FILE__ )
2
+ require "fileutils"
3
+ require "stringio"
4
+
5
+ def no_warnings
6
+ verbosity = $VERBOSE
7
+ $VERBOSE = nil
8
+ result = yield
9
+ $VERBOSE = verbosity
10
+ result
11
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redrum
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - !binary |
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-10-26 00:00:00 +02:00
20
+ date: 2010-10-28 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -43,13 +43,16 @@ extensions: []
43
43
  extra_rdoc_files: []
44
44
 
45
45
  files:
46
+ - lib/redrum/cli.rb
46
47
  - lib/redrum/redrum.rb
47
48
  - lib/redrum/skeleton.rb
48
49
  - lib/redrum.rb
50
+ - spec/redrum/cli_spec.rb
49
51
  - spec/redrum/redrum_spec.rb
50
52
  - spec/redrum/skeleton_spec.rb
51
53
  - spec/spec_helper.rb
52
54
  - bin/redrum
55
+ - features/command_line_interface.feature
53
56
  - features/create_folder_skeleton.feature
54
57
  has_rdoc: true
55
58
  homepage: http://darkno.de