summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/runner/actions/taglist_spec.rb
blob: 418c761c2dcf7b02b990c28d6e58595745540f83 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/actions/taglist'
require 'mspec/runner/mspec'
require 'mspec/runner/example'
require 'mspec/runner/tag'

describe TagListAction, "#include?" do
  it "returns true" do
    TagListAction.new.include?(:anything).should be_true
  end
end

describe TagListAction, "#===" do
  before :each do
    tag = SpecTag.new "fails:description"
    MSpec.stub(:read_tags).and_return([tag])
    @filter = double("MatchFilter").as_null_object
    MatchFilter.stub(:new).and_return(@filter)
    @action = TagListAction.new
    @action.load
  end

  it "returns true if filter === string returns true" do
    @filter.should_receive(:===).with("str").and_return(true)
    @action.===("str").should be_true
  end

  it "returns false if filter === string returns false" do
    @filter.should_receive(:===).with("str").and_return(false)
    @action.===("str").should be_false
  end
end

describe TagListAction, "#start" do
  before :each do
    @stdout = $stdout
    $stdout = IOStub.new
  end

  after :each do
    $stdout = @stdout
  end

  it "prints a banner for specific tags" do
    action = TagListAction.new ["fails", "unstable"]
    action.start
    $stdout.should == "\nListing specs tagged with 'fails', 'unstable'\n\n"
  end

  it "prints a banner for all tags" do
    action = TagListAction.new
    action.start
    $stdout.should == "\nListing all tagged specs\n\n"
  end
end

describe TagListAction, "#load" do
  before :each do
    @t1 = SpecTag.new "fails:I fail"
    @t2 = SpecTag.new "unstable:I'm unstable"
  end

  it "creates a MatchFilter for matching tags" do
    MSpec.should_receive(:read_tags).with(["fails"]).and_return([@t1])
    MatchFilter.should_receive(:new).with(nil, "I fail")
    TagListAction.new(["fails"]).load
  end

  it "creates a MatchFilter for all tags" do
    MSpec.should_receive(:read_tags).and_return([@t1, @t2])
    MatchFilter.should_receive(:new).with(nil, "I fail", "I'm unstable")
    TagListAction.new.load
  end

  it "does not create a MatchFilter if there are no matching tags" do
    MSpec.stub(:read_tags).and_return([])
    MatchFilter.should_not_receive(:new)
    TagListAction.new(["fails"]).load
  end
end

describe TagListAction, "#after" do
  before :each do
    @stdout = $stdout
    $stdout = IOStub.new

    @state = double("ExampleState")
    @state.stub(:description).and_return("str")

    @action = TagListAction.new
  end

  after :each do
    $stdout = @stdout
  end

  it "prints nothing if the filter does not match" do
    @action.should_receive(:===).with("str").and_return(false)
    @action.after(@state)
    $stdout.should == ""
  end

  it "prints the example description if the filter matches" do
    @action.should_receive(:===).with("str").and_return(true)
    @action.after(@state)
    $stdout.should == "str\n"
  end
end

describe TagListAction, "#register" do
  before :each do
    MSpec.stub(:register)
    @action = TagListAction.new
  end

  it "registers itself with MSpec for the :start event" do
    MSpec.should_receive(:register).with(:start, @action)
    @action.register
  end

  it "registers itself with MSpec for the :load event" do
    MSpec.should_receive(:register).with(:load, @action)
    @action.register
  end

  it "registers itself with MSpec for the :after event" do
    MSpec.should_receive(:register).with(:after, @action)
    @action.register
  end
end

describe TagListAction, "#unregister" do
  before :each do
    MSpec.stub(:unregister)
    @action = TagListAction.new
  end

  it "unregisters itself with MSpec for the :start event" do
    MSpec.should_receive(:unregister).with(:start, @action)
    @action.unregister
  end

  it "unregisters itself with MSpec for the :load event" do
    MSpec.should_receive(:unregister).with(:load, @action)
    @action.unregister
  end

  it "unregisters itself with MSpec for the :after event" do
    MSpec.should_receive(:unregister).with(:after, @action)
    @action.unregister
  end
end