Class: TagListAction

Inherits:
Object show all
Defined in:
lib/mspec/runner/actions/taglist.rb

Overview

TagListAction - prints out the descriptions for any specs tagged with tags. If tags is an empty list, prints out descriptions for any specs that are tagged.

Direct Known Subclasses

TagPurgeAction

Instance Method Summary collapse

Constructor Details

#initialize(tags = nil) ⇒ TagListAction

Returns a new instance of TagListAction.



7
8
9
10
# File 'lib/mspec/runner/actions/taglist.rb', line 7

def initialize(tags=nil)
  @tags = tags.nil? || tags.empty? ? nil : Array(tags)
  @filter = nil
end

Instance Method Details

#===(string) ⇒ Object

Returns true if any tagged descriptions matches string.



19
20
21
# File 'lib/mspec/runner/actions/taglist.rb', line 19

def ===(string)
  @filter === string
end

#after(state) ⇒ Object

Prints the spec description if it matches the filter.



40
41
42
43
# File 'lib/mspec/runner/actions/taglist.rb', line 40

def after(state)
  return unless self === state.description
  print state.description, "\n"
end

#include?(arg) ⇒ Boolean

Returns true. This enables us to match any tag when loading tags from the file.

Returns:

  • (Boolean)


14
15
16
# File 'lib/mspec/runner/actions/taglist.rb', line 14

def include?(arg)
  true
end

#loadObject

Creates a MatchFilter for specific tags or for all tags.



33
34
35
36
37
# File 'lib/mspec/runner/actions/taglist.rb', line 33

def load
  @filter = nil
  desc = MSpec.read_tags(@tags || self).map { |t| t.description }
  @filter = MatchFilter.new(nil, *desc) unless desc.empty?
end

#registerObject



45
46
47
48
49
# File 'lib/mspec/runner/actions/taglist.rb', line 45

def register
  MSpec.register :start, self
  MSpec.register :load,  self
  MSpec.register :after, self
end

#startObject

Prints a banner about matching tagged specs.



24
25
26
27
28
29
30
# File 'lib/mspec/runner/actions/taglist.rb', line 24

def start
  if @tags
    print "\nListing specs tagged with #{@tags.map { |t| "'#{t}'" }.join(", ") }\n\n"
  else
    print "\nListing all tagged specs\n\n"
  end
end

#unregisterObject



51
52
53
54
55
# File 'lib/mspec/runner/actions/taglist.rb', line 51

def unregister
  MSpec.unregister :start, self
  MSpec.unregister :load,  self
  MSpec.unregister :after, self
end