lucie-lib 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54cdab8b749d107f8e4623da10b409e84f9bc371
4
+ data.tar.gz: 6e6e80fd5c6f033f7e88e6196ba4ef5526b7ce5d
5
+ SHA512:
6
+ metadata.gz: c281e872db3d2a261d61822f1647bae06944a3abd902f1b35fe0a8034429fa36a4e6da99999a2e6a13ec9cbd89e2b0daff299123177e29677a1c5f9fca76d06c
7
+ data.tar.gz: cb0c5212712368ab0ab728e8f3cd2351ae9c55b659d05fe89f104c9a8ec35e31b8a2c9a0e3cebf3ef7177042a0e9ec3ec8e6aa20dfded83c0bb6c4ce0f1856ab
data/Rakefile CHANGED
@@ -4,8 +4,17 @@ require 'rake/testtask'
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << 'lib/lucie'
6
6
  t.libs << 'test'
7
- t.test_files = FileList['test/*/*_test.rb']
7
+ t.test_files = FileList['test/**/*_test.rb']
8
8
  t.verbose = false
9
9
  t.warning = true
10
10
  end
11
- task :default => :test
11
+ task :default => :test
12
+
13
+ if !ENV["TRAVIS"]
14
+ require 'rdoc/task'
15
+ RDoc::Task.new :doc do |rdoc|
16
+ rdoc.rdoc_dir = '../doc'
17
+ rdoc.options << '-f' << 'sdoc'
18
+ rdoc.rdoc_files.include("lib/*.rb")
19
+ end
20
+ end
data/lib/lucie/app.rb CHANGED
@@ -1,20 +1,45 @@
1
+
2
+
1
3
  module Lucie
4
+ # App responsible for configuring and launch the application
5
+ # based on Lucie application framework.
6
+ #
2
7
  class App
3
8
 
9
+ class << self
10
+ attr_accessor :raise_exception
11
+ attr_accessor :log_level
12
+ attr_accessor :root
13
+ @raise_exception = false
14
+ @log_level = :info
15
+ end
16
+
4
17
  attr_reader :command
5
18
  attr_reader :root
19
+ attr_reader :pwd
6
20
 
7
21
  def self.run(command = ARGV, root = nil)
8
- obj = self.new(command, root)
9
- obj.start
10
- obj.exit_value
22
+ root ||= File.expand_path("..", File.dirname(Kernel.caller[0]))
23
+ instance = self.init(command, root)
24
+ self.start(instance)
25
+ end
26
+
27
+ def self.init(command = ARGV, root = nil)
28
+ root ||= File.expand_path("..", File.dirname(Kernel.caller[0]))
29
+ self.new(command, root)
30
+ end
31
+
32
+ def self.start(instance)
33
+ instance.start
34
+ instance.exit_value
11
35
  end
12
36
 
13
37
  def initialize(command, root)
14
- self.root = root || File.expand_path("..", File.dirname(Kernel.caller[2]))
15
- self.command = command
38
+ @root = root
39
+ @command = CommandLineParser.new(command)
16
40
  @exit_value ||= 0
17
41
  @task = nil
42
+ @pwd = ENV["PWD"]
18
43
  end
19
44
 
20
45
  def start
@@ -25,11 +50,8 @@ module Lucie
25
50
  @exit_value
26
51
  end
27
52
 
28
- class << self
29
- attr_accessor :raise_exception
30
- attr_accessor :log_level
31
- @@raise_exception = false
32
- @@log_level = :info
53
+ def env
54
+ ENV
33
55
  end
34
56
 
35
57
  private
@@ -45,10 +67,6 @@ private
45
67
  raise if self.class.raise_exception
46
68
  end
47
69
 
48
- def command=(value)
49
- @command ||= CommandLineParser.new(value)
50
- end
51
-
52
70
  def help?
53
71
  @command.has_option?("-h") || @command.has_option?("--help") || @command.has_arg?("help") || task == "help"
54
72
  end
@@ -58,38 +76,60 @@ private
58
76
  end
59
77
 
60
78
  def action
61
- @action ||= @command.shift
62
- @action ? @action.to_sym : "index"
79
+ @action ||= begin
80
+ @command.args.first ? @command.args.first.to_sym : :index
81
+ end
63
82
  end
64
83
 
65
84
  def controller
66
- @controller ||= controller_class.send(:new, command)
85
+ @controller ||= controller_class.send(:new, command, self)
67
86
  end
68
87
 
69
88
  def controller_class
70
- @controller_class ||= [task.split("_").map{|i| i.capitalize}.join, "Controller"].join
71
- Object.const_get(@controller_class.to_sym)
89
+ if task
90
+ @controller_class ||= [task.split("_").map{|i| i.capitalize}.join, "Controller"].join
91
+ Object.const_get(@controller_class.to_sym)
92
+ else
93
+ include_controller_for "application"
94
+ @controller_class = "ApplicationController"
95
+ @action = :help
96
+ Object.const_get(@controller_class.to_sym)
97
+ end
72
98
  rescue NameError
73
99
  include_controller_for(task)
74
100
  Object.const_get(@controller_class.to_sym)
75
101
  end
76
102
 
77
103
  def include_controller_for(task)
78
- require [root, "app/controllers", "#{task}_controller"].join("/")
104
+ require File.join([root, "app/controllers", "#{task}_controller"])
79
105
  rescue LoadError
80
106
  self.exit_value = 255
81
107
  raise ControllerNotFound, task
82
108
  end
83
109
 
84
110
  def call_action_on_controller
85
- self.exit_value = controller.send(action || "index")
86
- rescue NameError
87
- self.exit_value = 255
88
- raise ActionNotFound.new(action, task)
111
+ method = action
112
+ if controller_has_action? action
113
+ # pop the args[0] element because this is the method
114
+ @command.shift
115
+ elsif controller_has_action? :no_method
116
+ method = :no_method
117
+ else
118
+ self.exit_value = 255
119
+ raise ActionNotFound.new(action, task)
120
+ end
121
+ self.exit_value = controller.send(method)
89
122
  rescue Controller::ExitRequest => exit_request
90
123
  self.exit_value = exit_request.code
91
124
  end
92
125
 
126
+ def controller_has_action?(action)
127
+ @public_actions ||= begin
128
+ controller_class.public_instance_methods - Controller::Base.public_instance_methods + [:help]
129
+ end
130
+ @public_actions.include?(action.to_sym)
131
+ end
132
+
93
133
  def apply_validators
94
134
  controller.class.apply_validators
95
135
  end
@@ -98,10 +138,6 @@ private
98
138
  controller.class.pair_parameters
99
139
  end
100
140
 
101
- def root=(value)
102
- @root = value
103
- end
104
-
105
141
  def exception=(exception)
106
142
  @exception = exception
107
143
  end
@@ -122,4 +158,4 @@ private
122
158
  @exit_value = exit_value if exit_value.is_a?(Fixnum)
123
159
  end
124
160
  end
125
- end
161
+ end
@@ -1,3 +1,5 @@
1
+ require "lucie/command_line_slicer"
2
+
1
3
  class CommandLineParser
2
4
 
3
5
  attr_reader :options
@@ -5,6 +7,7 @@ class CommandLineParser
5
7
  def initialize(parameters)
6
8
  @params_str = parameters.class == Array ? parameters.join(" ") : parameters
7
9
  @options = {}
10
+ @options[:args] = []
8
11
  @latest_option = nil
9
12
 
10
13
  parse_options()
@@ -37,6 +40,10 @@ class CommandLineParser
37
40
  @options[:args].include?(option)
38
41
  end
39
42
 
43
+ def args
44
+ @options[:args].dup
45
+ end
46
+
40
47
  private
41
48
 
42
49
  def parse_options
@@ -75,6 +82,6 @@ private
75
82
  end
76
83
 
77
84
  def array_of_options
78
- @params_str.strip.split
85
+ CommandLineSlicer.new(@params_str).to_a
79
86
  end
80
87
  end
@@ -0,0 +1,77 @@
1
+ class CommandLineSlicer
2
+ def initialize(line)
3
+ @line = line.split("")
4
+ @parts = []
5
+ @neutral_status = false
6
+ @quotation_open = false
7
+ @scanned = ""
8
+ end
9
+
10
+ def to_a
11
+ each_char do |char|
12
+ if boundary? char
13
+ save_chunk
14
+ elsif in_quoatation? char
15
+ toggle_quotation_state
16
+ elsif neutral? char
17
+ neutral :on
18
+ else
19
+ neutral :off
20
+ append char
21
+ end
22
+ end
23
+ save_chunk
24
+ end
25
+
26
+ private
27
+
28
+ def append(char)
29
+ @scanned += char
30
+ end
31
+
32
+ def each_char(&blk)
33
+ while @line.size > 0
34
+ yield(@line.shift)
35
+ end
36
+ end
37
+
38
+ def toggle_quotation_state
39
+ @quotation_open = !@quotation_open
40
+ end
41
+
42
+ def save_chunk
43
+ @parts << @scanned if @scanned != ""
44
+ @scanned = ""
45
+ @parts
46
+ end
47
+
48
+ def neutral(sym)
49
+ @neutral_status = (sym == :on)
50
+ end
51
+
52
+ private
53
+
54
+ def neutral_chars
55
+ ["\\"]
56
+ end
57
+
58
+ def boundary_chars
59
+ [" "]
60
+ end
61
+
62
+ def quotation_chars
63
+ ["\"", "'"]
64
+ end
65
+
66
+ def boundary?(char)
67
+ boundary_chars.include?(char) && !@neutral_status && !@quotation_open
68
+ end
69
+
70
+ def in_quoatation?(char)
71
+ quotation_chars.include?(char) && !@neutral_status
72
+ end
73
+
74
+ def neutral?(char)
75
+ neutral_chars.include?(char) && !@neutral_status
76
+ end
77
+ end
@@ -5,13 +5,16 @@ module Lucie
5
5
  include Validators::MandatoryOption
6
6
  include Validators::Optional
7
7
 
8
+ attr_reader :app
9
+
8
10
  class << self
9
11
  @validators = []
10
12
  @params = CommandLineParser.new("")
11
13
  end
12
14
 
13
- def initialize(command_line_parser)
15
+ def initialize(command_line_parser, app)
14
16
  self.class.params = command_line_parser
17
+ @app = app
15
18
  end
16
19
 
17
20
  def self.params=(params)
@@ -1,28 +1,72 @@
1
1
  require 'erb'
2
+ require 'fileutils'
2
3
 
3
4
  module Lucie
4
5
  module Snippets
5
6
  module Template
7
+
8
+ protected
9
+
10
+ # that would be great if we occurre the Helper init in every method, but
11
+ # now I don't know nice solution for this
12
+
6
13
  def create_file(file_path, &block)
7
- dir_name = File.dirname(file_path)
8
- if !File.directory?(dir_name)
9
- FileUtils.mkdir_p(dir_name)
14
+ @file_utils_helper ||= FileUtilsHelper.new(self)
15
+ @file_utils_helper.create_file(file_path, &block)
16
+ end
17
+
18
+ def template(template, target)
19
+ @file_utils_helper ||= FileUtilsHelper.new(self)
20
+ @file_utils_helper.template(template, target, binding)
21
+ end
22
+
23
+ private
24
+
25
+ class FileUtilsHelper
26
+
27
+ def initialize(controller)
28
+ @controller = controller
29
+ end
30
+
31
+ def create_file(path, &content)
32
+ path = normalized path
33
+ create_dir_for path
34
+ add_content_to_file path, &content
10
35
  end
11
36
 
12
- if block
13
- File.open(file_path, "a") do |f|
14
- yield(f)
37
+ def template(template, target, binding)
38
+ template = "app/templates/#{template}" if is_relative?(template)
39
+ target = File.join([@controller.app.pwd, target]) if is_relative?(target)
40
+ create_file(target) do |f|
41
+ f.write ERB.new(File.read(normalized(template))).result(binding)
15
42
  end
16
- else
17
- File.new(file_path, "a")
18
43
  end
19
- end
20
44
 
21
- def template(template, target)
22
- create_file(target) do |f|
23
- f.write ERB.new(File.read(template)).result(binding)
45
+ def is_relative?(file_path)
46
+ file_path[0] != "/"
47
+ end
48
+
49
+ def normalized(path)
50
+ if is_relative?(path)
51
+ File.join([@controller.app.root, path])
52
+ else
53
+ path
54
+ end
55
+ end
56
+
57
+ def create_dir_for(file_path)
58
+ dir_name = File.dirname(file_path)
59
+ if !File.directory?(dir_name)
60
+ FileUtils.mkdir_p(dir_name)
61
+ end
62
+ end
63
+
64
+ def add_content_to_file(path, &content)
65
+ block_given? && File.open(path, "a") { |f| yield f } || File.new(path, "a")
24
66
  end
67
+
25
68
  end
69
+
26
70
  end
27
71
  end
28
72
  end
data/lib/lucie.rb CHANGED
@@ -1,3 +1,5 @@
1
+ $LOAD_PATH << File.expand_path("..", __FILE__)
2
+
1
3
  require "lucie/version"
2
4
  require "lucie/exceptions"
3
5
 
@@ -17,12 +19,10 @@ module Lucie
17
19
  autoload :Template, "lucie/snippets/template"
18
20
  end
19
21
 
20
- autoload :CommandLineParser, "lucie/command_line_parser"
21
-
22
22
  end
23
23
 
24
+ require "lucie/command_line_parser"
24
25
  require "lucie/app"
25
26
  require "lucie/controller/base"
26
27
 
27
28
  include Lucie
28
-
data/lucie-lib.gemspec CHANGED
@@ -3,21 +3,22 @@ version = File.read(File.expand_path('../../version', __FILE__)).strip
3
3
  lib = File.expand_path('../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
- Gem::Specification.new do |gem|
7
- gem.name = "lucie-lib"
8
- gem.version = version
9
- gem.authors = ["Nucc"]
10
- gem.email = ["nucc@bteam.hu"]
11
- gem.description = %q{Command line utility framework}
12
- gem.summary = %q{}
13
- gem.homepage = ""
6
+ Gem::Specification.new do |s|
7
+ s.name = "lucie-lib"
8
+ s.version = version
9
+ s.authors = ["Nucc"]
10
+ s.email = ["nucc@bteam.hu"]
11
+ s.description = %q{Command line utility framework}
12
+ s.summary = %q{Library part of Lucie framework. Use only this gem, if you don't need project generator.}
13
+ s.homepage = "http://my.luc.ie"
14
14
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
15
+ s.files = `git ls-files`.split($/)
16
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ["lib"]
19
19
 
20
- gem.add_development_dependency "rake"
21
- gem.add_development_dependency "minitest"
22
- gem.add_development_dependency "mini_shoulda"
20
+ s.add_development_dependency "rake", "10.0.3"
21
+ s.add_development_dependency "minitest", "4.6"
22
+ s.add_development_dependency "mini_shoulda", "0.4.0"
23
+ s.add_development_dependency "sdoc"
23
24
  end
@@ -52,4 +52,18 @@ class CallIndexController < Controller::Base
52
52
  def index
53
53
  print "index_method"
54
54
  end
55
+ end
56
+
57
+ class MethodMissingController < Controller::Base
58
+ def index
59
+ print params[:args][0]
60
+ end
61
+
62
+ alias_method :no_method, :index
63
+ end
64
+
65
+ class DerivedController < CallIndexController
66
+ def new_method
67
+ print "new_method"
68
+ end
55
69
  end
@@ -0,0 +1,13 @@
1
+ class TemplateController < Controller::Base
2
+
3
+ include Snippets::Template
4
+
5
+ def test_1(filename)
6
+ create_file filename do |f| f.print "test_1"; end
7
+ end
8
+
9
+ def test_template_1(source, target)
10
+ template source, target
11
+ end
12
+
13
+ end
@@ -3,7 +3,7 @@ require "stringio"
3
3
  require "helpers/test_app"
4
4
  require "fixtures/command_parser_fixtures"
5
5
 
6
- class CommandProcessorTest < MiniTest::Spec
6
+ describe App do
7
7
 
8
8
  should "parse commands" do
9
9
  assert_output("Hello World", nil) { TestApp.run("command_parser hello") }
@@ -13,7 +13,6 @@ class CommandProcessorTest < MiniTest::Spec
13
13
  assert_output("Parameter", nil) { TestApp.run("command_parser hello_2 --parameter Parameter") }
14
14
  end
15
15
 
16
-
17
16
  should "not give error when mandatory parameters are present" do
18
17
  assert_output("Ok", nil) { TestApp.run("parameter_parser1 search -s") }
19
18
  end
@@ -32,6 +31,14 @@ class CommandProcessorTest < MiniTest::Spec
32
31
  assert_raises(Lucie::RequestError){ TestApp.run("optional_mandatory search") }
33
32
  assert_output("Ok", nil) { TestApp.run("optional_mandatory no_mandatory") }
34
33
  end
34
+
35
+ should "not be able to call method from Object class" do
36
+ assert_raises(Lucie::ActionNotFound) { TestApp.run("derived public_methods") }
37
+ end
38
+
39
+ should "not be able to call method from Controller::Base class" do
40
+ assert_raises(Lucie::ActionNotFound) { TestApp.run("derived params") }
41
+ end
35
42
  end
36
43
 
37
44
  should "be able to pair parameters" do
@@ -63,6 +70,12 @@ class CommandProcessorTest < MiniTest::Spec
63
70
  end
64
71
  end
65
72
 
73
+ should "call help method of ApplicationController when controller name is missing" do
74
+ assert_output "ApplicationController::help", "" do
75
+ TestApp.run "", File.expand_path("../../test_app/", __FILE__)
76
+ end
77
+ end
78
+
66
79
  should "return the exit value" do
67
80
  assert_equal 1, TestApp.run("exit_value method1")
68
81
  end
@@ -80,4 +93,22 @@ class CommandProcessorTest < MiniTest::Spec
80
93
  TestApp.run("call_index")
81
94
  end
82
95
  end
96
+
97
+ should "call method_missing if task method is missing and leave the task in args" do
98
+ assert_output "no_method_with_this_name", "" do
99
+ TestApp.run("method_missing no_method_with_this_name")
100
+ end
101
+ end
102
+
103
+ should "have a root directory which is the directory contains the bin and app folders" do
104
+ assert_equal File.expand_path("../..", __FILE__), TestApp.init("", nil).root
105
+ end
106
+
107
+ should "know the directory where it was called" do
108
+ assert_equal TestApp.new("", nil).pwd.path, File.expand_path("../../../", __FILE__).path
109
+ end
110
+
111
+ should "store the ENV" do
112
+ assert_equal ENV["PWD"], TestApp.init([], "").env["PWD"]
113
+ end
83
114
  end
@@ -1,4 +1,5 @@
1
1
  require "test_helper"
2
+ require "fixtures/template_snippet_fixtures"
2
3
  require "tempfile"
3
4
 
4
5
  class TemplateSnippetTest < MiniTest::Spec
@@ -6,25 +7,27 @@ class TemplateSnippetTest < MiniTest::Spec
6
7
  include Snippets::Template
7
8
 
8
9
  before do
10
+ @template_path = nil
11
+ @template_file_name = nil
9
12
  @tmp_filename = template_path
10
13
  remove_file(@tmp_filename) # if it exists
11
14
  end
12
15
 
13
- after do remove_file(@tmp_filename); end
14
-
16
+ after do
17
+ remove_file(@tmp_filename)
18
+ FileUtils.rmtree(File.join([template_dir, "a"]))
19
+ end
15
20
 
16
21
  describe "create_file" do
17
-
18
22
  should "be able to create an empty file" do
19
23
  create_file @tmp_filename
20
24
  assert File.exists?(@tmp_filename)
21
25
  end
22
26
 
23
27
  should "be able to generate multi level directory if it doesn't exist" do
24
- @tmp_filename = [template_dir, "a", "b", template_file_name].join("/")
28
+ @tmp_filename = File.join([template_dir, "a", "b", template_file_name])
25
29
  create_file @tmp_filename
26
30
  assert File.exists?(@tmp_filename)
27
- FileUtils.rmtree([template_dir, "a"].join("/"))
28
31
  end
29
32
 
30
33
  should "be able to add content to a file using block" do
@@ -46,20 +49,65 @@ class TemplateSnippetTest < MiniTest::Spec
46
49
  assert_equal "line_1", lines[0]
47
50
  assert_equal "line_2", lines[1]
48
51
  end
52
+
53
+ should "generate file relative to PWD that comes from app.pwd" do
54
+ app = Class.new do
55
+ def initialize(root) @root = root end
56
+ attr_reader :root
57
+ end
58
+
59
+ TemplateController.new("", app.new(template_dir)).test_1(template_file_name)
60
+ assert_equal "test_1", File.read(template_path)
61
+ end
49
62
  end
50
63
 
51
64
  context "template" do
52
- before do @template_file = Tempfile.new(template_file_name, template_dir); end
53
65
 
54
- should "generate file from template using absolute directory" do
66
+ before do
67
+ @template_file = Tempfile.new(template_file_name, template_dir)
68
+ @app = Class.new do
69
+ def initialize(root, pwd=nil) @root = root; @pwd = pwd end
70
+ attr_reader :root
71
+ attr_reader :pwd
72
+ end
73
+
74
+ @rand = rand
55
75
  File.open(@template_file, "w+") do |f|
56
- f.write "template <%= @variable %>"
76
+ f.write "template #{@rand}"
57
77
  end
78
+
79
+ end
80
+
81
+ should "generate file from template using absolute directory" do
58
82
  @variable = "test_var_for_template"
59
83
 
60
- template @template_file, @tmp_filename
61
- assert_equal "template test_var_for_template", File.open(@tmp_filename, "r").read
84
+ template @template_file.path, @tmp_filename
85
+ assert_equal "template #{@rand}", File.open(@tmp_filename, "r").read
62
86
  end
87
+
88
+ should "use APP_ROOT/app/templates directory if template has relative path" do
89
+ # we will write it in the controller
90
+ empty(@template_file)
91
+
92
+ source = template_file_name
93
+ source_full_path = File.join([template_dir, "app/templates", template_file_name])
94
+
95
+ create_file(source_full_path) { |f| f.print "template" }
96
+ TemplateController.new("", @app.new(template_dir)).test_template_1(source, @template_file.path)
97
+
98
+ remove_file(source_full_path)
99
+ assert_equal "template", File.read(@template_file)
100
+ end
101
+
102
+ should "generate file to PWD if target is relative path" do
103
+ TemplateController.new("", @app.new(template_dir, "/tmp")).test_template_1(@template_file.path, template_file_name)
104
+ begin
105
+ assert_equal "template #{@rand}", File.read("/tmp/#{template_file_name}")
106
+ ensure
107
+ remove_file("/tmp/#{template_file_name}")
108
+ end
109
+ end
110
+
63
111
  end
64
112
 
65
113
  private
@@ -69,16 +117,24 @@ class TemplateSnippetTest < MiniTest::Spec
69
117
  end
70
118
 
71
119
  def template_file_name
72
- rand = (Time.now.to_i * rand(10**6)).to_i
73
- "template_#{rand}"
120
+ @template_file_name ||= begin
121
+ rand = (Time.now.to_i * rand(10**6)).to_i
122
+ "template_#{rand}"
123
+ end
74
124
  end
75
125
 
76
126
  def template_path
77
- [template_dir, template_file_name].join("/")
127
+ @template_path ||= begin
128
+ File.join([template_dir, template_file_name])
129
+ end
78
130
  end
79
131
 
80
132
  def remove_file(filename)
81
133
  FileUtils.remove_file(filename) if File.exists?(filename)
82
134
  end
83
135
 
136
+ def empty(file)
137
+ file.truncate(0)
138
+ end
139
+
84
140
  end
@@ -0,0 +1,5 @@
1
+ class ApplicationController < Controller::Base
2
+ def help
3
+ print "ApplicationController::help"
4
+ end
5
+ end
data/test/test_helper.rb CHANGED
@@ -1,11 +1,18 @@
1
+ if ENV["TRAVIS"]
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ end
5
+
1
6
  # MiniTest is integrated to Ruby library and by default the test wants to use that.
2
7
  # Force the Rubygems version
3
8
  require 'minitest/autorun'
4
9
  require "mini_shoulda"
10
+ require "pathname"
5
11
  #require 'debugger'
6
12
 
7
13
  require File.expand_path('../../lib/lucie.rb', __FILE__)
8
14
 
15
+
9
16
  LUCIE_ROOT = File.expand_path File.dirname(__FILE__)
10
17
 
11
18
  class MiniTest::Spec
@@ -27,4 +34,10 @@ class MiniTest::Spec
27
34
  def reset_stderr_redirection
28
35
  $stderr = @stderr
29
36
  end
37
+ end
38
+
39
+ class String
40
+ def path
41
+ Pathname.new(self.to_s).realpath.to_s
42
+ end
30
43
  end
@@ -4,7 +4,8 @@ class CommandLineParserTest < MiniTest::Spec
4
4
 
5
5
  should "parse empty string" do
6
6
  parser = CommandLineParser.new ""
7
- assert_equal Hash.new, parser.options
7
+ hash = {:args => []}
8
+ assert_equal hash, parser.options
8
9
  end
9
10
 
10
11
  should "parse short boolean value" do
@@ -66,4 +67,10 @@ class CommandLineParserTest < MiniTest::Spec
66
67
  assert !parser.has_option?("print")
67
68
  end
68
69
 
70
+ should "parse params enclosed with \" or ' as one arg" do
71
+ parser = CommandLineParser.new "arg1 'arg2 arg3'"
72
+ assert_equal "arg1", parser.args[0]
73
+ assert_equal "arg2 arg3", parser.args[1]
74
+ end
75
+
69
76
  end
@@ -0,0 +1,33 @@
1
+ require "test_helper"
2
+
3
+ class CommandLineSlicerTest < MiniTest::Unit::TestCase
4
+
5
+ def test_empty
6
+ assert_equal [], CommandLineSlicer.new("").to_a
7
+ end
8
+
9
+ def test_one_word
10
+ assert_equal ["word"], CommandLineSlicer.new("word").to_a
11
+ end
12
+
13
+ def test_more_words_with_spaces
14
+ assert_equal ["first", "second"], CommandLineSlicer.new("first second").to_a
15
+ end
16
+
17
+ def test_neutral_space
18
+ assert_equal ["first second"], CommandLineSlicer.new("first\\ second").to_a
19
+ end
20
+
21
+ def test_neutral_element_on_another_neutral
22
+ assert_equal ["first\\", "second"], CommandLineSlicer.new("first\\\\ second").to_a
23
+ end
24
+
25
+ def test_neutral_element_on_another_neutral_between_quotation
26
+ assert_equal ["first\\ second"], CommandLineSlicer.new('"first\\\\ second"').to_a
27
+ end
28
+
29
+ def test_quotation_marks
30
+ assert_equal ["first", "second third"], CommandLineSlicer.new('first "second third"').to_a
31
+ assert_equal ["first", "second third"], CommandLineSlicer.new("first 'second third'").to_a
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class ControllerBaseTest < MiniTest::Unit::TestCase
4
+
5
+ include Controller
6
+
7
+ def test_app_can_be_set
8
+ app = Object.new
9
+ controller = Base.new(nil, app)
10
+ assert_equal app, controller.app
11
+ end
12
+
13
+ end
metadata CHANGED
@@ -1,62 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucie-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nucc
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-01 00:00:00.000000000 Z
11
+ date: 2013-09-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '='
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 10.0.3
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '='
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: 10.0.3
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '='
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '4.6'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '='
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: '4.6'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: mini_shoulda
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: sdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
52
60
  - !ruby/object:Gem::Version
53
61
  version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - '>='
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  description: Command line utility framework
@@ -71,6 +78,7 @@ files:
71
78
  - lib/lucie.rb
72
79
  - lib/lucie/app.rb
73
80
  - lib/lucie/command_line_parser.rb
81
+ - lib/lucie/command_line_slicer.rb
74
82
  - lib/lucie/controller/base.rb
75
83
  - lib/lucie/controller/exit_request.rb
76
84
  - lib/lucie/exceptions.rb
@@ -81,45 +89,47 @@ files:
81
89
  - lib/lucie/version.rb
82
90
  - lucie-lib.gemspec
83
91
  - test/fixtures/command_parser_fixtures.rb
84
- - test/functional/command_parser_test.rb
92
+ - test/fixtures/template_snippet_fixtures.rb
93
+ - test/functional/app_test.rb
85
94
  - test/functional/template_snippet_test.rb
86
95
  - test/helpers/test_app.rb
96
+ - test/test_app/app/controllers/application_controller.rb
87
97
  - test/test_helper.rb
88
98
  - test/unit/command_line_parser_test.rb
89
- homepage: ''
99
+ - test/unit/command_line_slicer_test.rb
100
+ - test/unit/controller/base_test.rb
101
+ homepage: http://my.luc.ie
90
102
  licenses: []
103
+ metadata: {}
91
104
  post_install_message:
92
105
  rdoc_options: []
93
106
  require_paths:
94
107
  - lib
95
108
  required_ruby_version: !ruby/object:Gem::Requirement
96
- none: false
97
109
  requirements:
98
- - - ! '>='
110
+ - - '>='
99
111
  - !ruby/object:Gem::Version
100
112
  version: '0'
101
- segments:
102
- - 0
103
- hash: 1605038875094015661
104
113
  required_rubygems_version: !ruby/object:Gem::Requirement
105
- none: false
106
114
  requirements:
107
- - - ! '>='
115
+ - - '>='
108
116
  - !ruby/object:Gem::Version
109
117
  version: '0'
110
- segments:
111
- - 0
112
- hash: 1605038875094015661
113
118
  requirements: []
114
119
  rubyforge_project:
115
- rubygems_version: 1.8.25
120
+ rubygems_version: 2.0.3
116
121
  signing_key:
117
- specification_version: 3
118
- summary: ''
122
+ specification_version: 4
123
+ summary: Library part of Lucie framework. Use only this gem, if you don't need project
124
+ generator.
119
125
  test_files:
120
126
  - test/fixtures/command_parser_fixtures.rb
121
- - test/functional/command_parser_test.rb
127
+ - test/fixtures/template_snippet_fixtures.rb
128
+ - test/functional/app_test.rb
122
129
  - test/functional/template_snippet_test.rb
123
130
  - test/helpers/test_app.rb
131
+ - test/test_app/app/controllers/application_controller.rb
124
132
  - test/test_helper.rb
125
133
  - test/unit/command_line_parser_test.rb
134
+ - test/unit/command_line_slicer_test.rb
135
+ - test/unit/controller/base_test.rb