filigree 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,32 +21,32 @@ class ApplicationTester < Minitest::Test
21
21
  class Foo
22
22
  include Filigree::Application
23
23
  end
24
-
24
+
25
25
  class Bar
26
26
  include Filigree::Application
27
-
27
+
28
28
  class Configuration
29
29
  auto :foo do
30
30
  :foo
31
31
  end
32
32
  end
33
-
33
+
34
34
  def kill; end
35
35
  def pause; end
36
36
  def resume; end
37
37
  def run; end
38
38
  def stop; end
39
39
  end
40
-
40
+
41
41
  def setup
42
-
42
+
43
43
  end
44
-
44
+
45
45
  def test_application
46
46
  assert_raises(NoMethodError) { Foo.finalize }
47
47
  Bar.finalize
48
48
  end
49
-
49
+
50
50
  def test_embedded_config
51
51
  assert_equal :foo, Bar.new.config.foo
52
52
  end
@@ -19,19 +19,19 @@ require 'filigree/boolean'
19
19
 
20
20
  class BooleanTester < Minitest::Test
21
21
  def setup
22
-
22
+
23
23
  end
24
-
24
+
25
25
  def test_integer
26
26
  assert 1.to_bool
27
27
  assert 10.to_bool
28
28
  assert !0.to_bool
29
29
  end
30
-
30
+
31
31
  def test_true
32
32
  assert_equal 1, true.to_i
33
33
  end
34
-
34
+
35
35
  def test_false
36
36
  assert_equal 0, false.to_i
37
37
  end
@@ -19,25 +19,25 @@ require 'filigree/class'
19
19
 
20
20
  class ClassTester < Minitest::Test
21
21
  module Foo; end
22
-
22
+
23
23
  class Bar
24
24
  include Foo
25
-
25
+
26
26
  class Baf; end
27
27
  end
28
-
28
+
29
29
  class Baz < Bar; end
30
-
30
+
31
31
  def setup
32
-
32
+
33
33
  end
34
-
34
+
35
35
  def test_class
36
36
  assert Bar.includes_module?(Foo)
37
-
38
- assert_equal 'ClassTester::Bar::Baf', Bar::Baf.name
37
+
38
+ assert_equal 'ClassTester::Bar::Baf', Bar::Baf.name
39
39
  assert_equal 'Baf', Bar::Baf.short_name
40
-
40
+
41
41
  assert Baz.subclass_of?(Bar)
42
42
  assert !Baz.subclass_of?(Fixnum)
43
43
  assert_raises(TypeError) { Baz.subclass_of?(1) }
@@ -20,51 +20,109 @@ require 'filigree/class_methods_module'
20
20
  class ClassMethodsModuleTester < Minitest::Test
21
21
  module Foo
22
22
  include Filigree::ClassMethodsModule
23
-
23
+
24
24
  def foo
25
25
  :foo
26
26
  end
27
-
27
+
28
28
  module ClassMethods
29
29
  def foo
30
30
  :foo
31
31
  end
32
32
  end
33
33
  end
34
-
34
+
35
35
  module Baz
36
36
  include Filigree::ClassMethodsModule
37
-
37
+
38
38
  def baz
39
39
  :baz
40
40
  end
41
-
41
+
42
42
  module ClassMethods
43
43
  def baz
44
44
  :baz
45
45
  end
46
46
  end
47
47
  end
48
-
48
+
49
49
  class Bar
50
50
  include Foo
51
51
  end
52
-
52
+
53
53
  class Baf
54
54
  include Foo
55
55
  include Baz
56
56
  end
57
-
57
+
58
+ # module ModuleVarTester0
59
+ # include Filigree::ClassMethodsModule
60
+
61
+ # module ClassMethods
62
+ # module Variables
63
+ # @
64
+ # end
65
+
66
+ # def answer
67
+ # @answer
68
+ # end
69
+
70
+ # def answer=(val)
71
+ # @answer = val
72
+ # end
73
+ # end
74
+ # end
75
+
76
+ # module ModuleVarTester1
77
+ # include Filigree::ClassMethodsModule
78
+
79
+ # def ClassVariables
80
+ # @hoopy = :frood
81
+ # end
82
+
83
+ # module ClassMethods
84
+ # def hoopy
85
+ # @hoopy
86
+ # end
87
+ # end
88
+ # end
89
+
90
+ # class VarTester0
91
+ # include ModuleVarTester0
92
+ # end
93
+
94
+ # class VarTester1
95
+ # include ModuleVarTester0
96
+ # end
97
+
98
+ # class VarTester2
99
+ # include ModuleVarTester0
100
+ # include ModuleVarTester1
101
+ # end
102
+
58
103
  def test_class_methods_module
59
104
  assert_equal :foo, Bar.foo
60
105
  assert_equal :foo, Bar.new.foo
61
106
  end
62
-
107
+
108
+ # def test_class_variables
109
+ # assert_equal 42, VarTester0.answer
110
+ # assert_equal 42, VarTester1.answer
111
+
112
+ # VarTester1.answer = 0
113
+
114
+ # assert_equal 42, VarTester0.answer
115
+ # assert_equal 0, VarTester1.answer
116
+
117
+ # assert_equal 42, VarTester2.answer
118
+ # assert_equal :frood, VarTester2.hoopy
119
+ # end
120
+
63
121
  def test_double_include
64
-
122
+
65
123
  assert_equal :foo, Baf.foo
66
124
  assert_equal :foo, Baf.new.foo
67
-
125
+
68
126
  assert_equal :baz, Baf.baz
69
127
  assert_equal :baz, Baf.new.baz
70
128
  end
@@ -20,19 +20,19 @@ require 'filigree/commands'
20
20
  class CommandTester < Minitest::Test
21
21
  class TestCommands
22
22
  include Filigree::Commands
23
-
23
+
24
24
  command 'foo' do
25
25
  :foo
26
26
  end
27
-
27
+
28
28
  command 'foo bar' do
29
29
  :foobar
30
30
  end
31
-
31
+
32
32
  command 'hello1' do |subject|
33
33
  "hello #{subject}"
34
34
  end
35
-
35
+
36
36
  config do
37
37
  default 'world'
38
38
  option 'subject', 's', conversions: [:to_s]
@@ -40,38 +40,38 @@ class CommandTester < Minitest::Test
40
40
  command 'hello2' do
41
41
  "hello #{subject}"
42
42
  end
43
-
43
+
44
44
  command 'add' do |x, y|
45
45
  x.to_i + y.to_i
46
46
  end
47
47
  end
48
-
48
+
49
49
  def setup
50
50
  @commander = TestCommands.new
51
51
  end
52
-
52
+
53
53
  def test_command_not_found
54
54
  assert_raises(CommandNotFoundError) { @commander.('bar') }
55
55
  end
56
-
56
+
57
57
  def test_command_args
58
58
  assert_equal 'hello world', @commander.('hello1 world')
59
59
  assert_equal 42, @commander.('add 27 15')
60
60
  end
61
-
61
+
62
62
  def test_command_with_wrong_args
63
63
  assert_raises(ArgumentError) { @commander.('hello1 cat dog') }
64
64
  end
65
-
65
+
66
66
  def test_configured_command
67
67
  assert_equal 'hello world', @commander.('hello2')
68
68
  assert_equal 'hello dog', @commander.('hello2 -s dog')
69
69
  end
70
-
70
+
71
71
  def test_subcommand
72
72
  assert_equal :foobar, @commander.('foo bar')
73
73
  end
74
-
74
+
75
75
  def test_zero_arg_command
76
76
  assert_equal :foo, @commander.('foo')
77
77
  end
@@ -20,153 +20,153 @@ require 'filigree/configuration'
20
20
  class ConfigurationTester < Minitest::Test
21
21
  class TestConfig
22
22
  include Filigree::Configuration
23
-
23
+
24
24
  help 'Does foo.'
25
25
  default { moo.to_s }
26
26
  string_option 'foo', 'f'
27
-
27
+
28
28
  help 'This is a longer help message to test and see how the string segmentation works. I hope it is long enough.'
29
29
  default 42
30
30
  option 'bar', 'b', conversions: [:to_i]
31
-
31
+
32
32
  help 'Does baz.'
33
33
  option 'baz', 'z', conversions: [:to_sym, :to_sym]
34
-
34
+
35
35
  help 'Does moo.'
36
36
  required
37
37
  option 'moo', 'm' do |i|
38
38
  i.to_i * 6
39
39
  end
40
-
40
+
41
41
  help 'This does daf'
42
42
  option 'daf', 'd' do |*syms|
43
43
  syms.map { |syms| syms.to_sym }
44
44
  end
45
-
45
+
46
46
  bool_option :bool
47
-
47
+
48
48
  auto :cow do
49
49
  self.moo / 3
50
50
  end
51
51
  end
52
-
52
+
53
53
  def setup
54
54
  @defaults = ['--moo', '10']
55
55
  end
56
-
56
+
57
57
  def test_auto
58
58
  conf = TestConfig.new @defaults
59
-
59
+
60
60
  assert_equal 20, conf.cow
61
61
  end
62
-
62
+
63
63
  def test_bool_option
64
64
  conf = TestConfig.new @defaults.clone
65
65
  assert !conf.bool, 'Boolean flag set in config object'
66
-
66
+
67
67
  conf = TestConfig.new(@defaults.clone << '--bool')
68
68
  assert conf.bool, 'Boolean flag not set in config object'
69
69
  end
70
-
70
+
71
71
  def test_defaults
72
72
  conf = TestConfig.new @defaults
73
-
73
+
74
74
  assert_equal 42, conf.bar
75
75
  assert_equal '60', conf.foo
76
76
  end
77
-
77
+
78
78
  def test_long_option
79
79
  conf = TestConfig.new @defaults
80
-
80
+
81
81
  assert_equal 60, conf.moo
82
82
  end
83
-
83
+
84
84
  def test_proc_handler
85
85
  conf = TestConfig.new (@defaults + ['--foo', 'hello world'])
86
-
86
+
87
87
  assert_equal 'hello world', conf.foo
88
88
  end
89
-
89
+
90
90
  def test_required
91
91
  assert_raises(ArgumentError) { TestConfig.new([]) }
92
92
  TestConfig.new(@defaults)
93
93
  end
94
-
94
+
95
95
  def test_serialization
96
96
  require 'tempfile'
97
-
97
+
98
98
  conf = TestConfig.new (@defaults + ['-f', 'hello world', '-b', '32', '-z', 'a', 'b'])
99
-
99
+
100
100
  yaml_string = conf.dump
101
-
101
+
102
102
  conf = TestConfig.new yaml_string
103
-
103
+
104
104
  assert_equal 60, conf.moo
105
105
  assert_equal 'hello world', conf.foo
106
106
  assert_equal 32, conf.bar
107
107
  assert_equal [:a, :b], conf.baz
108
-
108
+
109
109
  yaml_file = Tempfile.new 'tc_configuration_serialization'
110
110
  yaml_file_path = yaml_file.path
111
111
  yaml_file.close
112
-
112
+
113
113
  # Dump the file.
114
114
  File.open(yaml_file_path, 'w') { |f| conf.dump f }
115
-
115
+
116
116
  # Load the configuration from the file.
117
117
  conf = File.open(yaml_file_path, 'r') { |f| TestConfig.new f }
118
-
118
+
119
119
  assert_equal 60, conf.moo
120
120
  assert_equal 'hello world', conf.foo
121
121
  assert_equal 32, conf.bar
122
122
  assert_equal [:a, :b], conf.baz
123
-
123
+
124
124
  # Remove the file.
125
125
  FileUtils.rm yaml_file_path
126
-
126
+
127
127
  # Re-create an empty file.
128
128
  FileUtils.touch yaml_file_path
129
-
129
+
130
130
  # Dump the config again.
131
131
  conf.dump yaml_file_path
132
-
132
+
133
133
  # Load the configuration again.
134
134
  conf = TestConfig.new yaml_file_path
135
-
135
+
136
136
  assert_equal 60, conf.moo
137
137
  assert_equal 'hello world', conf.foo
138
138
  assert_equal 32, conf.bar
139
139
  assert_equal [:a, :b], conf.baz
140
-
140
+
141
141
  #########################
142
142
  # Partial Serialization #
143
143
  #########################
144
-
144
+
145
145
  yaml_string = conf.dump nil, :moo, :foo, :bar
146
-
146
+
147
147
  conf = TestConfig.new yaml_string
148
-
148
+
149
149
  assert_equal 60, conf.moo
150
150
  assert_equal 'hello world', conf.foo
151
151
  assert_equal 32, conf.bar
152
152
  end
153
-
153
+
154
154
  def test_short_option
155
155
  conf = TestConfig.new ['-m', 10]
156
-
156
+
157
157
  assert_equal 60, conf.moo
158
158
  end
159
-
159
+
160
160
  def test_splat
161
161
  conf = TestConfig.new (['-d', 'a', 'b', 'c'] + @defaults)
162
-
162
+
163
163
  assert_equal [:a, :b, :c], conf.daf
164
164
  end
165
-
165
+
166
166
  def test_symbol_handler
167
167
  conf = TestConfig.new (@defaults + ['-b', '32'])
168
168
  assert_equal 32, conf.bar
169
-
169
+
170
170
  conf = TestConfig.new (@defaults + ['-z', 'a', 'b'])
171
171
  assert_equal [:a, :b], conf.baz
172
172
  end