opal-rspec 1.1.0.alpha2 → 1.1.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daf042a48c3443b869f363a722554e1b71a3e4153f1ea6edd73562e1d0c5f6b1
4
- data.tar.gz: 9e1db2043bedaa0c70c673a9485ecce6a99014db2b7f0eb51ec13d97c2b59d76
3
+ metadata.gz: 0ade995b0c6d3f286e1fab0a744a29747a9404af45a8379dacbd30a42a04521d
4
+ data.tar.gz: c2e8c3252227413b183f0c0aaad68de756cb933b182aa250d92d565ffe4d8a71
5
5
  SHA512:
6
- metadata.gz: c92f9b1bd05afa875b886deb5d48b81b568f5042a0d51bf82f1bbcd98c5403cc0dc69c26dc671c9fc92646adbb889771c4d1fce7e6c69fffe717f581f09be6f4
7
- data.tar.gz: e5ec66ded2c2ed976a3234946efc8bb4b6a003d1dbc764831730bbd3de8cd348e1da1e3818b9777e5405b1cca743827b29ef96650cedd1fd4bd7d4875a8d336e
6
+ metadata.gz: c785be231521c658867c6fbe412066199feaab7ebb1f5fd28966f96f828bc5f783950f9ea1e8b27f2a973b46897809def87904e1f71105485881f8c03c436f33
7
+ data.tar.gz: 9ef0711790bcd41452f75f5d7a721f7db2194f30f88e17abbcc25a931d9a1424a88d65d70d4803a274778cfd295824ac8bc44531029103bf906e9a5bc2b45398
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Opal-RSpec Changelog
2
2
 
3
+ ## 1.1.0.alpha3 - 2023-09-26
4
+
5
+ - Refactor glob_to_re into a robust implementation
6
+
7
+ - Add `--opal-opt` CLI option
8
+
9
+ - Add `--rbrequire` CLI option
10
+
11
+
3
12
  ## 1.1.0.alpha2 - 2023-09-20
4
13
 
5
14
  - Drop advertised support for Opal v1.6
@@ -22,6 +22,16 @@ class Opal::RSpec::Core::Parser
22
22
  options[:runner] = name
23
23
  end
24
24
 
25
+ parser.on('-q', '--rbrequire FILE', 'Require a file in MRI context before running Opal') do |name|
26
+ options[:opal_rbrequires] ||= []
27
+ options[:opal_rbrequires] << name
28
+ end
29
+
30
+ parser.on('-O', '--opal-opt FLAG', 'Run Opal with additional options (separate by `,` or specify multiple times)') do |name|
31
+ options[:opal_options] ||= []
32
+ options[:opal_options] += name.split(",")
33
+ end
34
+
25
35
  parser.separator ''
26
36
  parser.separator ' **** Help ****'
27
37
  parser.separator ''
@@ -117,6 +117,10 @@ module Opal
117
117
  options << '--missing-require=ignore'
118
118
  options += @legacy_server_proxy.to_cli_options
119
119
 
120
+ spec_opts.delete(:opal_rbrequires) { [] }.each do |r|
121
+ require r
122
+ end
123
+
120
124
  load_paths = [Opal.paths, locator.get_spec_load_paths, self.libs].compact.sum([]).uniq
121
125
 
122
126
  load_paths.each { |p| options << "-I#{p}" }
@@ -125,6 +129,7 @@ module Opal
125
129
  ::Opal::Config.stubbed_files.each { |p| options << "-s#{p}" }
126
130
 
127
131
  options += @cli_options if @cli_options
132
+ options += spec_opts.delete(:opal_options) { [] }
128
133
 
129
134
  bootstrap_code = ::Opal::RSpec.spec_opts_code(spec_opts)
130
135
 
@@ -2,7 +2,7 @@ require 'opal/rspec/util'
2
2
 
3
3
  module Opal
4
4
  module RSpec
5
- VERSION = '1.1.0.alpha2'
5
+ VERSION = '1.1.0.alpha3'
6
6
  end
7
7
  end
8
8
 
@@ -23,27 +23,49 @@ module ::RSpec; module Core; class Configuration
23
23
  str.gsub(/(?:\.js)?\.(?:rb|opal|\{rb,opal\})\z/, '')
24
24
  end
25
25
 
26
+ def glob_to_re_expand_alternatives(glob)
27
+ # If there are no braces, just return the string as an array
28
+ return [glob] unless glob =~ /(.*)\{([^\{\}]*?)\}(.*)/
29
+
30
+ prefix, contents, suffix = $1, $2, $3
31
+
32
+ alternatives = contents.split(',')
33
+
34
+ expanded_patterns = alternatives.map do |alternative|
35
+ "#{prefix}#{alternative}#{suffix}"
36
+ end
37
+
38
+ # Recursively expand for the rest of the pattern
39
+ return expanded_patterns.flat_map { |pattern| glob_to_re_expand_alternatives(pattern) }
40
+ end
41
+
26
42
  def glob_to_re(path, pattern)
27
43
  pattern = remove_ruby_ext(pattern)
28
- path = "" if pattern.start_with?(path)
29
- path += "/" unless path.end_with?("/")
30
- re = Regexp.escape(pattern).gsub('\*\*', '.*?')
31
- .gsub('\*', '[^/]*?')
32
- .gsub('\?', '[^/]')
33
- .gsub(/\\{(.*?)\\}/) {
34
- '(?:' + $1.gsub(",", "|") + ')'
35
- }
36
- re = "(?:^|/)" + Regexp.escape(path) + re + "$"
37
- # Strip the first `/` so it acts more like the intention of `**`
38
- re = re.gsub("/.*?", ".*?")
44
+ if pattern.start_with?(path)
45
+ path = ""
46
+ else
47
+ path += "/" unless path.end_with?("/")
48
+ end
49
+ pattern = path + pattern
50
+ patterns = glob_to_re_expand_alternatives(pattern)
51
+ re = patterns.map { |i| Regexp.escape(i) }.join("|").then { |i| "(?:#{i})" }
52
+ re = re.gsub('\/\*\*\/', '(?:/|/.*?/)')
53
+ .gsub('\*', '[^/]*?')
54
+ .gsub('\?', '[^/]')
55
+ re = '(?:^|/)' + re + "$"
56
+ # Strip multiple '/'s
57
+ re = re.gsub(%r{(\\/|/)+}, '/')
39
58
  # Strip the `/./`
40
- re = re.gsub("/\\.\\/", "\\/")
41
- re = re.gsub("/)\\.\\/", "\\/)")
59
+ re = re.gsub('/\./', '/')
60
+ re = re.gsub('(?:^|/)\./', '(?:^|/)')
42
61
  Regexp.new(re)
43
62
  end
44
63
 
45
64
  # Only load from loaded files
46
65
  def get_matching_files(path, pattern)
66
+ if pattern.is_a?(Array)
67
+ return pattern.map { |pat| get_matching_files(path, pat) }.flatten.sort.uniq
68
+ end
47
69
  `Object.keys(Opal.modules)`.grep(glob_to_re(path, pattern)).sort
48
70
  end
49
71
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.alpha2
4
+ version: 1.1.0.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Beynon
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2023-09-20 00:00:00.000000000 Z
13
+ date: 2023-09-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: opal