Module: Yari::RSpec::Loader

Defined in:
lib/yari/yari_loader.rb

Instance Method Summary collapse

Instance Method Details

#load(*paths, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/yari/yari_loader.rb', line 7

def load(*paths, &block)

  # Override feature exclusion filter if running features
  if paths.any? { |path| Yari.feature?(path) }
    ::RSpec.configuration.filter_manager.exclusions.rules.reject! do |key, value|
      key == :feature || (key == :type && value == 'feature')
    end
  end

  paths = paths.map do |path|
    if Yari.feature?(path)
      spec_path = Yari.feature_to_spec(path)
      if File.exist?(spec_path)
        spec_path
      else
        Yari::Builder.build(path).features.each do |feature|
          ::RSpec.describe("Feature: #{feature.name}", :type => :feature, :feature => true) do
            it do |example|
              example.[:location] = path << ':1'
              skip('No spec implemented for feature')
            end
          end
        end
        nil
      end
    else
      path
    end
  end.compact

  # Load needed features to Yari.features array
  paths.each do |path|
    if Yari.feature_spec?(path)
      feature_path = Yari.spec_to_feature(path)

      if File.exists?(feature_path)
        Yari.features += Yari::Builder.build(feature_path).features
      end
    end
  end

  super(*paths, &block) if paths.size > 0
end