blob: c1aba5379488c08eac85820bd327b3744a8691e2 (
plain)
1
2
3
4
5
6
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
50
51
52
53
54
55
56
|
require 'mspec/runner/actions/filter'
# 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.
class TagListAction
def initialize(tags=nil)
@tags = tags.nil? || tags.empty? ? nil : Array(tags)
@filter = nil
end
# Returns true. This enables us to match any tag when loading
# tags from the file.
def include?(arg)
true
end
# Returns true if any tagged descriptions matches +string+.
def ===(string)
@filter === string
end
# Prints a banner about matching tagged specs.
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
# Creates a MatchFilter for specific tags or for all tags.
def load
@filter = nil
desc = MSpec.read_tags(@tags || self).map { |t| t.description }
@filter = MatchFilter.new(nil, *desc) unless desc.empty?
end
# Prints the spec description if it matches the filter.
def after(state)
return unless self === state.description
print state.description, "\n"
end
def register
MSpec.register :start, self
MSpec.register :load, self
MSpec.register :after, self
end
def unregister
MSpec.unregister :start, self
MSpec.unregister :load, self
MSpec.unregister :after, self
end
end
|