Class: Opal::RSpec::Locator

Inherits:
Object
  • Object
show all
Includes:
Core::RubyProject
Defined in:
lib/opal/rspec/locator.rb

Constant Summary collapse

DEFAULT_GLOB =
'**{,/*/**}/*_spec{.js,}.{rb,opal}'
DEFAULT_DEFAULT_PATH =
'spec-opal'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern: nil, exclude_pattern: nil, files: nil, default_path: nil) ⇒ Locator

Returns a new instance of Locator.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/opal/rspec/locator.rb', line 18

def initialize(pattern: nil, exclude_pattern: nil, files: nil, default_path: nil)
  @spec_exclude_pattern = Array(exclude_pattern)
  @spec_files           = files
  @default_path         = default_path || DEFAULT_DEFAULT_PATH
  @spec_pattern         = Array(pattern || DEFAULT_GLOB)

  @spec_pattern = @spec_pattern.map do |pattern|
    pattern.sub(/\A#{Regexp.escape(@default_path)}/, '')
  end

  @spec_exclude_pattern = @spec_exclude_pattern.map do |pattern|
    pattern.sub(/\A#{Regexp.escape(@default_path)}/, '')
  end
end

Instance Attribute Details

#default_pathObject

Returns the value of attribute default_path.



16
17
18
# File 'lib/opal/rspec/locator.rb', line 16

def default_path
  @default_path
end

#spec_exclude_patternObject

Returns the value of attribute spec_exclude_pattern.



16
17
18
# File 'lib/opal/rspec/locator.rb', line 16

def spec_exclude_pattern
  @spec_exclude_pattern
end

#spec_filesObject

Returns the value of attribute spec_files.



16
17
18
# File 'lib/opal/rspec/locator.rb', line 16

def spec_files
  @spec_files
end

#spec_patternObject

Returns the value of attribute spec_pattern.



16
17
18
# File 'lib/opal/rspec/locator.rb', line 16

def spec_pattern
  @spec_pattern
end

Instance Method Details

#determine_rootObject



33
34
35
# File 'lib/opal/rspec/locator.rb', line 33

def determine_root
  find_first_parent_containing(@default_path) || '.'
end

#get_matching_files_under(path:) ⇒ Object



41
42
43
44
# File 'lib/opal/rspec/locator.rb', line 41

def get_matching_files_under(path: )
  FileList[*@spec_pattern.map { |i| "#{path}/#{i}" }]
    .exclude(*@spec_exclude_pattern.map { |i| "#{path}/#{i}" })
end

#get_opal_spec_requiresObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/opal/rspec/locator.rb', line 46

def get_opal_spec_requires
  if !@spec_files || @spec_files.empty?
    files = get_matching_files_under(path: @default_path)
  else
    files = @spec_files.map do |file|
      file = file.split(/[\[:]/).first
      if File.directory?(file)
        get_matching_files_under(path: file).to_a
      else
        file
      end
    end.flatten
    files = FileList[*files]
  end
  files.uniq.map { |file| File.expand_path file }
end

#get_spec_load_pathsObject



37
38
39
# File 'lib/opal/rspec/locator.rb', line 37

def get_spec_load_paths
  [File.join(root, @default_path)]
end