Sha256: fc80518347e71601ae40603448e9b8b0fa637f91f8943a5401fe8ecbb091e4cf

Contents?: true

Size: 1.08 KB

Versions: 198

Compression:

Stored size: 1.08 KB

Contents

class ProfileFilter
  def initialize(what, *files)
    @what = what
    @methods = load(*files)
    @pattern = /([^ .#]+[.#])([^ ]+)/
  end

  def find(name)
    return name if File.exist?(File.expand_path(name))

    ["spec/profiles", "spec", "profiles", "."].each do |dir|
      file = File.join dir, name
      return file if File.exist? file
    end
  end

  def parse(file)
    pattern = /(\S+):\s*/
    key = ""
    file.inject(Hash.new { |h,k| h[k] = [] }) do |hash, line|
      line.chomp!
      if line[0,2] == "- "
        hash[key] << line[2..-1].gsub(/[ '"]/, "")
      elsif m = pattern.match(line)
        key = m[1]
      end
      hash
    end
  end

  def load(*files)
    files.inject({}) do |hash, file|
      next hash unless name = find(file)

      File.open name, "r" do |f|
        hash.merge parse(f)
      end
    end
  end

  def ===(string)
    return false unless m = @pattern.match(string)
    return false unless l = @methods[m[1]]
    l.include? m[2]
  end

  def register
    MSpec.register @what, self
  end

  def unregister
    MSpec.unregister @what, self
  end
end

Version data entries

198 entries across 174 versions & 4 rubygems

Version Path
rhodes-7.6.0 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-7.5.1 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-7.4.1 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-7.1.17 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-6.2.0 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-6.0.11 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-5.5.18 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-5.5.17 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-5.5.15 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-5.5.0.22 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-5.5.2 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-5.5.0.7 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-5.5.0.3 lib/extensions/mspec/mspec/runner/filters/profile.rb
rhodes-5.5.0 lib/extensions/mspec/mspec/runner/filters/profile.rb
tauplatform-1.0.3 lib/extensions/mspec/mspec/runner/filters/profile.rb
mspec-1.9.1 lib/mspec/runner/filters/profile.rb
mspec-1.9.0 lib/mspec/runner/filters/profile.rb
tauplatform-1.0.2 lib/extensions/mspec/mspec/runner/filters/profile.rb
tauplatform-1.0.1 lib/extensions/mspec/mspec/runner/filters/profile.rb
mspec-1.8.0 lib/mspec/runner/filters/profile.rb