rubikon 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,8 +43,12 @@ class TestApplication < Test::Unit::TestCase
43
43
  assert_instance_of SystemExit, e
44
44
  assert_equal 1, e.status
45
45
  end
46
- @ostream.rewind
47
- assert_equal "Error:\n", @ostream.gets
46
+ if @app.instance.instance_eval { @settings[:colors] }
47
+ error_text = "\e[0;31mError:\e[0m\n"
48
+ else
49
+ error_text = "Error:\n"
50
+ end
51
+ assert_equal error_text, @ostream.gets
48
52
  assert_equal " Unknown command: unknown\n", @ostream.gets
49
53
  end
50
54
 
@@ -72,16 +76,12 @@ class TestApplication < Test::Unit::TestCase
72
76
  @istream.puts input_string
73
77
  @istream.rewind
74
78
  assert_equal input_string, @app.run(%w{input})
75
- @ostream.rewind
76
79
  assert_equal 'input: ', @ostream.gets
77
80
  end
78
81
 
79
82
  should 'not break output while displaying a throbber or progress bar' do
80
83
  @app.run(%w{throbber})
81
84
  assert_match (/ \x08(?:(?:-|\\|\/|\|)\x08){4,}don't\nbreak\n/), @ostream.string
82
-
83
- @ostream.rewind
84
-
85
85
  @app.run(%w{progressbar})
86
86
  assert_equal "#" * 20 << "\n" << "test\n" * 4, @ostream.string
87
87
  end
data/test/test_command.rb CHANGED
@@ -42,10 +42,10 @@ class TestCommand < Test::Unit::TestCase
42
42
  should 'correctly parse given parameters' do
43
43
  command = Command.new @app, :command, [:cmd_arg] do end
44
44
  option = Option.new(@app, :test, [:opt_arg])
45
- command.add_param option
45
+ command.send(:add_param, option)
46
46
  flag = Flag.new(@app, :t)
47
- command.add_param flag
48
- command.run(*%w{--test arg -t test})
47
+ command.send(:add_param, flag)
48
+ command.send(:run, *%w{--test arg -t test})
49
49
  assert option.active?
50
50
  assert flag.active?
51
51
  assert_equal %w{test}, command.arguments
@@ -56,21 +56,21 @@ class TestCommand < Test::Unit::TestCase
56
56
  assert_equal 'arg', command.test.opt_arg
57
57
 
58
58
  assert_raise UnknownParameterError do
59
- command.run(*%w{--unknown})
59
+ command.send(:run, *%w{--unknown})
60
60
  end
61
61
  end
62
62
 
63
63
  should 'allow parameter aliases' do
64
64
  command = Command.new @app, :command do end
65
- command.add_param({ :t => :test })
65
+ command.send(:add_param, { :t => :test })
66
66
  flag1 = Flag.new(@app, :test)
67
- command.add_param flag1
67
+ command.send(:add_param, flag1)
68
68
  flag2 = Flag.new(@app, :test2)
69
- command.add_param flag2
70
- command.add_param({ :t2 => :test2 })
71
- command.run(*%w{-t --t2})
72
- assert flag1.active?
73
- assert flag2.active?
69
+ command.send(:add_param, flag2)
70
+ command.send(:add_param, { :t2 => :test2 })
71
+ command.send(:run, *%w{-t --t2})
72
+ assert flag1.send(:active?)
73
+ assert flag2.send(:active?)
74
74
  end
75
75
 
76
76
  should 'run the code supplied inside its block' do
@@ -78,13 +78,13 @@ class TestCommand < Test::Unit::TestCase
78
78
  command = Command.new @app, :command do
79
79
  block_run = true
80
80
  end
81
- command.run
81
+ command.send :run
82
82
  assert block_run
83
83
  end
84
84
 
85
85
  should 'run external code if no block is given' do
86
86
  command = Command.new @app, :external_command
87
- command.run
87
+ command.send :run
88
88
  assert @app.sandbox.instance_variable_get(:@external_command_run)
89
89
  end
90
90
 
@@ -0,0 +1,41 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2009-2010, Sebastian Staudt
5
+
6
+ require 'test_helper'
7
+
8
+ class TestConfig < Test::Unit::TestCase
9
+
10
+ context 'A configuration' do
11
+
12
+ setup do
13
+ path = File.join(File.dirname(__FILE__), 'config')
14
+ @config_file = 'config.yml'
15
+ @search_paths = []
16
+ @search_paths << File.join(path, '0')
17
+ @search_paths << File.join(path, '1')
18
+ @search_paths << File.join(path, '2')
19
+ @search_paths << File.join(path, '3')
20
+
21
+ @factory = Rubikon::Config::Factory.new(@config_file, @search_paths)
22
+ end
23
+
24
+ should 'search multiple paths for a configuration file' do
25
+ config_files = @search_paths[0..-2].map { |p| File.join(p, @config_file) }
26
+ assert_equal config_files, @factory.files
27
+ end
28
+
29
+ should 'read the configuration from the specified files' do
30
+ config = {
31
+ :value => 0,
32
+ :value1 => 1,
33
+ :value2 => 2,
34
+ :overriden => 2
35
+ }
36
+ assert_equal config, @factory.config
37
+ end
38
+
39
+ end
40
+
41
+ end
data/test/test_flag.rb CHANGED
@@ -21,7 +21,7 @@ class TestFlag < Test::Unit::TestCase
21
21
  flag = Flag.new @app, :flag do
22
22
  block_run = true
23
23
  end
24
- flag.active!
24
+ flag.send :active!
25
25
  assert flag.active?
26
26
  assert block_run
27
27
  end
@@ -29,11 +29,11 @@ class TestFlag < Test::Unit::TestCase
29
29
  should 'not allow any arguments' do
30
30
  flag = Flag.new @app, :test
31
31
  assert_raise ExtraArgumentError do
32
- flag << 'argument'
32
+ flag.send(:<<, 'argument')
33
33
  end
34
34
 
35
- assert flag.args_full?
36
- assert !flag.more_args?
35
+ assert flag.send(:args_full?)
36
+ assert !flag.send(:more_args?)
37
37
  assert !flag.respond_to?(:args)
38
38
  end
39
39
 
@@ -22,71 +22,71 @@ class TestHasArguments < Test::Unit::TestCase
22
22
 
23
23
  should 'allow a Numeric as argument count' do
24
24
  has_arg = HasArg.new(1)
25
- assert_equal 1..1, has_arg.arg_count
25
+ assert_equal 1..1, has_arg.send(:arg_count)
26
26
  assert_nil has_arg.arg_names
27
27
  end
28
28
 
29
29
  should 'allow a Range as argument count' do
30
30
  has_arg = HasArg.new(1..3)
31
- assert_equal 1..3, has_arg.arg_count
31
+ assert_equal 1..3, has_arg.send(:arg_count)
32
32
  assert_nil has_arg.arg_names
33
33
  end
34
34
 
35
35
  should 'allow an Array as argument count' do
36
36
  has_arg = HasArg.new([2, 5, 6])
37
- assert_equal 2..6, has_arg.arg_count
37
+ assert_equal 2..6, has_arg.send(:arg_count)
38
38
  assert_nil has_arg.arg_names
39
39
  end
40
40
 
41
41
  should 'allow a Symbol Array as argument names' do
42
42
  has_arg = HasArg.new([:arg1, :arg2, :arg3])
43
- assert_equal 3..3, has_arg.arg_count
43
+ assert_equal 3..3, has_arg.send(:arg_count)
44
44
  assert_equal [:arg1, :arg2, :arg3], has_arg.arg_names
45
45
  end
46
46
 
47
47
  should 'only have required arguments if argument count is > 0' do
48
48
  has_arg = HasArg.new(2)
49
- assert !has_arg.args_full?
50
- assert has_arg.more_args?
51
- has_arg << 'argument'
49
+ assert !has_arg.send(:args_full?)
50
+ assert has_arg.send(:more_args?)
51
+ has_arg.send(:<<, 'argument')
52
52
  assert_equal %w{argument}, has_arg.args
53
53
  assert_raise MissingArgumentError do
54
- has_arg.check_args
54
+ has_arg.send :check_args
55
55
  end
56
- has_arg << 'argument'
57
- assert has_arg.args_full?
58
- assert !has_arg.more_args?
56
+ has_arg.send(:<<, 'argument')
57
+ assert has_arg.send(:args_full?)
58
+ assert !has_arg.send(:more_args?)
59
59
  assert_equal %w{argument argument}, has_arg.args
60
60
  assert_raise ExtraArgumentError do
61
- has_arg << 'argument'
61
+ has_arg.send(:<<, 'argument')
62
62
  end
63
63
  assert_equal %w{argument argument}, has_arg.args
64
64
  end
65
65
 
66
66
  should 'have required and optional arguments if argument count is < 0' do
67
67
  has_arg = HasArg.new(-1)
68
- assert !has_arg.args_full?
69
- assert has_arg.more_args?
68
+ assert !has_arg.send(:args_full?)
69
+ assert has_arg.send(:more_args?)
70
70
  assert_raise MissingArgumentError do
71
- has_arg.check_args
71
+ has_arg.send :check_args
72
72
  end
73
- has_arg << 'argument'
74
- assert has_arg.args_full?
75
- assert has_arg.more_args?
73
+ has_arg.send(:<<, 'argument')
74
+ assert has_arg.send(:args_full?)
75
+ assert has_arg.send(:more_args?)
76
76
  assert_equal %w{argument}, has_arg.args
77
77
  end
78
78
 
79
79
  should 'only have optional arguments if argument count is 0' do
80
80
  has_arg = HasArg.new(0)
81
- assert has_arg.args_full?
82
- assert has_arg.more_args?
83
- has_arg << 'argument'
81
+ assert has_arg.send(:args_full?)
82
+ assert has_arg.send(:more_args?)
83
+ has_arg.send(:<<, 'argument')
84
84
  assert_equal %w{argument}, has_arg.args
85
85
  end
86
86
 
87
87
  should 'provide named arguments' do
88
88
  has_arg = HasArg.new([:named])
89
- has_arg << 'argument'
89
+ has_arg.send(:<<, 'argument')
90
90
  assert_equal 'argument', has_arg[:named]
91
91
  assert_equal 'argument', has_arg.named
92
92
  assert_raise NoMethodError do
@@ -99,8 +99,8 @@ class TestHasArguments < Test::Unit::TestCase
99
99
  has_arg = HasArg.new nil do
100
100
  block_run = true
101
101
  end
102
- has_arg.active!
103
- assert has_arg.active?
102
+ has_arg.send :active!
103
+ assert has_arg.send(:active?)
104
104
  assert block_run
105
105
  end
106
106
 
@@ -0,0 +1,26 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2010, Sebastian Staudt
5
+
6
+ require 'test_helper'
7
+
8
+ class TestIniProvider < Test::Unit::TestCase
9
+
10
+ context 'A configuration provider for INI files' do
11
+
12
+ should 'return correct values' do
13
+ ini = File.join(File.dirname(__FILE__), 'config', 'test.ini')
14
+ expected = {
15
+ 'section' => {
16
+ 'value' => '1',
17
+ 'test1' => '1',
18
+ 'test2' => '2'
19
+ }
20
+ }
21
+ assert_equal expected, Rubikon::Config::IniProvider.load_config(ini)
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -100,6 +100,24 @@ class TestProgressBar < Test::Unit::TestCase
100
100
  assert_equal 101, @bar.instance_variable_get(:@value)
101
101
  end
102
102
 
103
+ should 'have brackets when enabled' do
104
+ ostream = StringIO.new
105
+ options = {
106
+ :brackets => true,
107
+ :bracket_filler => '-',
108
+ :ostream => ostream
109
+ }
110
+
111
+ @bar = ProgressBar.new options
112
+ assert_equal '[' + '-' * 20 + ']' + "\b" * 21, ostream.string
113
+
114
+ @bar + 50
115
+ assert_equal '[' + '-' * 20 + ']' + "\b" * 21 + '#' * 10, ostream.string
116
+
117
+ @bar + 50
118
+ assert_equal '[' + '-' * 20 + ']' + "\b" * 21 + '#' * 20 + "\n", ostream.string
119
+ end
120
+
103
121
  end
104
122
 
105
123
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubikon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sebastian Staudt
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-18 00:00:00 +02:00
18
+ date: 2010-11-12 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -82,7 +82,12 @@ files:
82
82
  - lib/rubikon/application/dsl_methods.rb
83
83
  - lib/rubikon/application/instance_methods.rb
84
84
  - lib/rubikon/application/sandbox.rb
85
+ - lib/rubikon/colored_io.rb
85
86
  - lib/rubikon/command.rb
87
+ - lib/rubikon/config/auto_provider.rb
88
+ - lib/rubikon/config/factory.rb
89
+ - lib/rubikon/config/ini_provider.rb
90
+ - lib/rubikon/config/yaml_provider.rb
86
91
  - lib/rubikon/exceptions.rb
87
92
  - lib/rubikon/flag.rb
88
93
  - lib/rubikon/has_arguments.rb
@@ -90,13 +95,16 @@ files:
90
95
  - lib/rubikon/parameter.rb
91
96
  - lib/rubikon/progress_bar.rb
92
97
  - lib/rubikon/throbber.rb
98
+ - samples/config/config_sample.rb
93
99
  - samples/helloworld/hello_world.rb
94
100
  - test/commands/external_command.rb
95
101
  - test/test_application.rb
96
102
  - test/test_command.rb
103
+ - test/test_config.rb
97
104
  - test/test_flag.rb
98
105
  - test/test_has_arguments.rb
99
106
  - test/test_helper.rb
107
+ - test/test_ini_provider.rb
100
108
  - test/test_option.rb
101
109
  - test/test_parameter.rb
102
110
  - test/test_progress_bar.rb
@@ -140,9 +148,11 @@ test_files:
140
148
  - test/commands/external_command.rb
141
149
  - test/test_application.rb
142
150
  - test/test_command.rb
151
+ - test/test_config.rb
143
152
  - test/test_flag.rb
144
153
  - test/test_has_arguments.rb
145
154
  - test/test_helper.rb
155
+ - test/test_ini_provider.rb
146
156
  - test/test_option.rb
147
157
  - test/test_parameter.rb
148
158
  - test/test_progress_bar.rb