Sha256: d8dfcfe6fc66bbca3b755c571db167817eaf7d93490ba1db9d1af8c93065d4f8

Contents?: true

Size: 1.85 KB

Versions: 14

Compression:

Stored size: 1.85 KB

Contents

module Guard
  class RSpec < Plugin
    module Inspectors
      class BaseInspector
        attr_accessor :options, :spec_paths

        def initialize(options = {})
          @options = options
          @spec_paths = @options[:spec_paths]
          @chdir = @options[:chdir]
        end

        def paths(_paths)
          raise NotImplementedError
        end

        def failed(_locations)
          raise NotImplementedError
        end

        def reload
          raise NotImplementedError
        end

        private

        # Leave only spec/feature files from spec_paths, remove others
        def _clean(paths)
          paths.uniq!
          paths.compact!
          spec_dirs = _select_only_spec_dirs(paths)
          spec_files = _select_only_spec_files(paths)
          (spec_dirs + spec_files).uniq
        end

        def _select_only_spec_dirs(paths)
          chdir_paths = _spec_paths_with_chdir
          paths.select do |path|
            File.directory?(path) || chdir_paths.include?(path)
          end
        end

        def _select_only_spec_files(paths)
          spec_files = _collect_files("*[_.]spec.rb")
          feature_files = _collect_files("*.feature")
          files = (spec_files + feature_files).flatten

          paths.select do |path|
            (files & [@chdir ? File.join(@chdir, path) : path]).any?
          end
        end

        def _spec_paths_with_chdir
          _paths_with_chdir(spec_paths, @chdir)
        end

        def _collect_files(pattern)
          base_paths = _spec_paths_with_chdir
          base_paths.map do |path|
            # TODO: not tested properly
            Dir[File.join(path, "**{,/*/**}", pattern)]
          end
        end

        def _paths_with_chdir(paths, chdir)
          paths.map do |path|
            chdir ? File.join(chdir, path) : path
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 6 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
gameboard-3.1.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
gameboard-3.0.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.7.3 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.7.2 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.7.1 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.7.0 lib/guard/rspec/inspectors/base_inspector.rb