Sha256: d1890f63153f8ded4732c0f71c6841af06def1da602e7c46fc3d78ea84df9a47

Contents?: true

Size: 1.85 KB

Versions: 16

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)
          fail NotImplementedError
        end

        def failed(_locations)
          fail NotImplementedError
        end

        def reload
          fail 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

16 entries across 16 versions & 3 rubygems

Version Path
guard-rspec-4.6.5 lib/guard/rspec/inspectors/base_inspector.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/guard-rspec-4.6.4/lib/guard/rspec/inspectors/base_inspector.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/guard-rspec-4.6.4/lib/guard/rspec/inspectors/base_inspector.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/guard-rspec-4.6.4/lib/guard/rspec/inspectors/base_inspector.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/guard-rspec-4.6.4/lib/guard/rspec/inspectors/base_inspector.rb
geminfo-0.1.0 path/gems/guard-rspec-4.6.4/lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.6.4 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.6.3 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.6.2 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.6.1 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.6.0 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.5.2 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.5.1 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.5.0 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.4.2 lib/guard/rspec/inspectors/base_inspector.rb
guard-rspec-4.4.1 lib/guard/rspec/inspectors/base_inspector.rb