ehbrs-tools 0.6.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/executables.rb +7 -1
  3. data/lib/ehbrs/fs.rb +9 -0
  4. data/lib/ehbrs/fs/compressed_package.rb +48 -0
  5. data/lib/ehbrs/gems.rb +37 -0
  6. data/lib/ehbrs/google.rb +9 -0
  7. data/lib/ehbrs/google/translate.rb +11 -0
  8. data/lib/ehbrs/google/translate/session.rb +61 -0
  9. data/lib/ehbrs/observers.rb +11 -0
  10. data/lib/ehbrs/observers/base.rb +64 -0
  11. data/lib/ehbrs/observers/with_persistence.rb +34 -0
  12. data/lib/ehbrs/runner/fs.rb +19 -0
  13. data/lib/ehbrs/runner/fs/used_space.rb +161 -0
  14. data/lib/ehbrs/runner/google.rb +19 -0
  15. data/lib/ehbrs/runner/google/translate.rb +92 -0
  16. data/lib/ehbrs/runner/self.rb +19 -0
  17. data/lib/ehbrs/runner/self/test.rb +30 -0
  18. data/lib/ehbrs/runner/videos/extract.rb +71 -0
  19. data/lib/ehbrs/runner/videos/series.rb +21 -0
  20. data/lib/ehbrs/runner/videos/series/rename.rb +75 -0
  21. data/lib/ehbrs/self.rb +9 -0
  22. data/lib/ehbrs/self/observers/used_space.rb +22 -0
  23. data/lib/ehbrs/self/observers/with_persistence.rb +38 -0
  24. data/lib/ehbrs/tools/version.rb +1 -1
  25. data/lib/ehbrs/user_dirs.rb +34 -0
  26. data/lib/ehbrs/vg/wii/game_file.rb +13 -0
  27. data/lib/ehbrs/videos/extract.rb +11 -0
  28. data/lib/ehbrs/videos/extract/package.rb +75 -0
  29. data/lib/ehbrs/videos/extract/package_file.rb +54 -0
  30. data/lib/ehbrs/videos/series.rb +11 -0
  31. data/lib/ehbrs/videos/series/rename.rb +13 -0
  32. data/lib/ehbrs/videos/series/rename/directory_group.rb +28 -0
  33. data/lib/ehbrs/videos/series/rename/file.rb +114 -0
  34. data/lib/ehbrs/videos/series/rename/file/basename_parser.rb +44 -0
  35. data/lib/ehbrs/videos/series/rename/file/options.rb +30 -0
  36. data/lib/ehbrs/videos/series/rename/line_result.rb +26 -0
  37. data/lib/ehbrs/videos/series/rename/line_result_group.rb +39 -0
  38. data/lib/ehbrs/videos/series/rename/results_builder.rb +32 -0
  39. data/lib/ehbrs/videos/series/rename/season_group.rb +39 -0
  40. data/vendor/aranha-selenium/Gemfile +5 -0
  41. data/vendor/aranha-selenium/aranha-selenium.gemspec +19 -0
  42. data/vendor/aranha-selenium/lib/aranha/selenium.rb +8 -0
  43. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory.rb +47 -0
  44. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/base.rb +76 -0
  45. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/chrome.rb +28 -0
  46. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox.rb +54 -0
  47. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox_auto_download_mime_types +685 -0
  48. data/vendor/aranha-selenium/lib/aranha/selenium/session.rb +78 -0
  49. data/vendor/aranha-selenium/lib/aranha/selenium/version.rb +7 -0
  50. data/vendor/aranha-selenium/spec/rubocop_check_spec.rb +7 -0
  51. data/vendor/aranha-selenium/spec/spec_helper.rb +100 -0
  52. data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +1 -1
  53. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +68 -0
  54. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb +4 -12
  55. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +1 -1
  56. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
  57. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker.rb +1 -1
  58. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +2 -2
  59. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb +30 -0
  60. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp.rb +27 -8
  61. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/directory.rb +16 -0
  62. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/file.rb +34 -0
  63. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +4 -0
  64. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +10 -12
  65. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/symbol_list.rb +19 -0
  66. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb +4 -0
  67. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb +45 -0
  68. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb +10 -0
  69. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +1 -1
  70. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +2 -2
  71. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +1 -1
  72. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp.rb +4 -0
  73. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/if_match.rb +16 -0
  74. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time.rb +4 -0
  75. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb +5 -0
  76. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb +25 -0
  77. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +1 -3
  78. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +45 -2
  79. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  80. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +85 -2
  81. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +42 -0
  82. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +1 -0
  83. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb +5 -5
  84. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb +1 -1
  85. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +4 -0
  86. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/extname_spec.rb +18 -0
  87. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/temp_spec.rb +12 -0
  88. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/{temp.rb → temp_spec.rb} +22 -0
  89. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +32 -0
  90. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +1 -1
  91. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb +39 -0
  92. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +1 -1
  93. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +1 -1
  94. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec.rb +1 -1
  95. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_sub_spec.rb +4 -4
  96. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb +19 -0
  97. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_module_a.rb +6 -0
  98. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_not_module.rb +6 -0
  99. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec.rb +1 -1
  100. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/yaml_spec.rb +75 -0
  101. data/vendor/eac_ruby_utils/spec/locales/pt-BR.yml +17 -0
  102. metadata +105 -3
@@ -27,6 +27,7 @@ RSpec.describe ::EacRubyUtils::CommonConstructor do
27
27
  it "attribute \"#{attr}\" equal to \"#{expected_value}\"" do
28
28
  expect(subject.send(attr)).to eq(expected_value)
29
29
  end
30
+
30
31
  [false, true].each do |include_all|
31
32
  it "respond_to?('#{attr}', #{include_all}) == #{include_all}" do
32
33
  expect(subject.respond_to?("#{attr}=", include_all)).to eq(include_all)
@@ -66,7 +66,7 @@ RSpec.describe ::EacRubyUtils::Console::DocoptRunner do
66
66
 
67
67
  let(:instance) { RunnerWithSubcommands.new }
68
68
 
69
- context '#subcommands?' do
69
+ describe '#subcommands?' do
70
70
  it 'returns true' do
71
71
  expect(instance.subcommands?).to eq(true)
72
72
  end
@@ -85,19 +85,19 @@ RSpec.describe ::EacRubyUtils::Console::DocoptRunner do
85
85
  it { expect(instance.target_doc).to include('Subcommands:') }
86
86
  end
87
87
 
88
- context '#subcommand' do
88
+ describe '#subcommand' do
89
89
  it 'is of subcommand class' do
90
90
  expect(instance.subcommand).to be_a(RunnerWithSubcommands::MySubCommand)
91
91
  end
92
92
  end
93
93
 
94
- context '#context' do
94
+ describe '#context' do
95
95
  it 'accesses instance methods by subcommand' do
96
96
  expect(instance.subcommand.context(:parent_arg)).to eq('value0')
97
97
  end
98
98
  end
99
99
 
100
- context '#run' do
100
+ describe '#run' do
101
101
  it 'calls subcommand' do
102
102
  instance.run
103
103
  expect(instance.subarg_value).to eq('value1')
@@ -109,7 +109,7 @@ RSpec.describe ::EacRubyUtils::Console::DocoptRunner do
109
109
  context 'when subcommand is invalid' do
110
110
  let(:instance) { RunnerWithSubcommands.new(argv: %w[value0 invalid-subcommand]) }
111
111
 
112
- context '#run' do
112
+ describe '#run' do
113
113
  it 'raises Docopt::Exit' do
114
114
  expect { instance.run }.to raise_error(::Docopt::Exit)
115
115
  end
@@ -9,7 +9,7 @@ RSpec.describe ::EacRubyUtils::Console::Speaker do
9
9
  r
10
10
  end
11
11
 
12
- context '#request_input' do
12
+ describe '#request_input' do
13
13
  it 'recover value from hash list' do
14
14
  allow(instance).to receive(:request_string).and_return('opt1')
15
15
  list = { opt1: 'value1', opt2: 'value2' }
@@ -5,6 +5,7 @@ require 'eac_ruby_utils/envs/local_env'
5
5
 
6
6
  RSpec.describe ::EacRubyUtils::Envs::Executable do
7
7
  let(:env) { ::EacRubyUtils::Envs::LocalEnv.new }
8
+
8
9
  context 'when program exist' do
9
10
  let(:instance) { described_class.new(env, 'cat', '--version') }
10
11
 
@@ -18,12 +19,15 @@ RSpec.describe ::EacRubyUtils::Envs::Executable do
18
19
  let(:instance) { described_class.new(env, 'this_cannot_exist', '--version') }
19
20
 
20
21
  it { expect(instance.exist?).to eq(false) }
22
+
21
23
  it {
22
24
  expect { instance.validate! }.to raise_error(
23
25
  described_class.const_get('ProgramNotFoundError')
24
26
  )
25
27
  }
28
+
26
29
  it { expect(instance.validate).to be_present }
30
+
27
31
  it {
28
32
  expect { instance.command }.to raise_error(
29
33
  described_class.const_get('ProgramNotFoundError')
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/fs/extname'
4
+
5
+ RSpec.describe ::EacRubyUtils::Fs do
6
+ describe '#extname' do
7
+ {
8
+ 'After.Life.S01E01.WEBRip.x264-ION10.mp4' => '.mp4',
9
+ 's01e01.en.srt' => '.en.srt',
10
+ 's01e01.srt' => '.srt',
11
+ '/path/to/file.tar.gz' => '.tar.gz'
12
+ }.each do |source, expected|
13
+ context "when source is \"#{source}\"" do
14
+ it { expect(described_class.extname(source)).to eq(expected) }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/fs/temp/directory'
4
+
5
+ RSpec.describe ::EacRubyUtils::Fs::Temp::Directory do
6
+ describe '#remove!' do
7
+ let(:instance) { described_class.new }
8
+
9
+ it { expect(instance).to be_directory }
10
+ it { expect { instance.remove! }.not_to raise_error }
11
+ end
12
+ end
@@ -27,4 +27,26 @@ RSpec.describe ::EacRubyUtils::Fs::Temp do
27
27
  expect(temp_path).not_to exist
28
28
  end
29
29
  end
30
+
31
+ describe '#on_directory' do
32
+ it do
33
+ temp_path = nil
34
+ described_class.on_directory do |path|
35
+ temp_path = path
36
+ expect(temp_path).to be_directory
37
+ end
38
+ expect(temp_path).not_to exist
39
+ end
40
+
41
+ it 'not fail if already removed' do
42
+ temp_path = nil
43
+ described_class.on_directory do |path|
44
+ temp_path = path
45
+ expect(temp_path).to be_directory
46
+ temp_path.rmtree
47
+ expect(temp_path).not_to exist
48
+ end
49
+ expect(temp_path).not_to exist
50
+ end
51
+ end
30
52
  end
@@ -11,6 +11,8 @@ class Stub
11
11
  lists.add_integer :code, 7 => :a, 13 => :b
12
12
  lists.add_string :cadeia, :a, :b, :c
13
13
  lists.add_string :type, 'Namespace::ClazzA' => :a, 'Namespace::ClazzB' => :b
14
+ lists.add_symbol :simbolo, :a, :b, :c
15
+ lists.add_symbol :tipado, :tipo_aaa => :a, 'tipo_bbb' => :b
14
16
  end
15
17
 
16
18
  RSpec.describe ::EacRubyUtils::Listable do
@@ -19,6 +21,8 @@ RSpec.describe ::EacRubyUtils::Listable do
19
21
  it { expect(Stub.lists.code.values).to eq([7, 13]) }
20
22
  it { expect(Stub.lists.cadeia.values).to eq(%w[a b c]) }
21
23
  it { expect(Stub.lists.type.values).to eq(%w[Namespace::ClazzA Namespace::ClazzB]) }
24
+ it { expect(Stub.lists.simbolo.values).to eq(%i[a b c]) }
25
+ it { expect(Stub.lists.tipado.values).to eq(%i[tipo_aaa tipo_bbb]) }
22
26
  end
23
27
 
24
28
  context 'value instance options' do
@@ -26,18 +30,31 @@ RSpec.describe ::EacRubyUtils::Listable do
26
30
  expect(Stub.lists.inteiro.options)
27
31
  .to eq([['Inteiro A', 1], ['Inteiro BB', 2], ['Inteiro CCC', 3]])
28
32
  }
33
+
29
34
  it {
30
35
  expect(Stub.lists.code.options)
31
36
  .to eq([['Código A', 7], ['Código B', 13]])
32
37
  }
38
+
33
39
  it {
34
40
  expect(Stub.lists.cadeia.options)
35
41
  .to eq([['Cadeia AAA', 'a'], ['Cadeia BB', 'b'], ['Cadeia C', 'c']])
36
42
  }
43
+
37
44
  it {
38
45
  expect(Stub.lists.type.options)
39
46
  .to eq([['Tipo A', 'Namespace::ClazzA'], ['Tipo B', 'Namespace::ClazzB']])
40
47
  }
48
+
49
+ it {
50
+ expect(Stub.lists.simbolo.options)
51
+ .to eq([['Simbolo A', :a], ['Simbolo B', :b], ['Simbolo C', :c]])
52
+ }
53
+
54
+ it {
55
+ expect(Stub.lists.tipado.options)
56
+ .to eq([['Tipado A', :tipo_aaa], ['Tipado B', :tipo_bbb]])
57
+ }
41
58
  end
42
59
 
43
60
  context 'constants' do
@@ -50,6 +67,11 @@ RSpec.describe ::EacRubyUtils::Listable do
50
67
  it { expect(Stub::CADEIA_C).to eq('c') }
51
68
  it { expect(Stub::TYPE_A).to eq('Namespace::ClazzA') }
52
69
  it { expect(Stub::TYPE_B).to eq('Namespace::ClazzB') }
70
+ it { expect(Stub::SIMBOLO_A).to eq(:a) }
71
+ it { expect(Stub::SIMBOLO_B).to eq(:b) }
72
+ it { expect(Stub::SIMBOLO_C).to eq(:c) }
73
+ it { expect(Stub::TIPADO_A).to eq(:tipo_aaa) }
74
+ it { expect(Stub::TIPADO_B).to eq(:tipo_bbb) }
53
75
  end
54
76
 
55
77
  context 'values instances' do
@@ -110,60 +132,70 @@ RSpec.describe ::EacRubyUtils::Listable do
110
132
 
111
133
  context 'when inteiro value is A' do
112
134
  before { instance.inteiro = Stub::INTEIRO_A }
135
+
113
136
  it { expect(instance.inteiro_label).to eq('Inteiro A') }
114
137
  it { expect(instance.inteiro_description).to eq('Inteiro A Descr.') }
115
138
  end
116
139
 
117
140
  context 'when inteiro value is A' do
118
141
  before { instance.inteiro = Stub::INTEIRO_B }
142
+
119
143
  it { expect(instance.inteiro_label).to eq('Inteiro BB') }
120
144
  it { expect(instance.inteiro_description).to eq('Inteiro BB Descr.') }
121
145
  end
122
146
 
123
147
  context 'when inteiro value is C' do
124
148
  before { instance.inteiro = Stub::INTEIRO_C }
149
+
125
150
  it { expect(instance.inteiro_label).to eq('Inteiro CCC') }
126
151
  it { expect(instance.inteiro_description).to eq('Inteiro CCC Descr.') }
127
152
  end
128
153
 
129
154
  context 'when code value is A' do
130
155
  before { instance.code = Stub::CODE_A }
156
+
131
157
  it { expect(instance.code_label).to eq('Código A') }
132
158
  it { expect(instance.code_description).to eq('Código A Descr.') }
133
159
  end
134
160
 
135
161
  context 'when code value is B' do
136
162
  before { instance.code = Stub::CODE_B }
163
+
137
164
  it { expect(instance.code_label).to eq('Código B') }
138
165
  it { expect(instance.code_description).to eq('Código B Descr.') }
139
166
  end
140
167
 
141
168
  context 'when cadeia value is A' do
142
169
  before { instance.cadeia = Stub::CADEIA_A }
170
+
143
171
  it { expect(instance.cadeia_label).to eq('Cadeia AAA') }
144
172
  it { expect(instance.cadeia_description).to eq('Cadeia AAA Descr.') }
145
173
  end
146
174
 
147
175
  context 'when cadeia value is B' do
148
176
  before { instance.cadeia = Stub::CADEIA_B }
177
+
149
178
  it { expect(instance.cadeia_label).to eq('Cadeia BB') }
150
179
  it { expect(instance.cadeia_description).to eq('Cadeia BB Descr.') }
151
180
  end
152
181
 
153
182
  context 'when cadeia value is C' do
154
183
  before { instance.cadeia = Stub::CADEIA_C }
184
+
155
185
  it { expect(instance.cadeia_label).to eq('Cadeia C') }
156
186
  it { expect(instance.cadeia_description).to eq('Cadeia C Descr.') }
157
187
  end
158
188
 
159
189
  context 'when type value is A' do
160
190
  before { instance.type = Stub::TYPE_A }
191
+
161
192
  it { expect(instance.type_label).to eq('Tipo A') }
162
193
  it { expect(instance.type_description).to eq('Tipo A Descr.') }
163
194
  end
164
195
 
165
196
  context 'when type value is B' do
166
197
  before { instance.type = Stub::TYPE_B }
198
+
167
199
  it { expect(instance.type_label).to eq('Tipo B') }
168
200
  it { expect(instance.type_description).to eq('Tipo B Descr.') }
169
201
  end
@@ -31,7 +31,7 @@ RSpec.describe ::EacRubyUtils::OptionsConsumer do
31
31
  end
32
32
  end
33
33
 
34
- context '#consume_all' do
34
+ describe '#consume_all' do
35
35
  subject(:instance) { described_class.new(a: 'a_value', b: 'b_value', c: 'c_value') }
36
36
 
37
37
  it 'return all options in arguments' do
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/enumerable/boolean_combinations'
4
+
5
+ RSpec.describe ::Enumerable do
6
+ let(:empty_instance) { [].to_enum }
7
+ let(:a_instance) { [:a].to_enum }
8
+ let(:ab_instance) { %i[a b].to_enum }
9
+
10
+ describe '#bool_hash_combs' do
11
+ it do
12
+ expect(empty_instance.bool_hash_combs).to eq([])
13
+ end
14
+
15
+ it do
16
+ expect(a_instance.bool_hash_combs).to eq([{ a: false }, { a: true }])
17
+ end
18
+
19
+ it do
20
+ expect(ab_instance.bool_hash_combs)
21
+ .to eq([{ a: false, b: false }, { a: false, b: true }, { a: true, b: false },
22
+ { a: true, b: true }])
23
+ end
24
+ end
25
+
26
+ describe '#bool_array_combs' do
27
+ it do
28
+ expect(empty_instance.bool_array_combs).to eq([])
29
+ end
30
+
31
+ it do
32
+ expect(a_instance.bool_array_combs).to eq([[], [:a]])
33
+ end
34
+
35
+ it do
36
+ expect(ab_instance.bool_array_combs).to eq([[], [:a], [:b], %i[a b]])
37
+ end
38
+ end
39
+ end
@@ -5,7 +5,7 @@ require 'eac_ruby_utils/patches/hash/sym_keys_hash'
5
5
  RSpec.describe ::Hash do
6
6
  let(:a_hash) { { 'a' => 'a_value', 1 => '1_value', s: 's_value' } }
7
7
 
8
- context '#to_sym_keys_hash' do
8
+ describe '#to_sym_keys_hash' do
9
9
  it 'converts all keys to symbols' do
10
10
  expect(a_hash.to_sym_keys_hash).to eq(a: 'a_value', '1': '1_value', s: 's_value')
11
11
  end
@@ -3,7 +3,7 @@
3
3
  require 'eac_ruby_utils/patches/object/if_present'
4
4
 
5
5
  RSpec.describe ::Object do
6
- context '#if_present' do
6
+ describe '#if_present' do
7
7
  it { expect(nil.if_present).to eq(nil) }
8
8
  it { expect(nil.if_present('default')) .to eq('default') }
9
9
  it { expect(nil.if_present('default') { |_v| 'calculated' }).to eq('default') }
@@ -17,7 +17,7 @@ RSpec.describe ::Object do
17
17
  ::EacRubyUtils::Templates::Searcher.default.included_paths.delete(templates_path)
18
18
  end
19
19
 
20
- context '#template' do
20
+ describe '#template' do
21
21
  it { expect(instance.template).to be_a(::EacRubyUtils::Templates::File) }
22
22
  end
23
23
  end
@@ -4,14 +4,14 @@ require 'eac_ruby_utils/patches/pathname/basename_sub'
4
4
 
5
5
  RSpec.describe ::Pathname do
6
6
  it do
7
- expect(::Pathname.new('/absolute/path/to/file').basename_sub { |_b| 'other_file' }).to eq(
8
- ::Pathname.new('/absolute/path/to/other_file')
7
+ expect(described_class.new('/absolute/path/to/file').basename_sub { |_b| 'other_file' }).to eq(
8
+ described_class.new('/absolute/path/to/other_file')
9
9
  )
10
10
  end
11
11
 
12
12
  it do
13
- expect(::Pathname.new('file').basename_sub { |b| b.to_s + '_appended' }).to eq(
14
- ::Pathname.new('file_appended')
13
+ expect(described_class.new('file').basename_sub { |b| b.to_s + '_appended' }).to eq(
14
+ described_class.new('file_appended')
15
15
  )
16
16
  end
17
17
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ RSpec.describe ::EacRubyUtils::RequireSub do
6
+ class RequireSubStubClass
7
+ end
8
+
9
+ let(:instance) { described_class.new(__FILE__, base: RequireSubStubClass, include_modules: true) }
10
+
11
+ before do
12
+ instance.apply
13
+ end
14
+
15
+ it do
16
+ expect(RequireSubStubClass.included_modules)
17
+ .to include(RequireSubStubClass::StubbedModuleA)
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RequireSubStubClass
4
+ module StubbedModuleA
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RequireSubStubClass
4
+ class StubbedNotModule
5
+ end
6
+ end
@@ -20,7 +20,7 @@ RSpec.describe ::EacRubyUtils::Templates::Searcher do
20
20
  }.each do |klass, subpaths|
21
21
  subpaths.each do |subpath|
22
22
  context "when subpath is \"#{subpath}\"" do
23
- it "should return a #{klass}'s instance" do
23
+ it "returns a #{klass}'s instance" do
24
24
  expect(instance.template(subpath, false)).to be_a(klass)
25
25
  end
26
26
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/hash_with_indifferent_access'
4
+ require 'eac_ruby_utils/yaml'
5
+
6
+ RSpec.describe ::EacRubyUtils::Yaml do
7
+ let(:unpermitted_class) do
8
+ Class.new do
9
+ def initialize(value)
10
+ @value = value
11
+ end
12
+
13
+ def to_s
14
+ @value.to_s
15
+ end
16
+ end
17
+ end
18
+
19
+ let(:arrayliable_class) do
20
+ Class.new do
21
+ def initialize(value)
22
+ @value = value
23
+ end
24
+
25
+ def to_a
26
+ [@value]
27
+ end
28
+ end
29
+ end
30
+
31
+ let(:source) do
32
+ {
33
+ a: 'a', b: :b, c: false, d: true, e: nil,
34
+ f: [
35
+ 'f',
36
+ {
37
+ g: 'g',
38
+ h: ::ActiveSupport::HashWithIndifferentAccess.new(
39
+ 'i' => ['i', unpermitted_class.new('j')],
40
+ k: arrayliable_class.new('k')
41
+ )
42
+ }
43
+ ]
44
+ }
45
+ end
46
+
47
+ let(:target) do
48
+ {
49
+ a: 'a', b: :b, c: false, d: true, e: nil,
50
+ f: ['f', { g: 'g', h: { i: %w[i j], k: ['k'] } }]
51
+ }
52
+ end
53
+
54
+ describe '#dump' do
55
+ it { expect(described_class.load(described_class.dump(source))).to eq(target) }
56
+ end
57
+
58
+ describe '#sanitize' do
59
+ it { expect(described_class.sanitize(target)).to eq(target) }
60
+ end
61
+
62
+ describe '#yaml' do
63
+ {
64
+ ['text'] => false,
65
+ 'text' => false,
66
+ "--- Text\n\n" => true,
67
+ "---\n" + ":index: 0\n" + ":codec_name: h264\n" + ":codec_type: video\n" => true,
68
+ '--- - \n bla bla bla' => false
69
+ }.each do |source, result|
70
+ it "return #{result} to source \"#{source}\"" do
71
+ expect(described_class.yaml?(source)).to eq(result)
72
+ end
73
+ end
74
+ end
75
+ end