cliutils 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68db9f1432d7c3406a8e3e0d8da2b36ebb3f9ca2
4
- data.tar.gz: 6f94550ad158c2fe248ce3a96d55c79b10205858
3
+ metadata.gz: 7a871fd064a86dc102c5f840bd900f51f60aedfd
4
+ data.tar.gz: b73ad1c281bdc4f03b4079ac2992e2b7f4fbe832
5
5
  SHA512:
6
- metadata.gz: 0f4cdd934a27ce5806633a2d6a4949e7f6d60a6f1bf60563952cc602035cee1609443a445844b1923b882163795dfab6ce306503ea8ada5d7b11654b048697b9
7
- data.tar.gz: f00af86450a6e7d39bb695c926ddb7005b23f28ebe90ff3983f619b0eaed384bc699b449a85675bab7cc4e561ec4ce88824ace3b90ce37a80e81f40b1f49a1ae
6
+ metadata.gz: 406caacfd63537aa09a66865b5e390e311877c7234ea8db01ff027b9b520cc52ae2e59b7966f205911b75bc44173585ffa7da89800b3847c1e44426ef096da54
7
+ data.tar.gz: e1c0a4abc34dc40a1f62f3c0759c17db0bd29ce78f541d9d33c0d15f7d464453975db85bea2d9e2ee46cd7e4119309aaaa6b045da5976f5b38dcb6fc29cd5464
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 2.1.2 (2014-04-26)
2
+
3
+ * Added some error checking to Configuration
4
+ * More unit tests
5
+ * A few small bugfixes
6
+
1
7
  # 2.1.1 (2014-04-26)
2
8
 
3
9
  * Fixed a bug in which older Ruby versions wouldn't load Pref assets correctly
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ require 'rake/testtask'
17
17
  desc 'Run unit tests'
18
18
  Rake::TestTask.new do |t|
19
19
  t.libs << "test"
20
- t.test_files = FileList['test/*_test.rb']
20
+ t.test_files = FileList['test/*_test.rb', 'test/**/*_test.rb']
21
21
  end
22
22
 
23
23
  desc "Release CLIUtils version #{version}"
@@ -1,5 +1,4 @@
1
1
  require 'logger'
2
- require 'yaml'
3
2
 
4
3
  module CLIUtils
5
4
  # Configuration Module
@@ -15,6 +14,8 @@ module CLIUtils
15
14
  'FATAL' => Logger::FATAL
16
15
  }
17
16
 
17
+ @@configuration = nil
18
+
18
19
  # Hook that triggers when this module is included.
19
20
  # @param [Object] k The includer object
20
21
  # @return [void]
@@ -26,7 +27,12 @@ module CLIUtils
26
27
  # a Configurator.
27
28
  # @return [Configurator]
28
29
  def configuration
29
- @@configuration ||= Configurator.new('~/.default-cliutils')
30
+ if !@@configuration.nil?
31
+ @@configuration
32
+ else
33
+ fail 'Attempted to access `configuration` before ' \
34
+ 'executing `load_configuration`'
35
+ end
30
36
  end
31
37
 
32
38
  # Singleton method to return (or initialize, if needed)
@@ -8,5 +8,5 @@ module CLIUtils
8
8
  SUMMARY = 'Sugary goodness for Ruby CLI apps.'
9
9
 
10
10
  # The current version of the gem
11
- VERSION = '2.1.1'
11
+ VERSION = '2.1.2'
12
12
  end
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_actions/open_url_action')
4
+
5
+ # Tests for the Configurator class
6
+ class TestOpenUrlAction < Test::Unit::TestCase
7
+ def test_run
8
+ a = CLIUtils::OpenUrlAction.new
9
+ a.parameters = { url: 'http://www.google.com' }
10
+ assert_output() { a.run }
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_behaviors/capitalize_behavior')
4
+
5
+ # Tests for the Configurator class
6
+ class TestCapitalizeBehavior < Test::Unit::TestCase
7
+ def test_evaluation
8
+ v = CLIUtils::CapitalizeBehavior.new
9
+ assert_equal(v.evaluate('bachya'), 'Bachya')
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_behaviors/expand_filepath_behavior')
4
+
5
+ # Tests for the Configurator class
6
+ class TestExpandFilepathBehavior < Test::Unit::TestCase
7
+ def test_evaluation
8
+ v = CLIUtils::ExpandFilepathBehavior.new
9
+ assert_equal(v.evaluate('~/test'), "#{ ENV['HOME'] }/test")
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_behaviors/lowercase_behavior')
4
+
5
+ # Tests for the Configurator class
6
+ class TestLowercaseBehavior < Test::Unit::TestCase
7
+ def test_evaluation
8
+ v = CLIUtils::LowercaseBehavior.new
9
+ assert_equal(v.evaluate('BaChYa'), 'bachya')
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_behaviors/prefix_behavior')
4
+
5
+ # Tests for the Configurator class
6
+ class TestPrefixBehavior < Test::Unit::TestCase
7
+ def test_evaluation
8
+ v = CLIUtils::PrefixBehavior.new
9
+ v.parameters = { prefix: 'test: ' }
10
+ assert_equal(v.evaluate('bachya'), 'test: bachya')
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_behaviors/suffix_behavior')
4
+
5
+ # Tests for the Configurator class
6
+ class TestSuffixBehavior < Test::Unit::TestCase
7
+ def test_evaluation
8
+ v = CLIUtils::SuffixBehavior.new
9
+ v.parameters = { suffix: ' - signing off!' }
10
+ assert_equal(v.evaluate('bachya'), 'bachya - signing off!')
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_behaviors/titlecase_behavior')
4
+
5
+ # Tests for the Configurator class
6
+ class TestTitlecaseBehavior < Test::Unit::TestCase
7
+ def test_evaluation
8
+ v = CLIUtils::TitlecaseBehavior.new
9
+ assert_equal(v.evaluate('my sentence is here'), 'My Sentence Is Here')
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_behaviors/uppercase_behavior')
4
+
5
+ # Tests for the Configurator class
6
+ class TestUppercaseBehavior < Test::Unit::TestCase
7
+ def test_evaluation
8
+ v = CLIUtils::UppercaseBehavior.new
9
+ assert_equal(v.evaluate('bachya'), 'BACHYA')
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/configurator')
4
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/configuration')
5
+
6
+ # Tests for the Configurator class
7
+ class TestConfiguration < Test::Unit::TestCase
8
+ include CLIUtils::Configuration
9
+
10
+ def setup
11
+ @config_path = '/tmp/test.config'
12
+ @expected_config_data = {
13
+ my_app: {
14
+ config_location: '/Users/bob/.my-app-config',
15
+ log_level: 'WARN',
16
+ version: '1.0.0'
17
+ },
18
+ user_data: {
19
+ username: 'bob',
20
+ age: 45
21
+ }
22
+ }
23
+ end
24
+
25
+ def teardown
26
+ FileUtils.rm(@config_path) if File.file?(@config_path)
27
+ end
28
+
29
+ def test_before_loading
30
+ assert_raise RuntimeError do
31
+ configuration
32
+ end
33
+ end
34
+
35
+ def test_empty_configuration
36
+ load_configuration(@config_path)
37
+ assert_equal(configuration.class, CLIUtils::Configurator)
38
+ assert_equal(configuration.config_path, @config_path)
39
+ assert_equal(configuration.data, {})
40
+ end
41
+
42
+ def test_existing_configuration
43
+ FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'test/test_files/configuration.yaml'), @config_path)
44
+ load_configuration(@config_path)
45
+ assert_equal(configuration.class, CLIUtils::Configurator)
46
+ assert_equal(configuration.config_path, @config_path)
47
+ assert_equal(configuration.data, @expected_config_data)
48
+ end
49
+ end
File without changes
@@ -0,0 +1,8 @@
1
+ ---
2
+ my_app:
3
+ config_location: "/Users/bob/.my-app-config"
4
+ log_level: WARN
5
+ version: 1.0.0
6
+ user_data:
7
+ username: bob
8
+ age: 45
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_validators/alphabetic_validator')
4
+
5
+ # Tests for the Configurator class
6
+ class TestAlphabeticValidator < Test::Unit::TestCase
7
+ def test_valid
8
+ v = CLIUtils::AlphabeticValidator.new
9
+ v.validate('bachya')
10
+
11
+ assert_equal(v.is_valid, 0)
12
+ assert_equal(v.message, 'Response is not alphabetic: bachya')
13
+ end
14
+
15
+ def test_invalid
16
+ v = CLIUtils::AlphabeticValidator.new
17
+ v.validate('12345')
18
+
19
+ assert_not_equal(v.is_valid, 0)
20
+ assert_equal(v.message, 'Response is not alphabetic: 12345')
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_validators/alphanumeric_validator')
4
+
5
+ # Tests for the Configurator class
6
+ class TestAlphanumericValidator < Test::Unit::TestCase
7
+ def test_valid
8
+ v = CLIUtils::AlphanumericValidator.new
9
+ v.validate('bachya91238 ')
10
+
11
+ assert_equal(v.is_valid, 0)
12
+ assert_equal(v.message, 'Response is not alphanumeric: bachya91238 ')
13
+ end
14
+
15
+ def test_invalid
16
+ v = CLIUtils::AlphanumericValidator.new
17
+ v.validate('!@&^')
18
+
19
+ assert_not_equal(v.is_valid, 0)
20
+ assert_equal(v.message, 'Response is not alphanumeric: !@&^')
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_validators/date_validator')
4
+
5
+ # Tests for the Configurator class
6
+ class TestDateValidator < Test::Unit::TestCase
7
+ def test_valid
8
+ v = CLIUtils::DateValidator.new
9
+ v.validate('2014-02-01')
10
+
11
+ assert_equal(v.is_valid, true)
12
+ assert_equal(v.message, 'Response is not a date: 2014-02-01')
13
+ end
14
+
15
+ def test_invalid
16
+ v = CLIUtils::DateValidator.new
17
+ v.validate('!@&^')
18
+
19
+ assert_equal(v.is_valid, false)
20
+ assert_equal(v.message, 'Response is not a date: !@&^')
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_validators/datetime_validator')
4
+
5
+ # Tests for the Configurator class
6
+ class TestDatetimeValidator < Test::Unit::TestCase
7
+ def test_valid
8
+ v = CLIUtils::DatetimeValidator.new
9
+ v.validate('2014-02-01 12:34 PM')
10
+
11
+ assert_equal(v.is_valid, true)
12
+ assert_equal(v.message, 'Response is not a datetime: 2014-02-01 12:34 PM')
13
+ end
14
+
15
+ def test_invalid
16
+ v = CLIUtils::DatetimeValidator.new
17
+ v.validate('!@&^')
18
+
19
+ assert_equal(v.is_valid, false)
20
+ assert_equal(v.message, 'Response is not a datetime: !@&^')
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_validators/filepath_exists_validator')
4
+
5
+ # Tests for the Configurator class
6
+ class TestFilepathExistsValidator < Test::Unit::TestCase
7
+ def test_valid
8
+ v = CLIUtils::FilepathExistsValidator.new
9
+ v.validate('/tmp')
10
+
11
+ assert_equal(v.is_valid, true)
12
+ assert_equal(v.message, 'Path does not exist locally: /tmp')
13
+ end
14
+
15
+ def test_invalid
16
+ v = CLIUtils::FilepathExistsValidator.new
17
+ v.validate('asdasd')
18
+
19
+ assert_equal(v.is_valid, false)
20
+ assert_equal(v.message, 'Path does not exist locally: asdasd')
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_validators/non_nil_validator')
4
+
5
+ # Tests for the Configurator class
6
+ class TestNonNilValidator < Test::Unit::TestCase
7
+ def test_valid
8
+ v = CLIUtils::NonNilValidator.new
9
+ v.validate('asdasdasd')
10
+
11
+ assert_equal(v.is_valid, true)
12
+ assert_equal(v.message, 'Nil text not allowed')
13
+ end
14
+
15
+ def test_invalid_1
16
+ v = CLIUtils::NonNilValidator.new
17
+ v.validate('')
18
+
19
+ assert_equal(v.is_valid, false)
20
+ assert_equal(v.message, 'Nil text not allowed')
21
+ end
22
+
23
+ def test_invalid_2
24
+ v = CLIUtils::NonNilValidator.new
25
+ v.validate(nil)
26
+
27
+ assert_equal(v.is_valid, false)
28
+ assert_equal(v.message, 'Nil text not allowed')
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_validators/number_validator')
4
+
5
+ # Tests for the Configurator class
6
+ class TestNumberValidator < Test::Unit::TestCase
7
+ def test_valid
8
+ v = CLIUtils::NumberValidator.new
9
+ v.validate('1234.112')
10
+
11
+ assert_equal(v.is_valid, 0)
12
+ assert_equal(v.message, 'Response is not a number: 1234.112')
13
+ end
14
+
15
+ def test_invalid
16
+ v = CLIUtils::NumberValidator.new
17
+ v.validate('abcdefg')
18
+
19
+ assert_not_equal(v.is_valid, 0)
20
+ assert_equal(v.message, 'Response is not a number: abcdefg')
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_validators/time_validator')
4
+
5
+ # Tests for the Configurator class
6
+ class TestTimeValidator < Test::Unit::TestCase
7
+ def test_valid
8
+ v = CLIUtils::TimeValidator.new
9
+ v.validate('12:43 AM')
10
+
11
+ assert_equal(v.is_valid, true)
12
+ assert_equal(v.message, 'Response is not a time: 12:43 AM')
13
+ end
14
+
15
+ def test_invalid
16
+ v = CLIUtils::TimeValidator.new
17
+ v.validate('bzzzp')
18
+
19
+ assert_equal(v.is_valid, false)
20
+ assert_equal(v.message, 'Response is not a time: bzzzp')
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/cliutils/prefs/pref_validators/url_validator')
4
+
5
+ # Tests for the Configurator class
6
+ class TestUrlValidator < Test::Unit::TestCase
7
+ def test_valid
8
+ v = CLIUtils::UrlValidator.new
9
+ v.validate('http://www.google.com')
10
+
11
+ assert_equal(v.is_valid, 0)
12
+ assert_equal(v.message, 'Response is not a url: http://www.google.com')
13
+ end
14
+
15
+ def test_invalid
16
+ v = CLIUtils::UrlValidator.new
17
+ v.validate('basdahd0283123')
18
+
19
+ assert_not_equal(v.is_valid, 0)
20
+ assert_equal(v.message, 'Response is not a url: basdahd0283123')
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bach
@@ -130,18 +130,37 @@ files:
130
130
  - res/readme-images/prettyio-red-text.png
131
131
  - res/readme-images/prompting.png
132
132
  - res/readme-images/wrapping.png
133
+ - test/action_tests/open_url_action_test.rb
134
+ - test/behavior_tests/capitalize_behavior_test.rb
135
+ - test/behavior_tests/expand_filepath_behavior_test.rb
136
+ - test/behavior_tests/lowercase_behavior_test.rb
137
+ - test/behavior_tests/prefix_behavior_test.rb
138
+ - test/behavior_tests/suffix_behavior_test.rb
139
+ - test/behavior_tests/titlecase_behavior_test.rb
140
+ - test/behavior_tests/uppercase_behavior_test.rb
141
+ - test/configuration_test.rb
133
142
  - test/configurator_test.rb
134
143
  - test/hash_extensions_test.rb
135
144
  - test/logger_extensions_test.rb
136
- - test/messenging_test.rb
145
+ - test/messaging_test.rb
137
146
  - test/pref_test.rb
138
147
  - test/prefs_test.rb
139
148
  - test/string_extesions_test.rb
149
+ - test/test_files/configuration.yaml
140
150
  - test/test_files/prefstest.yaml
141
151
  - test/test_files/test_action.rb
142
152
  - test/test_files/test_behavior.rb
143
153
  - test/test_files/test_validator.rb
144
154
  - test/test_helper.rb
155
+ - test/validator_tests/alphabetic_validator_test.rb
156
+ - test/validator_tests/alphanumeric_validator_test.rb
157
+ - test/validator_tests/date_validator_test.rb
158
+ - test/validator_tests/datetime_validator_test.rb
159
+ - test/validator_tests/filepath_exists_validator_test.rb
160
+ - test/validator_tests/non_nil_validator_test.rb
161
+ - test/validator_tests/number_validator_test.rb
162
+ - test/validator_tests/time_validator_test.rb
163
+ - test/validator_tests/url_validator_test.rb
145
164
  homepage: https://github.com/bachya/cliutils
146
165
  licenses:
147
166
  - MIT
@@ -167,16 +186,35 @@ signing_key:
167
186
  specification_version: 4
168
187
  summary: Sugary goodness for Ruby CLI apps.
169
188
  test_files:
189
+ - test/action_tests/open_url_action_test.rb
190
+ - test/behavior_tests/capitalize_behavior_test.rb
191
+ - test/behavior_tests/expand_filepath_behavior_test.rb
192
+ - test/behavior_tests/lowercase_behavior_test.rb
193
+ - test/behavior_tests/prefix_behavior_test.rb
194
+ - test/behavior_tests/suffix_behavior_test.rb
195
+ - test/behavior_tests/titlecase_behavior_test.rb
196
+ - test/behavior_tests/uppercase_behavior_test.rb
197
+ - test/configuration_test.rb
170
198
  - test/configurator_test.rb
171
199
  - test/hash_extensions_test.rb
172
200
  - test/logger_extensions_test.rb
173
- - test/messenging_test.rb
201
+ - test/messaging_test.rb
174
202
  - test/pref_test.rb
175
203
  - test/prefs_test.rb
176
204
  - test/string_extesions_test.rb
205
+ - test/test_files/configuration.yaml
177
206
  - test/test_files/prefstest.yaml
178
207
  - test/test_files/test_action.rb
179
208
  - test/test_files/test_behavior.rb
180
209
  - test/test_files/test_validator.rb
181
210
  - test/test_helper.rb
211
+ - test/validator_tests/alphabetic_validator_test.rb
212
+ - test/validator_tests/alphanumeric_validator_test.rb
213
+ - test/validator_tests/date_validator_test.rb
214
+ - test/validator_tests/datetime_validator_test.rb
215
+ - test/validator_tests/filepath_exists_validator_test.rb
216
+ - test/validator_tests/non_nil_validator_test.rb
217
+ - test/validator_tests/number_validator_test.rb
218
+ - test/validator_tests/time_validator_test.rb
219
+ - test/validator_tests/url_validator_test.rb
182
220
  has_rdoc: