ehbrs-tools 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +13 -0
- data/exe/ehbrs +6 -0
- data/lib/ehbrs.rb +7 -0
- data/lib/ehbrs/executables.rb +28 -0
- data/lib/ehbrs/tools.rb +9 -0
- data/lib/ehbrs/tools/runner.rb +35 -0
- data/lib/ehbrs/tools/runner/vg.rb +26 -0
- data/lib/ehbrs/tools/runner/vg/ips.rb +90 -0
- data/lib/ehbrs/tools/runner/videos.rb +25 -0
- data/lib/ehbrs/tools/runner/videos/unsupported.rb +65 -0
- data/lib/ehbrs/tools/version.rb +7 -0
- data/lib/ehbrs/videos.rb +9 -0
- data/lib/ehbrs/videos/convert_job.rb +99 -0
- data/lib/ehbrs/videos/file.rb +70 -0
- data/lib/ehbrs/videos/profiles/base.rb +35 -0
- data/lib/ehbrs/videos/profiles/same_quality.rb +21 -0
- data/lib/ehbrs/videos/track.rb +27 -0
- data/lib/ehbrs/videos/unsupported/check_result.rb +24 -0
- data/lib/ehbrs/videos/unsupported/check_set.rb +43 -0
- data/lib/ehbrs/videos/unsupported/check_support.rb +68 -0
- data/lib/ehbrs/videos/unsupported/checks.rb +13 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +27 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +26 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +23 -0
- data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +25 -0
- data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +25 -0
- data/lib/ehbrs/videos/unsupported/file.rb +50 -0
- data/lib/ehbrs/videos/unsupported/file/fix.rb +45 -0
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +56 -0
- data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +36 -0
- data/lib/ehbrs/videos/unsupported/fixes/supported_container.rb +17 -0
- data/lib/ehbrs/videos/unsupported/profiles.rb +13 -0
- data/lib/ehbrs/videos/unsupported/profiles/base.rb +102 -0
- data/lib/ehbrs/videos/unsupported/profiles/philco.rb +27 -0
- data/lib/ehbrs/videos/unsupported/profiles/samsung.rb +32 -0
- data/lib/ehbrs/videos/unsupported/search.rb +72 -0
- data/lib/ehbrs/videos/unsupported/track.rb +32 -0
- data/vendor/eac_cli/Gemfile +5 -0
- data/vendor/eac_cli/eac_cli.gemspec +18 -0
- data/vendor/eac_cli/lib/eac_cli.rb +7 -0
- data/vendor/eac_cli/lib/eac_cli/default_runner.rb +22 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +30 -0
- data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner/base_option.rb +22 -0
- data/vendor/eac_cli/lib/eac_cli/runner/boolean_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner/definition.rb +60 -0
- data/vendor/eac_cli/lib/eac_cli/runner/docopt_doc.rb +65 -0
- data/vendor/eac_cli/lib/eac_cli/runner/positional_argument.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +5 -0
- data/vendor/eac_cli/spec/rubocop_spec.rb +7 -0
- data/vendor/eac_cli/spec/spec_helper.rb +100 -0
- data/vendor/eac_ruby_utils/Gemfile +16 -0
- data/vendor/eac_ruby_utils/MIT-LICENCE +16 -0
- data/vendor/eac_ruby_utils/README.rdoc +3 -0
- data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/arguments_consumer.rb +81 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +133 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb +82 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +66 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +135 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +39 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_doc.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_settings.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +139 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker.rb +134 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker/_class_methods.rb +39 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker/list.rb +63 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker/node.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/contextualizable.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/core_ext.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/base_env.rb +28 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +155 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +46 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +51 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/file.rb +22 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/local_env.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/process.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +72 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/filesystem_traverser.rb +56 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb +11 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/class_methods.rb +14 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/instance_methods.rb +30 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/integer_list.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +89 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +61 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/string_list.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +38 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/on_clean_ruby_environment.rb +23 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/options_consumer.rb +62 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patch.rb +11 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/class/common_constructor.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/options_consumer.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/hash/sym_keys_hash.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/console_speaker.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/listable.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/simple_cache.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb +14 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +12 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +95 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +11 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec/conditional.rb +38 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/rspec/stubbed_ssh.rb +44 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/settings_provider.rb +65 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +42 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/directory.rb +104 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/file.rb +101 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/templates/searcher.rb +55 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/arguments_consumer_spec.rb +17 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +36 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +31 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/configs_spec.rb +14 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb +136 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb +36 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +33 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/ssh_env_spec.rb +25 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/filesystem_cache_spec.rb +32 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +180 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +45 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/options_consumer_spec.rb +17 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/console_speaker_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/listable_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/module/simple_cache_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +13 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec.rb +23 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec_files/path/my_stub_with_template +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +49 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/settings_provider_spec.rb +46 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/simple_cache_spec.rb +102 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec.rb +34 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec_files/expected_content +2 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/file_spec_files/source.template +2 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec.rb +30 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec_files/path1/subdir1/file1.template +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec_files/path1/subdir1/file2 +1 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec_files/path2/subdir1/file3.template +1 -0
- data/vendor/eac_ruby_utils/spec/locales/pt-BR.yml +38 -0
- data/vendor/eac_ruby_utils/spec/spec_helper.rb +12 -0
- metadata +227 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/arguments_consumer'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::ArgumentsConsumer do
|
6
|
+
let(:instance) { described_class.new(%i[a b c d], d: 'd_value') }
|
7
|
+
let(:args) { ['a_value', 'b_value', e: 'e_value'] }
|
8
|
+
let(:result) { instance.parse(args) }
|
9
|
+
|
10
|
+
it { expect(result).to be_a(::Hash) }
|
11
|
+
it { expect(result.count).to eq(5) }
|
12
|
+
it { expect(result.fetch(:a)).to eq('a_value') }
|
13
|
+
it { expect(result.fetch(:b)).to eq('b_value') }
|
14
|
+
it { expect(result.fetch(:c)).to eq(nil) }
|
15
|
+
it { expect(result.fetch(:d)).to eq('d_value') }
|
16
|
+
it { expect(result.fetch(:e)).to eq('e_value') }
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/common_constructor'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::CommonConstructor do
|
6
|
+
ARG_LIST = %i[a b c d].freeze
|
7
|
+
let(:instance) do
|
8
|
+
described_class.new(*ARG_LIST, default: %w[Vcc Vd]) do
|
9
|
+
@z = 'Vz'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class MyClass
|
14
|
+
attr_reader :z
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:subject) { MyClass.new('Va', 'Vb', 'Vc') }
|
18
|
+
|
19
|
+
before do
|
20
|
+
instance.setup_class(::MyClass)
|
21
|
+
end
|
22
|
+
|
23
|
+
it { expect(subject.z).to eq('Vz') }
|
24
|
+
|
25
|
+
ARG_LIST.each do |attr|
|
26
|
+
expected_value = "V#{attr}"
|
27
|
+
it "attribute \"#{attr}\" equal to \"#{expected_value}\"" do
|
28
|
+
expect(subject.send(attr)).to eq(expected_value)
|
29
|
+
end
|
30
|
+
[false, true].each do |include_all|
|
31
|
+
it "respond_to?('#{attr}', #{include_all}) == #{include_all}" do
|
32
|
+
expect(subject.respond_to?("#{attr}=", include_all)).to eq(include_all)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
require 'eac_ruby_utils/configs'
|
5
|
+
|
6
|
+
RSpec.describe ::EacRubyUtils::Configs do
|
7
|
+
let(:configs_key) { 'configsspec' }
|
8
|
+
let(:storage_path) do
|
9
|
+
file = ::Tempfile.new(configs_key)
|
10
|
+
path = file.path
|
11
|
+
file.close
|
12
|
+
file.unlink
|
13
|
+
path
|
14
|
+
end
|
15
|
+
let(:instance) { described_class.new(configs_key, storage_path: storage_path) }
|
16
|
+
|
17
|
+
describe '#storage_path' do
|
18
|
+
it { expect(instance.storage_path).to eq(storage_path) }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#write' do
|
22
|
+
let(:entry_key) { 'parent.child' }
|
23
|
+
|
24
|
+
before do
|
25
|
+
instance[entry_key] = 'value1'
|
26
|
+
instance.save
|
27
|
+
end
|
28
|
+
|
29
|
+
it { expect(::YAML.load_file(storage_path)).to eq(parent: { child: 'value1' }) }
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/configs'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::Console::Configs do
|
6
|
+
describe '#entry_key_to_envvar_name' do
|
7
|
+
{
|
8
|
+
'a.entry.value' => 'A_ENTRY_VALUE',
|
9
|
+
'appli-cation_0.var_one' => 'APPLICATION_0_VAR_ONE'
|
10
|
+
}.each do |input, expected_result|
|
11
|
+
it { expect(described_class.entry_key_to_envvar_name(input)).to eq(expected_result) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::Console::DocoptRunner do
|
6
|
+
context 'runner without DOC constant' do
|
7
|
+
class RunnerWithoutDocConstant < ::EacRubyUtils::Console::DocoptRunner
|
8
|
+
def run
|
9
|
+
# Do nothing
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:options) { { argv: [] } }
|
14
|
+
|
15
|
+
it 'raises exception if doc argument is not supplied' do
|
16
|
+
expect { RunnerWithoutDocConstant.new(options) }.to raise_error(::StandardError)
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'doc argument is supplied' do
|
20
|
+
let(:doc) do
|
21
|
+
<<~DOCUMENT
|
22
|
+
Runner without doc constant.
|
23
|
+
|
24
|
+
Usage:
|
25
|
+
__PROGRAM__
|
26
|
+
DOCUMENT
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:options_with_doc) { options.merge(doc: doc) }
|
30
|
+
|
31
|
+
it 'reads doc from arguments' do
|
32
|
+
expect { RunnerWithoutDocConstant.new(options_with_doc) }.not_to raise_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'doc with subcommands' do
|
38
|
+
class RunnerWithSubcommands < ::EacRubyUtils::Console::DocoptRunner
|
39
|
+
attr_accessor :subarg_value, :suboption_value
|
40
|
+
|
41
|
+
DOC = <<~DOCUMENT
|
42
|
+
A root runner with subcommands.
|
43
|
+
|
44
|
+
Usage:
|
45
|
+
__PROGRAM__ <parent-arg> __SUBCOMMANDS__
|
46
|
+
DOCUMENT
|
47
|
+
|
48
|
+
def parent_arg
|
49
|
+
options.fetch('<parent-arg>')
|
50
|
+
end
|
51
|
+
|
52
|
+
class MySubCommand < ::EacRubyUtils::Console::DocoptRunner
|
53
|
+
DOC = <<~DOCUMENT
|
54
|
+
A root runner with subcommands.
|
55
|
+
|
56
|
+
Usage:
|
57
|
+
__PROGRAM__ [--suboption=<suboption-value] <subarg-value>
|
58
|
+
DOCUMENT
|
59
|
+
|
60
|
+
def run
|
61
|
+
parent.suboption_value = options.fetch('--suboption')
|
62
|
+
parent.subarg_value = options.fetch('<subarg-value>')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
let(:instance) { RunnerWithSubcommands.new }
|
68
|
+
|
69
|
+
context '#subcommands?' do
|
70
|
+
it 'returns true' do
|
71
|
+
expect(instance.subcommands?).to eq(true)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when subcommand is valid' do
|
76
|
+
let(:instance) do
|
77
|
+
RunnerWithSubcommands.new(argv: %w[value0 my-sub-command value1 --suboption value2])
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#subcommand_arg_as_list?' do
|
81
|
+
it { expect(instance.subcommand_arg_as_list?).to eq(false) }
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#target_doc' do
|
85
|
+
it { expect(instance.target_doc).to include('Subcommands:') }
|
86
|
+
end
|
87
|
+
|
88
|
+
context '#subcommand' do
|
89
|
+
it 'is of subcommand class' do
|
90
|
+
expect(instance.subcommand).to be_a(RunnerWithSubcommands::MySubCommand)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context '#context' do
|
95
|
+
it 'accesses instance methods by subcommand' do
|
96
|
+
expect(instance.subcommand.context(:parent_arg)).to eq('value0')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context '#run' do
|
101
|
+
it 'calls subcommand' do
|
102
|
+
instance.run
|
103
|
+
expect(instance.subarg_value).to eq('value1')
|
104
|
+
expect(instance.suboption_value).to eq('value2')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'when subcommand is invalid' do
|
110
|
+
let(:instance) { RunnerWithSubcommands.new(argv: %w[value0 invalid-subcommand]) }
|
111
|
+
|
112
|
+
context '#run' do
|
113
|
+
it 'raises Docopt::Exit' do
|
114
|
+
expect { instance.run }.to raise_error(::Docopt::Exit)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when subcommand as arg list is enabled' do
|
120
|
+
let(:argv) { %w[value0 my-sub-command value1 --suboption value2] }
|
121
|
+
let(:instance) { RunnerWithSubcommands.new(argv: argv, subcommand_arg_as_list: true) }
|
122
|
+
|
123
|
+
describe '#subcommand_arg_as_list?' do
|
124
|
+
it { expect(instance.subcommand_arg_as_list?).to eq(true) }
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#target_doc' do
|
128
|
+
it { expect(instance.target_doc).to include('(my-sub-command)') }
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#subcommand_name' do
|
132
|
+
it { expect(instance.subcommand_name).to eq('my-sub-command') }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/console/speaker'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::Console::Speaker do
|
6
|
+
let(:instance) do
|
7
|
+
r = ::Object.new
|
8
|
+
r.extend(described_class)
|
9
|
+
r
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#request_input' do
|
13
|
+
it 'recover value from hash list' do
|
14
|
+
allow(instance).to receive(:request_string).and_return('opt1')
|
15
|
+
list = { opt1: 'value1', opt2: 'value2' }
|
16
|
+
expect(instance.request_input('Question', list: list)).to eq('value1')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'recover value from array list' do
|
20
|
+
allow(instance).to receive(:request_string).and_return('OPT1')
|
21
|
+
list = %w[opt1 opt2]
|
22
|
+
expect(instance.request_input('Question', list: list)).to eq('opt1')
|
23
|
+
end
|
24
|
+
|
25
|
+
{
|
26
|
+
'yes' => true, 'y' => true, 'Y' => true, 'NO' => false, 'no' => false, 'n' => false
|
27
|
+
}.each do |input, expected|
|
28
|
+
context "when bool: true and input is \"#{input}\"" do
|
29
|
+
it "return #{expected}" do
|
30
|
+
allow(instance).to receive(:request_string).and_return(input)
|
31
|
+
expect(instance.request_input('Question', bool: true)).to eq(expected)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/envs/executable'
|
4
|
+
require 'eac_ruby_utils/envs/local_env'
|
5
|
+
|
6
|
+
RSpec.describe ::EacRubyUtils::Envs::Executable do
|
7
|
+
let(:env) { ::EacRubyUtils::Envs::LocalEnv.new }
|
8
|
+
context 'when program exist' do
|
9
|
+
let(:instance) { described_class.new(env, 'cat', '--version') }
|
10
|
+
|
11
|
+
it { expect(instance.exist?).to eq(true) }
|
12
|
+
it { expect { instance.validate! }.not_to raise_error }
|
13
|
+
it { expect(instance.validate).to be_blank }
|
14
|
+
it { expect(instance.command).to be_a(::EacRubyUtils::Envs::Command) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when program does not exist' do
|
18
|
+
let(:instance) { described_class.new(env, 'this_cannot_exist', '--version') }
|
19
|
+
|
20
|
+
it { expect(instance.exist?).to eq(false) }
|
21
|
+
it {
|
22
|
+
expect { instance.validate! }.to raise_error(
|
23
|
+
described_class.const_get('ProgramNotFoundError')
|
24
|
+
)
|
25
|
+
}
|
26
|
+
it { expect(instance.validate).to be_present }
|
27
|
+
it {
|
28
|
+
expect { instance.command }.to raise_error(
|
29
|
+
described_class.const_get('ProgramNotFoundError')
|
30
|
+
)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/envs/ssh_env'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::Envs::SshEnv do
|
6
|
+
describe '#ssh_command_line' do
|
7
|
+
{
|
8
|
+
'eduardo@localhost' => 'ssh eduardo@localhost',
|
9
|
+
'ssh://eduardo@localhost' => 'ssh eduardo@localhost',
|
10
|
+
'ssh://eduardo@localhost:2222' => 'ssh -p 2222 eduardo@localhost',
|
11
|
+
'localhost' => 'ssh localhost'
|
12
|
+
}.each do |input, expected|
|
13
|
+
it "convert \"#{input}\" to \"#{expected}\"" do
|
14
|
+
env = described_class.new(input)
|
15
|
+
expect(env.send('ssh_command_line')).to eq(expected)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
['my user@hostname', 'http://hostname', 'ssh:/invalid-test', 'Fulano de tal'].each do |input|
|
20
|
+
it "\"#{input}\" raise error" do
|
21
|
+
expect { described_class.new(input) }.to raise_error(StandardError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'eac_ruby_utils/filesystem_cache'
|
5
|
+
|
6
|
+
RSpec.describe ::EacRubyUtils::FilesystemCache do
|
7
|
+
let(:tmpdir) { ::Dir.mktmpdir }
|
8
|
+
let(:instance) { described_class.new(tmpdir, 'instance') }
|
9
|
+
|
10
|
+
it { expect(instance.read).to be_blank }
|
11
|
+
it { expect(instance.cached?).to eq(false) }
|
12
|
+
|
13
|
+
context 'when instance is writed' do
|
14
|
+
before { instance.write('STUB') }
|
15
|
+
|
16
|
+
it { expect(instance.read).to eq('STUB') }
|
17
|
+
it { expect(instance.cached?).to eq(true) }
|
18
|
+
|
19
|
+
context 'when instance is cleared' do
|
20
|
+
before { instance.clear }
|
21
|
+
|
22
|
+
it { expect(instance.read).to be_blank }
|
23
|
+
it { expect(instance.cached?).to eq(false) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#child' do
|
28
|
+
let(:child) { instance.child('child') }
|
29
|
+
|
30
|
+
it { expect(child.path).to match(/\A#{::Regexp.quote(instance.path)}/) }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/listable'
|
4
|
+
|
5
|
+
class Stub
|
6
|
+
include ::EacRubyUtils::Listable
|
7
|
+
|
8
|
+
attr_accessor :inteiro, :code, :cadeia, :type
|
9
|
+
|
10
|
+
lists.add_integer :inteiro, :a, :b, :c
|
11
|
+
lists.add_integer :code, 7 => :a, 13 => :b
|
12
|
+
lists.add_string :cadeia, :a, :b, :c
|
13
|
+
lists.add_string :type, 'Namespace::ClazzA' => :a, 'Namespace::ClazzB' => :b
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.describe ::EacRubyUtils::Listable do
|
17
|
+
context 'attribute values' do
|
18
|
+
it { expect(Stub.lists.inteiro.values).to eq([1, 2, 3]) }
|
19
|
+
it { expect(Stub.lists.code.values).to eq([7, 13]) }
|
20
|
+
it { expect(Stub.lists.cadeia.values).to eq(%w[a b c]) }
|
21
|
+
it { expect(Stub.lists.type.values).to eq(%w[Namespace::ClazzA Namespace::ClazzB]) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'value instance options' do
|
25
|
+
it {
|
26
|
+
expect(Stub.lists.inteiro.options)
|
27
|
+
.to eq([['Inteiro A', 1], ['Inteiro BB', 2], ['Inteiro CCC', 3]])
|
28
|
+
}
|
29
|
+
it {
|
30
|
+
expect(Stub.lists.code.options)
|
31
|
+
.to eq([['Código A', 7], ['Código B', 13]])
|
32
|
+
}
|
33
|
+
it {
|
34
|
+
expect(Stub.lists.cadeia.options)
|
35
|
+
.to eq([['Cadeia AAA', 'a'], ['Cadeia BB', 'b'], ['Cadeia C', 'c']])
|
36
|
+
}
|
37
|
+
it {
|
38
|
+
expect(Stub.lists.type.options)
|
39
|
+
.to eq([['Tipo A', 'Namespace::ClazzA'], ['Tipo B', 'Namespace::ClazzB']])
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'constants' do
|
44
|
+
it { expect(Stub::INTEIRO_A).to eq(1) }
|
45
|
+
it { expect(Stub::INTEIRO_B).to eq(2) }
|
46
|
+
it { expect(Stub::INTEIRO_C).to eq(3) }
|
47
|
+
it { expect(Stub::CODE_A).to eq(7) }
|
48
|
+
it { expect(Stub::CODE_B).to eq(13) }
|
49
|
+
it { expect(Stub::CADEIA_A).to eq('a') }
|
50
|
+
it { expect(Stub::CADEIA_C).to eq('c') }
|
51
|
+
it { expect(Stub::TYPE_A).to eq('Namespace::ClazzA') }
|
52
|
+
it { expect(Stub::TYPE_B).to eq('Namespace::ClazzB') }
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'values instances' do
|
56
|
+
it { expect(Stub.lists.is_a?(::EacRubyUtils::Listable::Lists)).to eq(true) }
|
57
|
+
it { expect(Stub.lists.inteiro.value_a.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
58
|
+
it { expect(Stub.lists.inteiro.value_b.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
59
|
+
it { expect(Stub.lists.inteiro.value_c.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
60
|
+
it { expect(Stub.lists.code.value_a.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
61
|
+
it { expect(Stub.lists.code.value_b.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
62
|
+
it { expect(Stub.lists.cadeia.value_a.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
63
|
+
it { expect(Stub.lists.cadeia.value_b.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
64
|
+
it { expect(Stub.lists.cadeia.value_c.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
65
|
+
it { expect(Stub.lists.type.value_a.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
66
|
+
it { expect(Stub.lists.type.value_b.is_a?(::EacRubyUtils::Listable::Value)).to eq(true) }
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'value instance label' do
|
70
|
+
it { expect(Stub.lists.inteiro.value_a.label).to eq('Inteiro A') }
|
71
|
+
it { expect(Stub.lists.inteiro.value_b.label).to eq('Inteiro BB') }
|
72
|
+
it { expect(Stub.lists.inteiro.value_c.label).to eq('Inteiro CCC') }
|
73
|
+
it { expect(Stub.lists.code.value_a.label).to eq('Código A') }
|
74
|
+
it { expect(Stub.lists.code.value_b.label).to eq('Código B') }
|
75
|
+
it { expect(Stub.lists.cadeia.value_a.label).to eq('Cadeia AAA') }
|
76
|
+
it { expect(Stub.lists.cadeia.value_b.label).to eq('Cadeia BB') }
|
77
|
+
it { expect(Stub.lists.cadeia.value_c.label).to eq('Cadeia C') }
|
78
|
+
it { expect(Stub.lists.type.value_a.label).to eq('Tipo A') }
|
79
|
+
it { expect(Stub.lists.type.value_b.label).to eq('Tipo B') }
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'value instance description' do
|
83
|
+
it { expect(Stub.lists.inteiro.value_a.description).to eq('Inteiro A Descr.') }
|
84
|
+
it { expect(Stub.lists.inteiro.value_b.description).to eq('Inteiro BB Descr.') }
|
85
|
+
it { expect(Stub.lists.inteiro.value_c.description).to eq('Inteiro CCC Descr.') }
|
86
|
+
it { expect(Stub.lists.code.value_a.description).to eq('Código A Descr.') }
|
87
|
+
it { expect(Stub.lists.code.value_b.description).to eq('Código B Descr.') }
|
88
|
+
it { expect(Stub.lists.cadeia.value_a.description).to eq('Cadeia AAA Descr.') }
|
89
|
+
it { expect(Stub.lists.cadeia.value_b.description).to eq('Cadeia BB Descr.') }
|
90
|
+
it { expect(Stub.lists.cadeia.value_c.description).to eq('Cadeia C Descr.') }
|
91
|
+
it { expect(Stub.lists.type.value_a.description).to eq('Tipo A Descr.') }
|
92
|
+
it { expect(Stub.lists.type.value_b.description).to eq('Tipo B Descr.') }
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'value instance constant name' do
|
96
|
+
it { expect(Stub.lists.inteiro.value_a.constant_name).to eq('INTEIRO_A') }
|
97
|
+
it { expect(Stub.lists.inteiro.value_b.constant_name).to eq('INTEIRO_B') }
|
98
|
+
it { expect(Stub.lists.inteiro.value_c.constant_name).to eq('INTEIRO_C') }
|
99
|
+
it { expect(Stub.lists.code.value_a.constant_name).to eq('CODE_A') }
|
100
|
+
it { expect(Stub.lists.code.value_b.constant_name).to eq('CODE_B') }
|
101
|
+
it { expect(Stub.lists.cadeia.value_a.constant_name).to eq('CADEIA_A') }
|
102
|
+
it { expect(Stub.lists.cadeia.value_b.constant_name).to eq('CADEIA_B') }
|
103
|
+
it { expect(Stub.lists.cadeia.value_c.constant_name).to eq('CADEIA_C') }
|
104
|
+
it { expect(Stub.lists.type.value_a.constant_name).to eq('TYPE_A') }
|
105
|
+
it { expect(Stub.lists.type.value_b.constant_name).to eq('TYPE_B') }
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'instance label and descriptions' do
|
109
|
+
let(:instance) { Stub.new }
|
110
|
+
|
111
|
+
context 'when inteiro value is A' do
|
112
|
+
before { instance.inteiro = Stub::INTEIRO_A }
|
113
|
+
it { expect(instance.inteiro_label).to eq('Inteiro A') }
|
114
|
+
it { expect(instance.inteiro_description).to eq('Inteiro A Descr.') }
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when inteiro value is A' do
|
118
|
+
before { instance.inteiro = Stub::INTEIRO_B }
|
119
|
+
it { expect(instance.inteiro_label).to eq('Inteiro BB') }
|
120
|
+
it { expect(instance.inteiro_description).to eq('Inteiro BB Descr.') }
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'when inteiro value is C' do
|
124
|
+
before { instance.inteiro = Stub::INTEIRO_C }
|
125
|
+
it { expect(instance.inteiro_label).to eq('Inteiro CCC') }
|
126
|
+
it { expect(instance.inteiro_description).to eq('Inteiro CCC Descr.') }
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when code value is A' do
|
130
|
+
before { instance.code = Stub::CODE_A }
|
131
|
+
it { expect(instance.code_label).to eq('Código A') }
|
132
|
+
it { expect(instance.code_description).to eq('Código A Descr.') }
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'when code value is B' do
|
136
|
+
before { instance.code = Stub::CODE_B }
|
137
|
+
it { expect(instance.code_label).to eq('Código B') }
|
138
|
+
it { expect(instance.code_description).to eq('Código B Descr.') }
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'when cadeia value is A' do
|
142
|
+
before { instance.cadeia = Stub::CADEIA_A }
|
143
|
+
it { expect(instance.cadeia_label).to eq('Cadeia AAA') }
|
144
|
+
it { expect(instance.cadeia_description).to eq('Cadeia AAA Descr.') }
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when cadeia value is B' do
|
148
|
+
before { instance.cadeia = Stub::CADEIA_B }
|
149
|
+
it { expect(instance.cadeia_label).to eq('Cadeia BB') }
|
150
|
+
it { expect(instance.cadeia_description).to eq('Cadeia BB Descr.') }
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when cadeia value is C' do
|
154
|
+
before { instance.cadeia = Stub::CADEIA_C }
|
155
|
+
it { expect(instance.cadeia_label).to eq('Cadeia C') }
|
156
|
+
it { expect(instance.cadeia_description).to eq('Cadeia C Descr.') }
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when type value is A' do
|
160
|
+
before { instance.type = Stub::TYPE_A }
|
161
|
+
it { expect(instance.type_label).to eq('Tipo A') }
|
162
|
+
it { expect(instance.type_description).to eq('Tipo A Descr.') }
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when type value is B' do
|
166
|
+
before { instance.type = Stub::TYPE_B }
|
167
|
+
it { expect(instance.type_label).to eq('Tipo B') }
|
168
|
+
it { expect(instance.type_description).to eq('Tipo B Descr.') }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe '#value_validate!' do
|
173
|
+
it { expect { Stub.lists.inteiro.value_validate!(1) }.not_to raise_error }
|
174
|
+
it { expect { Stub.lists.inteiro.value_validate!('1') }.to raise_error }
|
175
|
+
it { expect { Stub.lists.inteiro.value_validate!(10) }.to raise_error(::StandardError) }
|
176
|
+
it { expect { Stub.lists.cadeia.value_validate!(:a) }.to raise_error }
|
177
|
+
it { expect { Stub.lists.cadeia.value_validate!('a') }.not_to raise_error }
|
178
|
+
it { expect { Stub.lists.cadeia.value_validate!(:z) }.to raise_error(::StandardError) }
|
179
|
+
end
|
180
|
+
end
|