ehbrs-tools 0.14.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/runner.rb +4 -7
  3. data/lib/ehbrs/runner/finances.rb +4 -7
  4. data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
  5. data/lib/ehbrs/runner/fs.rb +4 -7
  6. data/lib/ehbrs/runner/fs/used_space.rb +4 -5
  7. data/lib/ehbrs/runner/google.rb +4 -7
  8. data/lib/ehbrs/runner/google/translate.rb +7 -12
  9. data/lib/ehbrs/runner/self.rb +4 -7
  10. data/lib/ehbrs/runner/self/test.rb +5 -10
  11. data/lib/ehbrs/runner/vg.rb +4 -7
  12. data/lib/ehbrs/runner/vg/ips.rb +9 -14
  13. data/lib/ehbrs/runner/vg/wii.rb +10 -13
  14. data/lib/ehbrs/runner/videos.rb +3 -5
  15. data/lib/ehbrs/runner/videos/extract.rb +10 -13
  16. data/lib/ehbrs/runner/videos/probe.rb +6 -9
  17. data/lib/ehbrs/runner/videos/series.rb +5 -8
  18. data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
  19. data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
  20. data/lib/ehbrs/runner/web_utils.rb +24 -0
  21. data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
  22. data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
  23. data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
  24. data/lib/ehbrs/tools/version.rb +1 -1
  25. data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
  26. data/lib/ehbrs/videos/file.rb +4 -8
  27. data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
  28. data/lib/ehbrs/videos/track.rb +20 -10
  29. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +2 -0
  30. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +2 -0
  31. data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +2 -0
  32. data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +2 -0
  33. data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
  34. data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
  35. data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +1 -1
  36. data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
  37. data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
  38. data/vendor/aranha-parsers/Gemfile +5 -0
  39. data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
  40. data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
  41. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
  42. data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
  43. data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
  44. data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
  45. data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
  46. data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
  47. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
  48. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
  49. data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
  50. data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
  51. data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
  52. data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
  53. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
  54. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
  55. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
  56. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
  57. data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
  58. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
  59. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
  60. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
  61. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
  62. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
  63. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
  64. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
  65. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
  66. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
  67. data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
  68. data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
  69. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  70. data/vendor/eac_cli/lib/eac_cli/definition.rb +49 -22
  71. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  72. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
  73. data/vendor/eac_cli/lib/eac_cli/{parser/options_collection.rb → definition/help_formatter.rb} +20 -49
  74. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
  75. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  76. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  77. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
  78. data/vendor/eac_cli/lib/eac_cli/parser.rb +21 -3
  79. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +88 -0
  80. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  81. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  82. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  83. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  84. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
  85. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  86. data/vendor/eac_cli/lib/eac_cli/runner.rb +7 -3
  87. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +19 -2
  88. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +1 -1
  89. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
  90. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
  91. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  92. data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
  93. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +35 -0
  94. data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
  95. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +57 -40
  96. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  97. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
  98. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  99. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  100. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  101. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  102. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +7 -104
  103. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  104. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  105. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +46 -0
  106. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  107. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  108. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  109. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  110. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  111. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  112. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  113. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  114. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  115. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  116. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  117. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
  118. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +4 -0
  119. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  120. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  121. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  122. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  123. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  124. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  125. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  126. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  127. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
  128. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
  129. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
  130. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
  131. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
  132. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
  133. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
  134. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
  135. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
  136. metadata +78 -7
  137. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
  138. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
  139. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
  140. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aranha
4
+ module Parsers
5
+ class InvalidStateException < StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ module Patches
8
+ ::EacRubyUtils.require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ofx-parser'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ module Patches
8
+ module OfxParser
9
+ module OfxParser
10
+ def self.included(base)
11
+ base.class_eval do
12
+ class << self
13
+ prepend ClassMethods
14
+ end
15
+ end
16
+ end
17
+
18
+ module ClassMethods
19
+ def build_transaction(transaction)
20
+ r = super
21
+ r.currate = (transaction / 'CURRENCY/CURRATE').inner_text
22
+ r
23
+ end
24
+ end
25
+ end
26
+
27
+ module Transaction
28
+ attr_accessor :currate, :cursym
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ require 'eac_ruby_utils/patch'
36
+
37
+ ::EacRubyUtils.patch(::OfxParser::OfxParser, ::Aranha::Parsers::Patches::OfxParser::OfxParser)
38
+ ::EacRubyUtils.patch(::OfxParser::Transaction, ::Aranha::Parsers::Patches::OfxParser::Transaction)
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/module/delegation'
4
+ require 'eac_ruby_utils/require_sub'
5
+ require 'yaml'
6
+
7
+ module Aranha
8
+ module Parsers
9
+ class SourceAddress
10
+ ::EacRubyUtils.require_sub __FILE__
11
+
12
+ class << self
13
+ SUBS = [
14
+ ::Aranha::Parsers::SourceAddress::HashHttpGet,
15
+ ::Aranha::Parsers::SourceAddress::HashHttpPost,
16
+ ::Aranha::Parsers::SourceAddress::HttpGet,
17
+ ::Aranha::Parsers::SourceAddress::File
18
+ ].freeze
19
+
20
+ def detect_sub(source)
21
+ return source.sub if source.is_a?(self)
22
+
23
+ SUBS.each do |sub|
24
+ return sub.new(source) if sub.valid_source?(source)
25
+ end
26
+ raise "No content fetcher found for source \"#{source}\""
27
+ end
28
+
29
+ def deserialize(string)
30
+ new(string =~ %r{\A[a-z]+://} ? string.strip : ::YAML.load(string)) # rubocop:disable Security/YAMLLoad
31
+ end
32
+
33
+ def from_file(path)
34
+ deserialize(::File.read(path))
35
+ end
36
+ end
37
+
38
+ attr_reader :sub
39
+
40
+ def initialize(source)
41
+ @sub = self.class.detect_sub(source)
42
+ end
43
+
44
+ delegate :content, :url, to: :sub
45
+
46
+ def to_s
47
+ sub.url
48
+ end
49
+
50
+ def serialize
51
+ sub.serialize.strip + "\n"
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/source_address/http_get'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ class SourceAddress
8
+ class File < ::Aranha::Parsers::SourceAddress::HttpGet
9
+ SCHEME = 'file://'
10
+
11
+ class << self
12
+ def valid_source?(source)
13
+ source.to_s.start_with?(SCHEME + '/', '/')
14
+ end
15
+ end
16
+
17
+ def initialize(source)
18
+ super source.to_s.gsub(/\A#{Regexp.quote(SCHEME)}/, '')
19
+ end
20
+
21
+ def url
22
+ "#{SCHEME}#{source}"
23
+ end
24
+
25
+ def content
26
+ ::File.open(source, &:read)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/source_address/hash_http_post'
4
+
5
+ module Aranha
6
+ module Parsers
7
+ class SourceAddress
8
+ class HashHttpGet < ::Aranha::Parsers::SourceAddress::HashHttpPost
9
+ class << self
10
+ def valid_source?(source)
11
+ source.is_a?(::Hash) &&
12
+ source.with_indifferent_access[:method].to_s.downcase.strip == 'get'
13
+ end
14
+ end
15
+
16
+ def content
17
+ HTTPClient.new.get_content(
18
+ source[:url],
19
+ source[:params]
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/hash/indifferent_access'
4
+ require 'httpclient'
5
+ require 'yaml'
6
+
7
+ module Aranha
8
+ module Parsers
9
+ class SourceAddress
10
+ class HashHttpPost
11
+ class << self
12
+ def valid_source?(source)
13
+ source.is_a?(::Hash) &&
14
+ source.with_indifferent_access[:method].to_s.downcase.strip == 'post'
15
+ end
16
+ end
17
+
18
+ attr_reader :source
19
+
20
+ def initialize(source)
21
+ @source = source.with_indifferent_access
22
+ end
23
+
24
+ def ==(other)
25
+ self.class == other.class && source == other.source
26
+ end
27
+
28
+ def url
29
+ source.fetch(:url)
30
+ end
31
+
32
+ def serialize
33
+ source.to_yaml
34
+ end
35
+
36
+ def content
37
+ HTTPClient.new.post_content(
38
+ source[:url],
39
+ source[:params].merge(follow_redirect: true)
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'addressable'
4
+ require 'curb'
5
+
6
+ module Aranha
7
+ module Parsers
8
+ class SourceAddress
9
+ class HttpGet
10
+ class << self
11
+ def location_uri(source_uri, location)
12
+ ::Addressable::URI.join(source_uri, location).to_s
13
+ end
14
+
15
+ def valid_source?(source)
16
+ source.to_s =~ %r{\Ahttps?://}
17
+ end
18
+ end
19
+
20
+ attr_reader :source
21
+
22
+ def initialize(source)
23
+ @source = source.to_s
24
+ end
25
+
26
+ def ==(other)
27
+ self.class == other.class && source == other.source
28
+ end
29
+
30
+ def url
31
+ source
32
+ end
33
+
34
+ def content
35
+ c = ::Curl::Easy.new(url)
36
+ c.follow_location = true
37
+ raise "Curl perform failed (URL: #{url})" unless c.perform
38
+ return c.body_str if c.status.to_i == 200
39
+
40
+ raise "Get #{url} returned #{c.status.to_i}"
41
+ end
42
+
43
+ def serialize
44
+ url
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object'
4
+ require 'active_support/core_ext/string'
5
+
6
+ module Aranha
7
+ module Parsers
8
+ # Lists pairs of source/target files in a directory.
9
+ class SourceTargetFixtures
10
+ class << self
11
+ def source_target_basename(file)
12
+ m = /^(.+)\.(?:source|target)(?:\..+)?$/.match(File.basename(file))
13
+ m ? m[1] : nil
14
+ end
15
+ end
16
+
17
+ attr_reader :fixtures_directory
18
+
19
+ def initialize(fixtures_directory)
20
+ @fixtures_directory = fixtures_directory
21
+ end
22
+
23
+ def source_target_files
24
+ sources_targets_basenames.map do |basename|
25
+ OpenStruct.new(basename: basename, source: source_file(basename),
26
+ target: target_file(basename))
27
+ end
28
+ end
29
+
30
+ def source_files
31
+ r = []
32
+ source_target_files.each do |st|
33
+ r << st.source if st.source
34
+ end
35
+ r
36
+ end
37
+
38
+ def target_files
39
+ r = []
40
+ source_target_files.each do |st|
41
+ r << st.target if st.target
42
+ end
43
+ r
44
+ end
45
+
46
+ def target_file(basename)
47
+ fixture_file(basename, 'target')
48
+ end
49
+
50
+ def source_file(basename)
51
+ fixture_file(basename, 'source')
52
+ end
53
+
54
+ private
55
+
56
+ def fixture_file(basename, suffix)
57
+ prefix = "#{basename}.#{suffix}"
58
+ Dir.foreach(fixtures_directory) do |item|
59
+ next if %w[. ..].include?(item)
60
+ return File.expand_path(item, fixtures_directory) if item.starts_with?(prefix)
61
+ end
62
+ nil
63
+ end
64
+
65
+ def sources_targets_basenames
66
+ basenames = Set.new
67
+ Dir.foreach(fixtures_directory) do |item|
68
+ next if %w[. ..].include?(item)
69
+
70
+ b = self.class.source_target_basename(item)
71
+ basenames << b if b.present?
72
+ end
73
+ basenames
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/source_target_fixtures'
4
+ require 'yaml'
5
+
6
+ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable Metrics/BlockLength
7
+ let(:spec_file) { spec_file }
8
+
9
+ it 'fixtures directory should exist' do
10
+ expect(::File.directory?(fixtures_dir)).to be true
11
+ end
12
+
13
+ context 'with fixtures directory' do
14
+ it 'has at least one file' do
15
+ expect(source_target_fixtures.source_target_files.count).to be > 0 # rubocop:disable Style/NumericPredicate
16
+ end
17
+
18
+ if ENV['WRITE_TARGET_FIXTURES']
19
+ it 'writes target data for all files' do
20
+ source_target_fixtures.source_files.each do |source_file|
21
+ sd = sort_results(source_data(source_file))
22
+ basename = ::Aranha::Parsers::SourceTargetFixtures.source_target_basename(source_file)
23
+ target_file = File.expand_path("../#{basename}.target#{target_file_extname}", source_file)
24
+ File.write(target_file, target_content(sd))
25
+ end
26
+ end
27
+ else
28
+ it 'parses data for all files' do
29
+ source_target_fixtures.source_target_files.each do |st|
30
+ assert_source_target_complete(st)
31
+ sd = source_data(st.source)
32
+ td = target_data(st.target)
33
+ expect(sort_results(sd)).to eq(sort_results(td))
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def source_target_fixtures
40
+ @source_target_fixtures ||= ::Aranha::Parsers::SourceTargetFixtures.new(fixtures_dir)
41
+ end
42
+
43
+ def assert_source_target_complete(source_target)
44
+ expect(source_target.source).to(be_truthy, "Source not found (Target: #{source_target.target})")
45
+ expect(source_target.target).to(be_truthy, "Target not found (Source: #{source_target.source})")
46
+ end
47
+
48
+ def source_data(source_file)
49
+ instance = described_class.new(source_file)
50
+ return instance.data if instance.respond_to?(:data)
51
+
52
+ raise "#{instance} has no \"data\" method. You need to implement \"#{instance}.data\" or " \
53
+ "\"#{self}.source_data(source_file)\""
54
+ end
55
+
56
+ def fixtures_dir
57
+ ::File.join(
58
+ ::File.dirname(spec_file),
59
+ ::File.basename(spec_file, '.*') + '_files'
60
+ )
61
+ end
62
+
63
+ def sort_results(results)
64
+ results
65
+ end
66
+
67
+ def target_data(target_file)
68
+ ::YAML.load_file(target_file)
69
+ end
70
+
71
+ def target_content(data)
72
+ data.to_yaml
73
+ end
74
+
75
+ def target_file_extname
76
+ '.yaml'
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aranha
4
+ module Parsers
5
+ VERSION = '0.7.0'
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/source_address/http_get'
4
+
5
+ RSpec.describe ::Aranha::Parsers::SourceAddress::HttpGet do
6
+ SOURCE_URI = 'http://example.net/abc' # rubocop:disable RSpec/LeakyConstantDeclaration
7
+
8
+ describe '#location_uri' do
9
+ [
10
+ { location: 'http://example.net/def', expected: 'http://example.net/def' },
11
+ { location: '/def', expected: 'http://example.net/def' }
12
+ ].each do |stub|
13
+ context "when source_uri is \"#{SOURCE_URI}\" and location is \"#{stub.fetch(:location)}\"" do
14
+ it "return #{stub.fetch(:expected)}" do
15
+ expect(described_class.location_uri(SOURCE_URI, stub.fetch(:location)))
16
+ .to eq(stub.fetch(:expected))
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end