class Lucid::ContextLoader::SpecLoader

Public Class Methods

new(spec_files, filters, tag_expression) click to toggle source
# File lib/lucid/spec_loader.rb, line 8
def initialize(spec_files, filters, tag_expression)
  @spec_files, @filters, @tag_expression = spec_files, filters, tag_expression
end

Public Instance Methods

load_specs() click to toggle source

@see Lucid::ContextLoader.load_spec_context

# File lib/lucid/spec_loader.rb, line 13
def load_specs
  load unless (defined? @spec) and @spec
  @spec
end

Private Instance Methods

check_tag_limits(tag_counts) click to toggle source
# File lib/lucid/spec_loader.rb, line 50
def check_tag_limits(tag_counts)
  error_messages = []
  @tag_expression.limits.each do |tag_name, tag_limit|
    tag_locations = (tag_counts[tag_name] || [])
    tag_count = tag_locations.length
    if tag_count > tag_limit
      error = "#{tag_name} occurred #{tag_count} times, but the limit was set to #{tag_limit}\n  " +
        tag_locations.join("\n  ")
      error_messages << error
    end
  end
  raise TagExcess.new(error_messages) if error_messages.any?
end
load() click to toggle source

The specs loader will call upon load to load up all specs that were found in the spec repository. During this process, a Spec instance is created that will hold instances of the high level construct, which is basically the feature.

# File lib/lucid/spec_loader.rb, line 24
def load
  spec = Lucid::AST::Spec.new

  tag_counts = {}
  start = Time.new
  log.info("Specs:\n")

  @spec_files.each do |f|
    spec_file = SpecFile.new(f)

    feature = spec_file.parse(@filters, tag_counts)

    if feature
      spec.add_feature(feature)
      log.info("  * #{f}\n")
    end
  end

  duration = Time.now - start
  log.info("Parsing spec files took #{format_duration(duration)}\n\n")

  check_tag_limits(tag_counts)

  @spec = spec
end
log() click to toggle source
# File lib/lucid/spec_loader.rb, line 64
def log
  Lucid.logger
end