nugrant 1.4.2 → 2.0.0.dev1

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.
Files changed (72) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +1 -2
  3. data/.travis.yml +0 -6
  4. data/CHANGELOG.md +3 -79
  5. data/Gemfile +8 -8
  6. data/README.md +10 -146
  7. data/lib/nugrant.rb +4 -19
  8. data/lib/nugrant/bag.rb +8 -12
  9. data/lib/nugrant/config.rb +55 -24
  10. data/lib/nugrant/helper/bag.rb +19 -17
  11. data/lib/nugrant/parameters.rb +37 -9
  12. data/lib/nugrant/vagrant/v1/command/parameters.rb +13 -13
  13. data/lib/nugrant/vagrant/v1/command/root.rb +2 -7
  14. data/lib/nugrant/vagrant/v1/config/user.rb +1 -10
  15. data/lib/nugrant/vagrant/v2/command/parameters.rb +1 -1
  16. data/lib/nugrant/vagrant/v2/command/root.rb +2 -7
  17. data/lib/nugrant/vagrant/v2/config/user.rb +1 -10
  18. data/lib/nugrant/version.rb +1 -1
  19. data/nugrant.gemspec +1 -4
  20. data/test/lib/nugrant/test_bag.rb +19 -33
  21. data/test/lib/nugrant/test_config.rb +92 -100
  22. data/test/lib/nugrant/test_parameters.rb +186 -203
  23. data/test/resources/README.md +11 -11
  24. data/test/resources/{vagrantfiles/v1.empty → Vagrantfile.v1.empty} +0 -0
  25. data/test/resources/{vagrantfiles/v1.fake → Vagrantfile.v1.fake} +0 -0
  26. data/test/resources/{vagrantfiles/v1.real → Vagrantfile.v1.real} +0 -0
  27. data/test/resources/{vagrantfiles/v2.empty → Vagrantfile.v2.empty} +0 -0
  28. data/test/resources/{vagrantfiles/v2.fake → Vagrantfile.v2.fake} +1 -4
  29. data/test/resources/{vagrantfiles/v2.real → Vagrantfile.v2.real} +0 -0
  30. data/test/resources/json/params_current_1.json +6 -0
  31. data/test/resources/json/params_current_2.json +29 -0
  32. data/test/resources/{yml → yaml}/params_array.yml +0 -0
  33. data/test/resources/{yml → yaml}/params_boolean.yml +0 -0
  34. data/test/resources/{yml → yaml}/params_combinations.yml +0 -0
  35. data/test/resources/yaml/params_current_1.yml +4 -0
  36. data/test/resources/yaml/params_current_2.yml +23 -0
  37. data/test/resources/{yml → yaml}/params_defaults_at_root.yml +0 -0
  38. data/test/resources/{yml → yaml}/params_defaults_not_at_root.yml +0 -0
  39. data/test/resources/{yml → yaml}/params_empty.yml +0 -0
  40. data/test/resources/{yml → yaml}/params_list.yml +0 -0
  41. data/test/resources/{yml → yaml}/params_simple.yml +0 -0
  42. data/test/resources/{yml → yaml}/params_system_1.yml +0 -0
  43. data/test/resources/{yml → yaml}/params_system_2.yml +0 -0
  44. data/test/resources/{yml → yaml}/params_unix_eol.yml +0 -0
  45. data/test/resources/{yml → yaml}/params_user_1.yml +0 -0
  46. data/test/resources/{yml → yaml}/params_user_2.yml +0 -0
  47. data/test/resources/{yml → yaml}/params_windows_eol.yml +0 -0
  48. metadata +71 -95
  49. data/lib/nugrant/helper/env/exporter.rb +0 -208
  50. data/lib/nugrant/helper/env/namer.rb +0 -47
  51. data/lib/nugrant/helper/stack.rb +0 -86
  52. data/lib/nugrant/vagrant/errors.rb +0 -27
  53. data/lib/nugrant/vagrant/v1/command/env.rb +0 -107
  54. data/lib/nugrant/vagrant/v2/command/env.rb +0 -107
  55. data/locales/en.yml +0 -13
  56. data/test/lib/nugrant/helper/env/test_exporter.rb +0 -238
  57. data/test/lib/nugrant/helper/test_stack.rb +0 -149
  58. data/test/resources/json/params_project_1.json +0 -6
  59. data/test/resources/json/params_project_2.json +0 -29
  60. data/test/resources/json/params_user_nil_values.json +0 -9
  61. data/test/resources/vagrantfiles/v1.defaults_mixed_string_symbols +0 -18
  62. data/test/resources/vagrantfiles/v1.defaults_using_string +0 -18
  63. data/test/resources/vagrantfiles/v1.defaults_using_symbol +0 -18
  64. data/test/resources/vagrantfiles/v1.missing_parameter +0 -3
  65. data/test/resources/vagrantfiles/v2.defaults_mixed_string_symbols +0 -20
  66. data/test/resources/vagrantfiles/v2.defaults_null_values_in_vagrantuser +0 -25
  67. data/test/resources/vagrantfiles/v2.defaults_using_string +0 -20
  68. data/test/resources/vagrantfiles/v2.defaults_using_symbol +0 -20
  69. data/test/resources/vagrantfiles/v2.missing_parameter +0 -5
  70. data/test/resources/yml/params_project_1.yml +0 -4
  71. data/test/resources/yml/params_project_2.yml +0 -23
  72. data/test/resources/yml/params_user_nil_values.yml +0 -5
@@ -1,3 +1,3 @@
1
1
  module Nugrant
2
- VERSION = "1.4.2"
2
+ VERSION = "2.0.0.dev1"
3
3
  end
@@ -25,11 +25,8 @@ Gem::Specification.new do |gem|
25
25
 
26
26
  gem.files = `git ls-files`.split($/)
27
27
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
28
- gem.test_files = gem.files.grep(%r{^(test/lib)/})
28
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
29
29
  gem.require_paths = ["lib"]
30
30
 
31
- gem.add_dependency "multi_json", "~> 1.8"
32
-
33
31
  gem.add_development_dependency "rake"
34
- gem.add_development_dependency "minitest", "~> 5.0.8"
35
32
  end
@@ -1,23 +1,11 @@
1
- require 'minitest/autorun'
1
+ require 'test/unit'
2
2
 
3
3
  require 'nugrant/bag'
4
4
 
5
5
  module Nugrant
6
- class TestBag < ::Minitest::Test
7
- def create_bag(elements)
8
- return Bag.new(elements)
9
- end
10
-
11
- def assert_all_access_equal(value, bag, key)
12
- assert_equal(value, bag.method_missing(key.to_sym), "bag.#{key.to_sym.inspect}")
13
- assert_equal(value, bag[key.to_s], "bag[#{key.to_s.inspect}]")
14
- assert_equal(value, bag[key.to_sym], "bag[#{key.to_sym.inspect}]")
15
- end
16
-
17
- def assert_all_access_bag(value, bag, key)
18
- assert_bag(value, bag.method_missing(key.to_sym))
19
- assert_bag(value, bag[key.to_s])
20
- assert_bag(value, bag[key.to_sym])
6
+ class TestBag < Test::Unit::TestCase
7
+ def create_bag(parameters)
8
+ return Bag.new(parameters)
21
9
  end
22
10
 
23
11
  def assert_bag(parameters, bag)
@@ -25,11 +13,13 @@ module Nugrant
25
13
 
26
14
  parameters.each do |key, value|
27
15
  if not value.kind_of?(Hash)
28
- assert_all_access_equal(value, bag, key)
16
+ assert_equal(value, bag.send(key))
17
+ assert_equal(value, bag[key])
29
18
  next
30
19
  end
31
20
 
32
- assert_all_access_bag(value, bag, key)
21
+ assert_bag(value, bag.send(key))
22
+ assert_bag(value, bag[key])
33
23
  end
34
24
  end
35
25
 
@@ -84,17 +74,13 @@ module Nugrant
84
74
  def test_undefined_value()
85
75
  bag = create_bag({"value" => "one"})
86
76
 
87
- assert_raises(KeyError) do
77
+ assert_raise(KeyError) do
88
78
  bag.invalid_value
89
79
  end
90
80
 
91
- assert_raises(KeyError) do
81
+ assert_raise(KeyError) do
92
82
  bag["invalid_value"]
93
83
  end
94
-
95
- assert_raises(KeyError) do
96
- bag[:invalid_value]
97
- end
98
84
  end
99
85
 
100
86
  def test_to_hash()
@@ -103,29 +89,29 @@ module Nugrant
103
89
  assert_kind_of(Hash, hash)
104
90
  assert_equal({}, hash)
105
91
 
106
- hash = create_bag({"value" => {:one => "value", "two" => "value"}}).__to_hash()
92
+ hash = create_bag({"value" => {"one" => "value", "two" => "value"}}).__to_hash()
107
93
 
108
94
  assert_kind_of(Hash, hash)
109
- assert_kind_of(Hash, hash[:value])
110
- assert_kind_of(String, hash[:value][:one])
111
- assert_kind_of(String, hash[:value][:two])
112
- assert_equal({:value => {:one => "value", :two => "value"}}, hash)
95
+ assert_kind_of(Hash, hash['value'])
96
+ assert_kind_of(String, hash['value']['one'])
97
+ assert_kind_of(String, hash['value']['two'])
98
+ assert_equal({"value" => {"one" => "value", "two" => "value"}}, hash)
113
99
  end
114
100
 
115
101
  def test_merge_array()
116
102
  bag1 = create_bag({"first" => [1, 2]})
117
- bag2 = create_bag({:first => [2, 3]})
103
+ bag2 = create_bag({"first" => [2, 3]})
118
104
 
119
105
  bag1.__merge!(bag2);
120
106
 
121
- assert_equal({:first => [1, 2, 3]}, bag1.__to_hash())
107
+ assert_equal({"first" => [1, 2, 3]}, bag1.__to_hash())
122
108
 
123
109
  bag1 = create_bag({"first" => [1, 2]})
124
- bag2 = create_bag({:first => "string"})
110
+ bag2 = create_bag({"first" => "string"})
125
111
 
126
112
  bag1.__merge!(bag2);
127
113
 
128
- assert_equal({:first => "string"}, bag1.__to_hash())
114
+ assert_equal({"first" => "string"}, bag1.__to_hash())
129
115
  end
130
116
  end
131
117
  end
@@ -1,128 +1,120 @@
1
- require 'minitest/autorun'
2
- require 'tmpdir'
3
-
4
1
  require 'nugrant/config'
2
+ require 'test/unit'
3
+ require 'tmpdir'
5
4
 
6
- module Nugrant
7
- class TestConfig < ::Minitest::Test
8
- def setup
9
- @default_param_filename = Nugrant::Config::DEFAULT_PARAMS_FILENAME
5
+ class Nugrant::TestConfig < Test::Unit::TestCase
6
+ def setup
7
+ @default_param_filename = Nugrant::Config::DEFAULT_PARAMS_FILENAME
10
8
 
11
- @old_working_dir = Dir.getwd()
12
- @user_dir = Nugrant::Config.user_base_path()
13
- @system_dir = Nugrant::Config.system_base_path()
9
+ @old_working_dir = Dir.getwd()
10
+ @user_dir = Nugrant::Config.default_user_path()
11
+ @system_dir = Nugrant::Config.default_system_path()
14
12
 
15
- Dir.chdir(Dir.tmpdir())
13
+ Dir.chdir(Dir.tmpdir())
16
14
 
17
- @project_dir = Dir.getwd()
18
- end
19
-
20
- def teardown
21
- Dir.chdir(@old_working_dir)
15
+ @current_dir = Dir.getwd()
16
+ end
22
17
 
23
- @old_working_dir = nil
24
- @project_dir = nil
25
- @user_dir = nil
26
- @system_dir = nil
27
- end
18
+ def teardown
19
+ Dir.chdir(@old_working_dir)
28
20
 
29
- def test_default_values
30
- config = Nugrant::Config.new
21
+ @old_working_dir = nil
22
+ @current_dir = nil
23
+ @user_dir = nil
24
+ @system_dir = nil
25
+ end
31
26
 
32
- assert_equal(@default_param_filename, config.params_filename())
33
- assert_equal("#{@project_dir}/#{@default_param_filename}", config.project_params_path())
34
- assert_equal("#{@user_dir}/#{@default_param_filename}", config.user_params_path())
35
- assert_equal("#{@system_dir}/#{@default_param_filename}", config.system_params_path())
36
- end
27
+ def test_default_values
28
+ config = Nugrant::Config.new()
37
29
 
38
- def test_custom_params_filename
39
- config = Nugrant::Config.new({:params_filename => ".customparams"})
30
+ assert_equal(@default_param_filename, config.params_filename())
31
+ assert_equal("#{@current_dir}/#{@default_param_filename}", config.current_path())
32
+ assert_equal("#{@user_dir}/#{@default_param_filename}", config.user_path())
33
+ assert_equal("#{@system_dir}/#{@default_param_filename}", config.system_path())
34
+ end
40
35
 
41
- assert_equal(".customparams", config.params_filename())
42
- assert_equal("#{@project_dir}/.customparams", config.project_params_path())
43
- assert_equal("#{@user_dir}/.customparams", config.user_params_path())
44
- assert_equal("#{@system_dir}/.customparams", config.system_params_path())
45
- end
36
+ def test_custom_params_filename
37
+ config = Nugrant::Config.new({:params_filename => ".customparams"})
46
38
 
47
- def test_custom_params_filename_after_creation
48
- config = Nugrant::Config.new({:params_filename => ".vagrantuser"})
39
+ assert_equal(".customparams", config.params_filename())
40
+ assert_equal("#{@current_dir}/.customparams", config.current_path())
41
+ assert_equal("#{@user_dir}/.customparams", config.user_path())
42
+ assert_equal("#{@system_dir}/.customparams", config.system_path())
43
+ end
49
44
 
50
- config.params_filename = ".customparams"
45
+ def test_custom_current_path
46
+ config = Nugrant::Config.new({
47
+ :params_filename => ".customparams",
48
+ :current_path => "#{@user_dir}/.currentcustomparams"
49
+ })
51
50
 
52
- assert_equal(".customparams", config.params_filename())
53
- assert_equal("#{@project_dir}/.customparams", config.project_params_path())
54
- assert_equal("#{@user_dir}/.customparams", config.user_params_path())
55
- assert_equal("#{@system_dir}/.customparams", config.system_params_path())
56
- end
57
-
58
- def test_custom_project_params_path
59
- config = Nugrant::Config.new({
60
- :params_filename => ".customparams",
61
- :project_params_path => "#{@user_dir}/.projectcustomparams"
62
- })
51
+ assert_equal(".customparams", config.params_filename())
52
+ assert_equal("#{@user_dir}/.currentcustomparams", config.current_path())
53
+ end
63
54
 
64
- assert_equal(".customparams", config.params_filename())
65
- assert_equal("#{@user_dir}/.projectcustomparams", config.project_params_path())
66
- end
55
+ def test_custom_user_path
56
+ config = Nugrant::Config.new({
57
+ :params_filename => ".customparams",
58
+ :user_path => "#{@system_dir}/.usercustomparams"
59
+ })
67
60
 
68
- def test_custom_user_params_path
69
- config = Nugrant::Config.new({
70
- :params_filename => ".customparams",
71
- :user_params_path => "#{@system_dir}/.usercustomparams"
72
- })
61
+ assert_equal(".customparams", config.params_filename())
62
+ assert_equal("#{@system_dir}/.usercustomparams", config.user_path()) end
73
63
 
74
- assert_equal(".customparams", config.params_filename())
75
- assert_equal("#{@system_dir}/.usercustomparams", config.user_params_path()) end
64
+ def test_custom_system_path
65
+ config = Nugrant::Config.new({
66
+ :params_filename => ".customparams",
67
+ :system_path => "#{@current_dir}/.systemcustomparams"
68
+ })
76
69
 
77
- def test_custom_system_params_path
78
- config = Nugrant::Config.new({
79
- :params_filename => ".customparams",
80
- :system_params_path => "#{@project_dir}/.systemcustomparams"
81
- })
70
+ assert_equal(".customparams", config.params_filename())
71
+ assert_equal("#{@current_dir}/.systemcustomparams", config.system_path())
72
+ end
82
73
 
83
- assert_equal(".customparams", config.params_filename())
84
- assert_equal("#{@project_dir}/.systemcustomparams", config.system_params_path())
85
- end
74
+ def test_custom_all
75
+ config = Nugrant::Config.new({
76
+ :params_filename => ".customparams",
77
+ :current_path => "#{@user_dir}/.currentcustomparams",
78
+ :user_path => "#{@system_dir}/.usercustomparams",
79
+ :system_path => "#{@current_dir}/.systemcustomparams"
80
+ })
81
+
82
+ assert_equal(".customparams", config.params_filename())
83
+ assert_equal("#{@user_dir}/.currentcustomparams", config.current_path())
84
+ assert_equal("#{@system_dir}/.usercustomparams", config.user_path())
85
+ assert_equal("#{@current_dir}/.systemcustomparams", config.system_path())
86
+ end
86
87
 
87
- def test_custom_all
88
- config = Nugrant::Config.new({
89
- :params_filename => ".customparams",
90
- :project_params_path => "#{@user_dir}/.projectcustomparams",
91
- :user_params_path => "#{@system_dir}/.usercustomparams",
92
- :system_params_path => "#{@project_dir}/.systemcustomparams"
93
- })
94
-
95
- assert_equal(".customparams", config.params_filename())
96
- assert_equal("#{@user_dir}/.projectcustomparams", config.project_params_path())
97
- assert_equal("#{@system_dir}/.usercustomparams", config.user_params_path())
98
- assert_equal("#{@project_dir}/.systemcustomparams", config.system_params_path())
99
- end
88
+ def test_nil_current
89
+ config = Nugrant::Config.new({
90
+ :params_filename => ".customparams",
91
+ :current_path => nil,
92
+ })
100
93
 
101
- def test_nil_project
102
- config = Nugrant::Config.new({
103
- :params_filename => ".customparams",
104
- :project_params_path => nil,
105
- })
94
+ assert_not_nil("#{@current_dir}/.customparams", config.current_path())
95
+ end
106
96
 
107
- assert_equal("#{@project_dir}/.customparams", config.project_params_path())
108
- end
97
+ def test_nil_user
98
+ config = Nugrant::Config.new({
99
+ :params_filename => ".customparams",
100
+ :user_path => nil,
101
+ })
109
102
 
110
- def test_nil_user
111
- config = Nugrant::Config.new({
112
- :params_filename => ".customparams",
113
- :user_params_path => nil,
114
- })
103
+ assert_equal("#{@user_dir}/.customparams", config.user_path())
104
+ end
115
105
 
116
- assert_equal("#{@user_dir}/.customparams", config.user_params_path())
117
- end
106
+ def test_nil_system
107
+ config = Nugrant::Config.new({
108
+ :params_filename => ".customparams",
109
+ :system_path => nil,
110
+ })
118
111
 
119
- def test_nil_system
120
- config = Nugrant::Config.new({
121
- :params_filename => ".customparams",
122
- :system_params_path => nil,
123
- })
112
+ assert_equal("#{@system_dir}/.customparams", config.system_path())
113
+ end
124
114
 
125
- assert_equal("#{@system_dir}/.customparams", config.system_params_path())
115
+ def test_invalid_format
116
+ assert_raise(ArgumentError) do
117
+ Nugrant::Config.new({:params_format => :invalid})
126
118
  end
127
119
  end
128
120
  end
@@ -1,257 +1,240 @@
1
- require 'minitest/autorun'
2
-
3
1
  require 'nugrant'
4
2
  require 'nugrant/parameters'
3
+ require 'test/unit'
4
+
5
+ class Nugrant::TestParameters < Test::Unit::TestCase
6
+ @@FORMATS = [:json, :yaml]
7
+ @@INVALID_PATH = "impossible_file_path.yamljson.impossible"
8
+
9
+ def create_parameters(format, current_filename, user_filename, system_filename)
10
+ extension = case
11
+ when format = :json
12
+ "json"
13
+ when format = :yaml
14
+ "yml"
15
+ else
16
+ raise ArgumentError, "Format [#{format}] is currently not supported"
17
+ end
18
+
19
+ resource_path = File.expand_path("#{File.dirname(__FILE__)}/../../resources/#{format}")
20
+
21
+ current_path = "#{resource_path}/#{current_filename}.#{extension}" if current_filename
22
+ user_path = "#{resource_path}/#{user_filename}.#{extension}" if user_filename
23
+ system_path = "#{resource_path}/#{system_filename}.#{extension}" if system_filename
24
+
25
+ return Nugrant::Parameters.new({
26
+ :config => {
27
+ :format => format,
28
+ :current_path => current_path,
29
+ :user_path => user_path,
30
+ :system_path => system_path,
31
+ },
32
+ })
33
+ end
5
34
 
6
- module Nugrant
7
- class TestParameters < ::Minitest::Test
8
-
9
- @@PARAMS_FILETYPES = [:json, :yml]
10
- @@INVALID_PATH = "impossible_file_path.yml.impossible"
35
+ def assert_level(parameters, results)
36
+ results.each do |key, value|
37
+ assert_equal(value, parameters.send(key), "array[#{key}]")
38
+ assert_equal(value, parameters[key], "array[#{key}]")
39
+ end
11
40
 
12
- def create_parameters(params_filetype, project_params_filename, user_params_filename, system_params_filename)
13
- resource_path = File.expand_path("#{File.dirname(__FILE__)}/../../resources/#{params_filetype.to_s()}")
41
+ assert_key_error(parameters, "0.0.0")
42
+ end
14
43
 
15
- project_params_path = "#{resource_path}/#{project_params_filename}.#{params_filetype}" if project_params_filename
16
- user_params_path = "#{resource_path}/#{user_params_filename}.#{params_filetype}" if user_params_filename
17
- system_params_path = "#{resource_path}/#{system_params_filename}.#{params_filetype}" if system_params_filename
44
+ def assert_key_error(parameters, key)
45
+ assert_raise(KeyError) do
46
+ parameters[key]
47
+ end
48
+ end
18
49
 
19
- return Nugrant::create_parameters({
20
- :params_filetype => params_filetype,
21
- :project_params_path => project_params_path,
22
- :user_params_path => user_params_path,
23
- :system_params_path => system_params_path
50
+ def test_params_level_1()
51
+ formats.each do |format|
52
+ parameters = create_parameters(format, "params_current_1", "params_user_1", "params_system_1")
53
+
54
+ assert_level(parameters, {
55
+ "1.1.1" => "current",
56
+ "1.1.0" => "current",
57
+ "1.0.1" => "current",
58
+ "0.1.1" => "user",
59
+ "1.0.0" => "current",
60
+ "0.1.0" => "user",
61
+ "0.0.1" => "system",
24
62
  })
25
63
  end
64
+ end
26
65
 
27
- def assert_all_access_equal(value, parameters, key)
28
- assert_equal(value, parameters.method_missing(key.to_sym), "parameters.#{key.to_sym.inspect}")
29
- assert_equal(value, parameters[key.to_s], "parameters[#{key.to_s.inspect}]")
30
- assert_equal(value, parameters[key.to_sym], "parameters[#{key.to_sym.inspect}]")
31
- end
66
+ def test_params_level_2()
67
+ formats.each do |format|
68
+ parameters = create_parameters(format, "params_current_2", "params_user_2", "params_system_2")
69
+
70
+ run_second_level(parameters, "1.1.1", {
71
+ "1.1.1" => "current",
72
+ "1.1.0" => "current",
73
+ "1.0.1" => "current",
74
+ "0.1.1" => "user",
75
+ "1.0.0" => "current",
76
+ "0.1.0" => "user",
77
+ "0.0.1" => "system",
78
+ })
32
79
 
33
- def assert_level(parameters, results)
34
- results.each do |key, value|
35
- assert_all_access_equal(value, parameters, key)
36
- end
80
+ run_second_level(parameters, "1.1.0", {
81
+ "1.1.1" => "current",
82
+ "1.1.0" => "current",
83
+ "1.0.1" => "current",
84
+ "0.1.1" => "user",
85
+ "1.0.0" => "current",
86
+ "0.1.0" => "user",
87
+ })
37
88
 
38
- assert_key_error(parameters, "0.0.0")
39
- end
89
+ run_second_level(parameters, "1.0.1", {
90
+ "1.1.1" => "current",
91
+ "1.1.0" => "current",
92
+ "1.0.1" => "current",
93
+ "0.1.1" => "system",
94
+ "1.0.0" => "current",
95
+ "0.0.1" => "system",
96
+ })
40
97
 
41
- def assert_key_error(parameters, key)
42
- assert_raises(KeyError) do
43
- parameters[key]
44
- end
45
- end
98
+ run_second_level(parameters, "0.1.1", {
99
+ "1.1.1" => "user",
100
+ "1.1.0" => "user",
101
+ "1.0.1" => "system",
102
+ "0.1.1" => "user",
103
+ "0.1.0" => "user",
104
+ "0.0.1" => "system",
105
+ })
46
106
 
47
- def test_params_level_1()
48
- filetypes.each do |params_filetype|
49
- parameters = create_parameters(params_filetype, "params_project_1", "params_user_1", "params_system_1")
50
-
51
- assert_level(parameters, {
52
- "1.1.1" => "project",
53
- "1.1.0" => "project",
54
- "1.0.1" => "project",
55
- "0.1.1" => "user",
56
- "1.0.0" => "project",
57
- "0.1.0" => "user",
58
- "0.0.1" => "system",
59
- })
60
- end
61
- end
107
+ run_second_level(parameters, "1.0.0", {
108
+ "1.1.1" => "current",
109
+ "1.1.0" => "current",
110
+ "1.0.1" => "current",
111
+ "1.0.0" => "current",
112
+ })
62
113
 
63
- def test_params_level_2()
64
- filetypes.each do |params_filetype|
65
- parameters = create_parameters(params_filetype, "params_project_2", "params_user_2", "params_system_2")
66
-
67
- run_second_level(parameters, "1.1.1", {
68
- "1.1.1" => "project",
69
- "1.1.0" => "project",
70
- "1.0.1" => "project",
71
- "0.1.1" => "user",
72
- "1.0.0" => "project",
73
- "0.1.0" => "user",
74
- "0.0.1" => "system",
75
- })
76
-
77
- run_second_level(parameters, "1.1.0", {
78
- "1.1.1" => "project",
79
- "1.1.0" => "project",
80
- "1.0.1" => "project",
81
- "0.1.1" => "user",
82
- "1.0.0" => "project",
83
- "0.1.0" => "user",
84
- })
85
-
86
- run_second_level(parameters, "1.0.1", {
87
- "1.1.1" => "project",
88
- "1.1.0" => "project",
89
- "1.0.1" => "project",
90
- "0.1.1" => "system",
91
- "1.0.0" => "project",
92
- "0.0.1" => "system",
93
- })
94
-
95
- run_second_level(parameters, "0.1.1", {
96
- "1.1.1" => "user",
97
- "1.1.0" => "user",
98
- "1.0.1" => "system",
99
- "0.1.1" => "user",
100
- "0.1.0" => "user",
101
- "0.0.1" => "system",
102
- })
103
-
104
- run_second_level(parameters, "1.0.0", {
105
- "1.1.1" => "project",
106
- "1.1.0" => "project",
107
- "1.0.1" => "project",
108
- "1.0.0" => "project",
109
- })
110
-
111
- run_second_level(parameters, "0.1.0", {
112
- "1.1.1" => "user",
113
- "1.1.0" => "user",
114
- "0.1.1" => "user",
115
- "0.1.0" => "user",
116
- })
117
-
118
- run_second_level(parameters, "0.0.1", {
119
- "1.1.1" => "system",
120
- "1.0.1" => "system",
121
- "0.1.1" => "system",
122
- "0.0.1" => "system",
123
- })
124
-
125
- assert_key_error(parameters, "0.0.0")
126
- end
127
- end
114
+ run_second_level(parameters, "0.1.0", {
115
+ "1.1.1" => "user",
116
+ "1.1.0" => "user",
117
+ "0.1.1" => "user",
118
+ "0.1.0" => "user",
119
+ })
128
120
 
129
- def run_second_level(parameters, key, results)
130
- assert_level(parameters.send(key), results)
131
- assert_level(parameters[key], results)
121
+ run_second_level(parameters, "0.0.1", {
122
+ "1.1.1" => "system",
123
+ "1.0.1" => "system",
124
+ "0.1.1" => "system",
125
+ "0.0.1" => "system",
126
+ })
132
127
 
133
128
  assert_key_error(parameters, "0.0.0")
134
129
  end
130
+ end
135
131
 
136
- def test_params_array()
137
- file_path = "params_array"
138
- filetypes.each do |params_filetype|
139
- parameters = create_parameters(params_filetype, file_path, invalid_path, invalid_path)
132
+ def run_second_level(parameters, key, results)
133
+ assert_level(parameters.send(key), results)
134
+ assert_level(parameters[key], results)
140
135
 
141
- assert_equal(["1", "2", "3"], parameters['level1']['level2'])
142
- end
143
- end
136
+ assert_key_error(parameters, "0.0.0")
137
+ end
144
138
 
145
- def test_file_nil()
146
- run_test_file_invalid(nil)
147
- end
139
+ def test_params_array()
140
+ file_path = "params_array"
141
+ formats.each do |format|
142
+ parameters = create_parameters(format, file_path, invalid_path, invalid_path)
148
143
 
149
- def test_file_does_not_exist()
150
- run_test_file_invalid("impossible_file_path.yml.impossible")
144
+ assert_equal(["1", "2", "3"], parameters['level1']['level2'])
151
145
  end
146
+ end
152
147
 
153
- def run_test_file_invalid(invalid_value)
154
- filetypes.each do |params_filetype|
155
- parameters = create_parameters(params_filetype, "params_simple", invalid_path, invalid_path)
156
- assert_all_access_equal("value", parameters, "test")
148
+ def test_file_nil()
149
+ run_test_file_invalid(nil)
150
+ end
157
151
 
158
- parameters = create_parameters(params_filetype, invalid_path, "params_simple", invalid_path)
159
- assert_all_access_equal("value", parameters, "test")
152
+ def test_file_does_not_exist()
153
+ run_test_file_invalid("impossible_file_path.yml.impossible")
154
+ end
160
155
 
161
- parameters = create_parameters(params_filetype, invalid_path, invalid_path, "params_simple")
162
- assert_all_access_equal("value", parameters, "test")
156
+ def run_test_file_invalid(invalid_value)
157
+ formats.each do |format|
158
+ parameters = create_parameters(format, "params_simple", invalid_path, invalid_path)
159
+ assert_equal("value", parameters["test"])
163
160
 
164
- parameters = create_parameters(params_filetype, invalid_path, invalid_path, invalid_path)
165
- assert(parameters)
166
- end
167
- end
161
+ parameters = create_parameters(format, invalid_path, "params_simple", invalid_path)
162
+ assert_equal("value", parameters["test"])
168
163
 
169
- def test_params_windows_eol()
170
- run_test_params_eol("params_windows_eol")
171
- end
164
+ parameters = create_parameters(format, invalid_path, invalid_path, "params_simple")
165
+ assert_equal("value", parameters["test"])
172
166
 
173
- def test_params_unix_eol()
174
- run_test_params_eol("params_unix_eol")
175
- end
176
-
177
- def run_test_params_eol(file_path)
178
- filetypes.each do |params_filetype|
179
- parameters = create_parameters(params_filetype, file_path, invalid_path, invalid_path)
180
-
181
- assert_all_access_equal("value1", parameters, 'level1')
182
- assert_all_access_equal("value2", parameters['level2'], 'first')
183
- end
167
+ parameters = create_parameters(format, invalid_path, invalid_path, invalid_path)
168
+ assert_not_nil(parameters)
184
169
  end
170
+ end
185
171
 
186
- def test_restricted_defaults_usage()
187
- filetypes.each do |params_filetype|
188
- parameters = create_parameters(params_filetype, "params_defaults_at_root", invalid_path, invalid_path)
172
+ def test_params_windows_eol()
173
+ run_test_params_eol("params_windows_eol")
174
+ end
189
175
 
190
- assert_all_access_equal("value", parameters, :defaults)
191
- end
176
+ def test_params_unix_eol()
177
+ run_test_params_eol("params_unix_eol")
178
+ end
192
179
 
193
- filetypes.each do |params_filetype|
194
- parameters = create_parameters(params_filetype, "params_defaults_not_at_root", invalid_path, invalid_path)
180
+ def run_test_params_eol(file_path)
181
+ formats.each do |format|
182
+ parameters = create_parameters(format, file_path, invalid_path, invalid_path)
195
183
 
196
- assert_all_access_equal("value", parameters.level, :defaults)
197
- end
184
+ assert_equal("value1", parameters['level1'])
185
+ assert_equal("value2", parameters['level2']['first'])
198
186
  end
187
+ end
199
188
 
200
- def test_defaults()
201
- filetypes.each do |params_filetype|
202
- parameters = create_parameters(params_filetype, "params_simple", invalid_path, invalid_path)
203
- parameters.defaults = {"test" => "override1", "level" => "new1"}
189
+ def test_restricted_defaults_usage()
190
+ formats.each do |format|
191
+ parameters = create_parameters(format, "params_defaults_at_root", invalid_path, invalid_path)
204
192
 
205
- assert_all_access_equal("value", parameters, 'test')
206
- assert_all_access_equal("new1", parameters, 'level')
207
- end
193
+ assert_equal("value", parameters.defaults)
208
194
  end
209
195
 
210
- def test_empty_file()
211
- filetypes.each do |params_filetype|
212
- parameters = create_parameters(params_filetype, "params_empty", invalid_path, invalid_path)
213
- parameters.defaults = {"test" => "value"}
196
+ formats.each do |format|
197
+ parameters = create_parameters(format, "params_defaults_not_at_root", invalid_path, invalid_path)
214
198
 
215
- assert_all_access_equal("value", parameters, 'test')
216
- end
199
+ assert_equal("value", parameters.level.defaults)
217
200
  end
201
+ end
218
202
 
219
- def test_file_not_hash()
220
- ["boolean", "list"].each do |wrong_type|
221
- filetypes.each do |params_filetype|
222
- parameters = create_parameters(params_filetype, "params_#{wrong_type}", invalid_path, invalid_path)
223
- parameters.defaults = {"test" => "value"}
203
+ def test_defaults()
204
+ formats.each do |format|
205
+ parameters = create_parameters(format, "params_simple", invalid_path, invalid_path)
206
+ parameters.defaults = {"test" => "override1", "level" => "new1"}
224
207
 
225
- assert_all_access_equal("value", parameters, 'test')
226
- end
227
- end
208
+ assert_equal("value", parameters['test'])
209
+ assert_equal("new1", parameters['level'])
228
210
  end
211
+ end
229
212
 
230
- def test_nil_values()
231
- filetypes.each do |params_filetype|
232
- parameters = create_parameters(params_filetype, "params_user_nil_values", invalid_path, invalid_path)
233
- parameters.defaults = {:nil => "Not nil", :deep => {:nil => "Not nil", :deeper => {:nil => "Not nil"}}}
213
+ def test_empty_file()
214
+ formats.each do |format|
215
+ parameters = create_parameters(format, "params_empty", invalid_path, invalid_path)
216
+ parameters.defaults = {"test" => "value"}
234
217
 
235
- assert_all_access_equal("Not nil", parameters[:deep][:deeper], :nil)
236
- assert_all_access_equal("Not nil", parameters[:deep], :nil)
237
- assert_all_access_equal("Not nil", parameters, :nil)
238
- end
218
+ assert_equal("value", parameters['test'])
219
+ end
220
+ end
239
221
 
240
- filetypes.each do |params_filetype|
241
- parameters = create_parameters(params_filetype, "params_user_nil_values", invalid_path, invalid_path)
222
+ def test_file_not_hash()
223
+ ["boolean", "list"].each do |wrong_type|
224
+ formats.each do |format|
225
+ parameters = create_parameters(format, "params_#{wrong_type}", invalid_path, invalid_path)
226
+ parameters.defaults = {"test" => "value"}
242
227
 
243
- assert_all_access_equal(nil, parameters[:deep][:deeper], :nil)
244
- assert_all_access_equal(nil, parameters[:deep], :nil)
245
- assert_all_access_equal(nil, parameters, :nil)
228
+ assert_equal("value", parameters['test'])
246
229
  end
247
230
  end
231
+ end
248
232
 
249
- def filetypes()
250
- @@PARAMS_FILETYPES
251
- end
233
+ def formats()
234
+ @@FORMATS
235
+ end
252
236
 
253
- def invalid_path()
254
- @@INVALID_PATH
255
- end
237
+ def invalid_path()
238
+ @@INVALID_PATH
256
239
  end
257
240
  end