opal-rspec 1.1.0.alpha1 → 1.1.0.alpha3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95ab0afeb6b8db964c718d2716cd7b4f91cf022dc38eb33b7271219a7f277e8d
4
- data.tar.gz: c256b94c07aae78d0fab3407aad4cadc5f23f2d60662551056e1c65ad70d4a20
3
+ metadata.gz: 0ade995b0c6d3f286e1fab0a744a29747a9404af45a8379dacbd30a42a04521d
4
+ data.tar.gz: c2e8c3252227413b183f0c0aaad68de756cb933b182aa250d92d565ffe4d8a71
5
5
  SHA512:
6
- metadata.gz: 0567fb3f9293fbcafa0c6990dcdfb36bf2e40936ff75b6f8879a798628c3a9384842e95da555851a9ff9abb876409d148434e066e8071bd62a525670760ed914
7
- data.tar.gz: 0ee3ad1ace7524f5daf1025a7671309d23905bd9f6f87c280a297b8817c4292943a6a773cbe7c4dd208cf70836b5f197e2cec95924912880b13119136bc64419
6
+ metadata.gz: c785be231521c658867c6fbe412066199feaab7ebb1f5fd28966f96f828bc5f783950f9ea1e8b27f2a973b46897809def87904e1f71105485881f8c03c436f33
7
+ data.tar.gz: 9ef0711790bcd41452f75f5d7a721f7db2194f30f88e17abbcc25a931d9a1424a88d65d70d4803a274778cfd295824ac8bc44531029103bf906e9a5bc2b45398
@@ -13,10 +13,11 @@ on:
13
13
  jobs:
14
14
  build:
15
15
  strategy:
16
+ fail-fast: false
16
17
  matrix:
17
18
  os: [ 'ubuntu-latest' ]
18
- ruby: [ ruby-head, 3.1, "3.0", 2.7 ]
19
- opal: [ master, 1.6, 1.7 ]
19
+ ruby: [ ruby-head, 3.2, 3.1, "3.0", 2.7 ]
20
+ opal: [ master, 1.7, 1.8 ]
20
21
 
21
22
  runs-on: ${{ matrix.os }}
22
23
 
@@ -24,7 +25,9 @@ jobs:
24
25
  OPAL_VERSION: ${{ matrix.opal }}
25
26
 
26
27
  steps:
27
- - uses: actions/checkout@v2
28
+ - uses: actions/checkout@v4
29
+ with:
30
+ submodules: true
28
31
  - uses: ruby/setup-ruby@v1
29
32
  with:
30
33
  ruby-version: ${{ matrix.ruby }}
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
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
+
12
+ ## 1.1.0.alpha2 - 2023-09-20
13
+
14
+ - Drop advertised support for Opal v1.6
15
+
16
+ - Fix support for Ruby 2.7+
17
+
18
+ - Drop requirement of Opal-Sprockets
19
+
20
+
3
21
  ## 1.1.0.alpha1 - 2023-09-16
4
22
 
5
23
  - Support Opal headless browser runners
data/Gemfile CHANGED
@@ -18,7 +18,7 @@ case ENV['OPAL_VERSION']
18
18
  when 'local'
19
19
  gem 'opal', path: '../opal'
20
20
  when /^[0-9]/
21
- gem 'opal', ENV['OPAL_VERSION']
21
+ gem 'opal', "~> #{ENV['OPAL_VERSION']}.0a"
22
22
  when String
23
23
  gem 'opal', git: 'https://github.com/opal/opal.git', branch: ENV['OPAL_VERSION']
24
24
  end
@@ -1,10 +1,11 @@
1
+ require 'opal/rspec/util'
1
2
  require 'optparse'
2
3
 
3
4
  module Opal; module RSpec; module Core; end; end; end
4
5
  # Load necessary files under Opal's namespace, so as not to conflict with RSpec if it's being loaded too.
5
6
  # Later, we will monkey-patch those methods.
6
- load __dir__ + "/../../../rspec-core/upstream/lib/rspec/core/invocations.rb", ::Opal
7
- load __dir__ + "/../../../rspec-core/upstream/lib/rspec/core/option_parser.rb", ::Opal
7
+ ::Opal::RSpec.load_namespaced __dir__ + "/../../../rspec-core/upstream/lib/rspec/core/invocations.rb", ::Opal
8
+ ::Opal::RSpec.load_namespaced __dir__ + "/../../../rspec-core/upstream/lib/rspec/core/option_parser.rb", ::Opal
8
9
 
9
10
  class Opal::RSpec::Core::Parser
10
11
  alias parser_before_opal parser
@@ -21,6 +22,16 @@ class Opal::RSpec::Core::Parser
21
22
  options[:runner] = name
22
23
  end
23
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
+
24
35
  parser.separator ''
25
36
  parser.separator ' **** Help ****'
26
37
  parser.separator ''
@@ -1,8 +1,9 @@
1
+ require 'opal/rspec/util'
1
2
  require 'pathname'
2
3
  require 'rake'
3
4
  # require the bundled RSpec's file and don't rely on the load path in case opal-rspec is included in a project's
4
5
  # Gemfile without rspec also being in the Gemfile
5
- load __dir__+'/../../../rspec-core/upstream/lib/rspec/core/ruby_project.rb', ::Opal
6
+ ::Opal::RSpec.load_namespaced __dir__+'/../../../rspec-core/upstream/lib/rspec/core/ruby_project.rb', ::Opal
6
7
 
7
8
  module Opal
8
9
  module RSpec
@@ -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
 
@@ -0,0 +1,15 @@
1
+ module ::Opal
2
+ module RSpec
3
+ def self.load_namespaced(file, mod)
4
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.1")
5
+ load file, mod
6
+ else
7
+ str = ""
8
+ str += "module ::#{mod.name};"
9
+ str += File.read(file)
10
+ str += ";end"
11
+ eval(str)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,10 +1,12 @@
1
+ require 'opal/rspec/util'
2
+
1
3
  module Opal
2
4
  module RSpec
3
- VERSION = '1.1.0.alpha1'
5
+ VERSION = '1.1.0.alpha3'
4
6
  end
5
7
  end
6
8
 
7
- load __dir__ + "/../../../rspec-core/upstream/lib/rspec/core/version.rb", ::Opal
8
- load __dir__ + "/../../../rspec-expectations/upstream/lib/rspec/expectations/version.rb", ::Opal
9
- load __dir__ + "/../../../rspec-mocks/upstream/lib/rspec/mocks/version.rb", ::Opal
10
- load __dir__ + "/../../../rspec-support/upstream/lib/rspec/support/version.rb", ::Opal
9
+ ::Opal::RSpec.load_namespaced __dir__ + "/../../../rspec-core/upstream/lib/rspec/core/version.rb", ::Opal
10
+ ::Opal::RSpec.load_namespaced __dir__ + "/../../../rspec-expectations/upstream/lib/rspec/expectations/version.rb", ::Opal
11
+ ::Opal::RSpec.load_namespaced __dir__ + "/../../../rspec-mocks/upstream/lib/rspec/mocks/version.rb", ::Opal
12
+ ::Opal::RSpec.load_namespaced __dir__ + "/../../../rspec-support/upstream/lib/rspec/support/version.rb", ::Opal
data/lib/opal/rspec.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'opal'
2
- require 'opal-sprockets'
3
2
  require 'opal/rspec/version'
4
3
  require 'opal/rspec/runner'
5
4
  require 'opal/rspec/configuration_parser'
@@ -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.alpha1
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-15 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
@@ -303,6 +303,7 @@ files:
303
303
  - lib/opal/rspec/runner.rb
304
304
  - lib/opal/rspec/sprockets.rb
305
305
  - lib/opal/rspec/sprockets_environment.rb
306
+ - lib/opal/rspec/util.rb
306
307
  - lib/opal/rspec/version.rb
307
308
  - opal-rspec.gemspec
308
309
  - rspec-core/upstream/.document