Sha256: 34e54bec9d6f51c09a31cb029e1fb1aa5b03fd141a47ec990a589168a0e38364

Contents?: true

Size: 969 Bytes

Versions: 7

Compression:

Stored size: 969 Bytes

Contents

require 'mspec/runner/filters/match'

# ActionFilter is a base class for actions that are triggered by
# specs that match the filter. The filter may be specified by
# strings that match spec descriptions or by tags for strings
# that match spec descriptions.
#
# Unlike TagFilter and RegexpFilter, ActionFilter instances do
# not affect the specs that are run. The filter is only used to
# trigger the action.

class ActionFilter
  def initialize(tags=nil, descs=nil)
    @tags = Array(tags)
    descs = Array(descs)
    @sfilter = MatchFilter.new(nil, *descs) unless descs.empty?
  end

  def ===(string)
    @sfilter === string or @tfilter === string
  end

  def load
    @tfilter = nil
    return if @tags.empty?

    desc = MSpec.read_tags(*@tags).map { |t| t.description }
    return if desc.empty?

    @tfilter = MatchFilter.new(nil, *desc)
  end

  def register
    MSpec.register :load, self
  end

  def unregister
    MSpec.unregister :load, self
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mspec-1.0.0 lib/mspec/runner/actions/filter.rb
mspec-1.1.1 lib/mspec/runner/actions/filter.rb
mspec-1.2.0 lib/mspec/runner/actions/filter.rb
mspec-1.3.1 lib/mspec/runner/actions/filter.rb
mspec-1.3.0 lib/mspec/runner/actions/filter.rb
mspec-1.4.0 lib/mspec/runner/actions/filter.rb
mspec-1.1.0 lib/mspec/runner/actions/filter.rb