mspec 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/LICENSE +22 -0
  2. data/README +101 -0
  3. data/Rakefile +44 -0
  4. data/bin/mkspec +7 -0
  5. data/bin/mspec +7 -0
  6. data/bin/mspec-ci +8 -0
  7. data/bin/mspec-run +8 -0
  8. data/bin/mspec-tag +8 -0
  9. data/lib/mspec.rb +6 -0
  10. data/lib/mspec/commands/mkspec.rb +147 -0
  11. data/lib/mspec/commands/mspec-ci.rb +71 -0
  12. data/lib/mspec/commands/mspec-run.rb +80 -0
  13. data/lib/mspec/commands/mspec-tag.rb +87 -0
  14. data/lib/mspec/commands/mspec.rb +143 -0
  15. data/lib/mspec/expectations.rb +2 -0
  16. data/lib/mspec/expectations/expectations.rb +12 -0
  17. data/lib/mspec/expectations/should.rb +23 -0
  18. data/lib/mspec/guards.rb +13 -0
  19. data/lib/mspec/guards/bug.rb +27 -0
  20. data/lib/mspec/guards/compliance.rb +18 -0
  21. data/lib/mspec/guards/conflict.rb +16 -0
  22. data/lib/mspec/guards/endian.rb +40 -0
  23. data/lib/mspec/guards/extensions.rb +12 -0
  24. data/lib/mspec/guards/guard.rb +120 -0
  25. data/lib/mspec/guards/noncompliance.rb +12 -0
  26. data/lib/mspec/guards/platform.rb +38 -0
  27. data/lib/mspec/guards/quarantine.rb +15 -0
  28. data/lib/mspec/guards/runner.rb +30 -0
  29. data/lib/mspec/guards/superuser.rb +15 -0
  30. data/lib/mspec/guards/support.rb +12 -0
  31. data/lib/mspec/guards/version.rb +40 -0
  32. data/lib/mspec/helpers.rb +6 -0
  33. data/lib/mspec/helpers/bignum.rb +5 -0
  34. data/lib/mspec/helpers/const_lookup.rb +5 -0
  35. data/lib/mspec/helpers/flunk.rb +5 -0
  36. data/lib/mspec/helpers/io.rb +13 -0
  37. data/lib/mspec/helpers/scratch.rb +17 -0
  38. data/lib/mspec/helpers/tmp.rb +32 -0
  39. data/lib/mspec/matchers.rb +16 -0
  40. data/lib/mspec/matchers/base.rb +95 -0
  41. data/lib/mspec/matchers/be_ancestor_of.rb +24 -0
  42. data/lib/mspec/matchers/be_close.rb +27 -0
  43. data/lib/mspec/matchers/be_empty.rb +20 -0
  44. data/lib/mspec/matchers/be_false.rb +20 -0
  45. data/lib/mspec/matchers/be_kind_of.rb +24 -0
  46. data/lib/mspec/matchers/be_nil.rb +20 -0
  47. data/lib/mspec/matchers/be_true.rb +20 -0
  48. data/lib/mspec/matchers/complain.rb +56 -0
  49. data/lib/mspec/matchers/eql.rb +26 -0
  50. data/lib/mspec/matchers/equal.rb +26 -0
  51. data/lib/mspec/matchers/equal_utf16.rb +34 -0
  52. data/lib/mspec/matchers/include.rb +32 -0
  53. data/lib/mspec/matchers/output.rb +67 -0
  54. data/lib/mspec/matchers/output_to_fd.rb +71 -0
  55. data/lib/mspec/matchers/raise_error.rb +48 -0
  56. data/lib/mspec/mocks.rb +3 -0
  57. data/lib/mspec/mocks/mock.rb +123 -0
  58. data/lib/mspec/mocks/object.rb +28 -0
  59. data/lib/mspec/mocks/proxy.rb +112 -0
  60. data/lib/mspec/runner.rb +13 -0
  61. data/lib/mspec/runner/actions.rb +6 -0
  62. data/lib/mspec/runner/actions/debug.rb +17 -0
  63. data/lib/mspec/runner/actions/filter.rb +40 -0
  64. data/lib/mspec/runner/actions/gdb.rb +17 -0
  65. data/lib/mspec/runner/actions/tag.rb +97 -0
  66. data/lib/mspec/runner/actions/tally.rb +80 -0
  67. data/lib/mspec/runner/actions/timer.rb +22 -0
  68. data/lib/mspec/runner/filters.rb +4 -0
  69. data/lib/mspec/runner/filters/match.rb +22 -0
  70. data/lib/mspec/runner/filters/profile.rb +54 -0
  71. data/lib/mspec/runner/filters/regexp.rb +7 -0
  72. data/lib/mspec/runner/filters/tag.rb +29 -0
  73. data/lib/mspec/runner/formatters.rb +7 -0
  74. data/lib/mspec/runner/formatters/dotted.rb +81 -0
  75. data/lib/mspec/runner/formatters/html.rb +87 -0
  76. data/lib/mspec/runner/formatters/specdoc.rb +27 -0
  77. data/lib/mspec/runner/formatters/spinner.rb +89 -0
  78. data/lib/mspec/runner/formatters/summary.rb +8 -0
  79. data/lib/mspec/runner/formatters/unit.rb +25 -0
  80. data/lib/mspec/runner/formatters/yaml.rb +43 -0
  81. data/lib/mspec/runner/mspec.rb +232 -0
  82. data/lib/mspec/runner/object.rb +20 -0
  83. data/lib/mspec/runner/shared.rb +12 -0
  84. data/lib/mspec/runner/state.rb +116 -0
  85. data/lib/mspec/runner/tag.rb +20 -0
  86. data/lib/mspec/utils/name_map.rb +130 -0
  87. data/lib/mspec/utils/options.rb +344 -0
  88. data/lib/mspec/utils/script.rb +77 -0
  89. data/lib/mspec/version.rb +3 -0
  90. data/spec/commands/mkspec_spec.rb +321 -0
  91. data/spec/commands/mspec_ci_spec.rb +139 -0
  92. data/spec/commands/mspec_run_spec.rb +146 -0
  93. data/spec/commands/mspec_spec.rb +359 -0
  94. data/spec/commands/mspec_tag_spec.rb +131 -0
  95. data/spec/expectations/expectations_spec.rb +16 -0
  96. data/spec/expectations/should_spec.rb +99 -0
  97. data/spec/guards/bug_spec.rb +137 -0
  98. data/spec/guards/compliance_spec.rb +70 -0
  99. data/spec/guards/conflict_spec.rb +20 -0
  100. data/spec/guards/endian_spec.rb +42 -0
  101. data/spec/guards/extensions_spec.rb +36 -0
  102. data/spec/guards/guard_spec.rb +355 -0
  103. data/spec/guards/noncompliance_spec.rb +36 -0
  104. data/spec/guards/platform_spec.rb +84 -0
  105. data/spec/guards/quarantine_spec.rb +19 -0
  106. data/spec/guards/runner_spec.rb +75 -0
  107. data/spec/guards/superuser_spec.rb +22 -0
  108. data/spec/guards/support_spec.rb +22 -0
  109. data/spec/guards/version_spec.rb +133 -0
  110. data/spec/helpers/bignum_spec.rb +11 -0
  111. data/spec/helpers/const_lookup_spec.rb +19 -0
  112. data/spec/helpers/flunk_spec.rb +15 -0
  113. data/spec/helpers/io_spec.rb +34 -0
  114. data/spec/helpers/scratch_spec.rb +22 -0
  115. data/spec/helpers/tmp_spec.rb +72 -0
  116. data/spec/matchers/base_spec.rb +180 -0
  117. data/spec/matchers/be_ancestor_of_spec.rb +28 -0
  118. data/spec/matchers/be_close_spec.rb +46 -0
  119. data/spec/matchers/be_empty_spec.rb +26 -0
  120. data/spec/matchers/be_false_spec.rb +28 -0
  121. data/spec/matchers/be_kind_of_spec.rb +29 -0
  122. data/spec/matchers/be_nil_spec.rb +27 -0
  123. data/spec/matchers/be_true_spec.rb +28 -0
  124. data/spec/matchers/complain_spec.rb +52 -0
  125. data/spec/matchers/eql_spec.rb +33 -0
  126. data/spec/matchers/equal_spec.rb +33 -0
  127. data/spec/matchers/equal_utf16_spec.rb +47 -0
  128. data/spec/matchers/include_spec.rb +37 -0
  129. data/spec/matchers/output_spec.rb +74 -0
  130. data/spec/matchers/output_to_fd_spec.rb +33 -0
  131. data/spec/matchers/raise_error_spec.rb +56 -0
  132. data/spec/mocks/mock_spec.rb +272 -0
  133. data/spec/mocks/proxy_spec.rb +259 -0
  134. data/spec/runner/actions/debug_spec.rb +61 -0
  135. data/spec/runner/actions/filter_spec.rb +84 -0
  136. data/spec/runner/actions/gdb_spec.rb +61 -0
  137. data/spec/runner/actions/tag_spec.rb +253 -0
  138. data/spec/runner/actions/tally_spec.rb +107 -0
  139. data/spec/runner/actions/timer_spec.rb +42 -0
  140. data/spec/runner/filters/a.yaml +4 -0
  141. data/spec/runner/filters/b.yaml +11 -0
  142. data/spec/runner/filters/match_spec.rb +44 -0
  143. data/spec/runner/filters/profile_spec.rb +117 -0
  144. data/spec/runner/filters/regexp_spec.rb +13 -0
  145. data/spec/runner/filters/tag_spec.rb +77 -0
  146. data/spec/runner/formatters/dotted_spec.rb +184 -0
  147. data/spec/runner/formatters/html_spec.rb +191 -0
  148. data/spec/runner/formatters/specdoc_spec.rb +57 -0
  149. data/spec/runner/formatters/spinner_spec.rb +78 -0
  150. data/spec/runner/formatters/summary_spec.rb +29 -0
  151. data/spec/runner/formatters/unit_spec.rb +71 -0
  152. data/spec/runner/formatters/yaml_spec.rb +123 -0
  153. data/spec/runner/mspec_spec.rb +393 -0
  154. data/spec/runner/shared_spec.rb +41 -0
  155. data/spec/runner/state_spec.rb +535 -0
  156. data/spec/runner/tag_spec.rb +93 -0
  157. data/spec/runner/tags.txt +3 -0
  158. data/spec/spec_helper.rb +46 -0
  159. data/spec/utils/name_map_spec.rb +178 -0
  160. data/spec/utils/options_spec.rb +862 -0
  161. data/spec/utils/script_spec.rb +240 -0
  162. metadata +217 -0
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/actions/debug'
3
+ require 'mspec/runner/mspec'
4
+ require 'mspec/runner/state'
5
+
6
+ describe DebugAction do
7
+ before :each do
8
+ MSpec.stub!(:read_tags).and_return([])
9
+ end
10
+
11
+ it "creates an MatchFilter with its tag and desc arguments" do
12
+ filter = mock('action filter', :null_object => true)
13
+ MatchFilter.should_receive(:new).with(nil, "some", "thing").and_return(filter)
14
+ DebugAction.new ["tag", "key"], ["some", "thing"]
15
+ end
16
+ end
17
+
18
+ describe DebugAction, "#before" do
19
+ before :each do
20
+ MSpec.stub!(:read_tags).and_return([])
21
+ @state = SpecState.new "Catch#me", "if you can"
22
+ end
23
+
24
+ it "does not invoke the debugger if the description does not match" do
25
+ Kernel.should_not_receive(:debugger)
26
+ action = DebugAction.new nil, "match"
27
+ action.before @state
28
+ end
29
+
30
+ it "invokes the debugger if the description matches" do
31
+ Kernel.should_receive(:debugger)
32
+ action = DebugAction.new nil, "can"
33
+ action.before @state
34
+ end
35
+ end
36
+
37
+ describe DebugAction, "#register" do
38
+ before :each do
39
+ MSpec.stub!(:read_tags).and_return([])
40
+ MSpec.stub!(:register)
41
+ @action = DebugAction.new nil, nil
42
+ end
43
+
44
+ it "registers itself with MSpec for the :before action" do
45
+ MSpec.should_receive(:register).with(:before, @action)
46
+ @action.register
47
+ end
48
+ end
49
+
50
+ describe DebugAction, "#unregister" do
51
+ before :each do
52
+ MSpec.stub!(:read_tags).and_return([])
53
+ MSpec.stub!(:unregister)
54
+ @action = DebugAction.new nil, nil
55
+ end
56
+
57
+ it "unregisters itself with MSpec for the :before action" do
58
+ MSpec.should_receive(:unregister).with(:before, @action)
59
+ @action.unregister
60
+ end
61
+ end
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/actions/filter'
3
+ require 'mspec/runner/mspec'
4
+ require 'mspec/runner/tag'
5
+
6
+ describe ActionFilter do
7
+ it "creates a filter when not passed a description" do
8
+ MatchFilter.should_not_receive(:new)
9
+ ActionFilter.new(nil, nil)
10
+ end
11
+
12
+ it "creates a filter from a single description" do
13
+ MatchFilter.should_receive(:new).with(nil, "match me")
14
+ ActionFilter.new(nil, "match me")
15
+ end
16
+
17
+ it "creates a filter from an array of descriptions" do
18
+ MatchFilter.should_receive(:new).with(nil, "match me", "again")
19
+ ActionFilter.new(nil, ["match me", "again"])
20
+ end
21
+ end
22
+
23
+ describe ActionFilter, "#===" do
24
+ before :each do
25
+ MSpec.stub!(:read_tags).and_return(["match"])
26
+ @action = ActionFilter.new(nil, ["catch", "if you"])
27
+ end
28
+
29
+ it "returns false if there are no filters" do
30
+ action = ActionFilter.new
31
+ action.===("anything").should == false
32
+ end
33
+
34
+ it "returns true if the argument matches any of the descriptions" do
35
+ @action.===("catch").should == true
36
+ @action.===("if you can").should == true
37
+ end
38
+
39
+ it "returns false if the argument does not match any of the descriptions" do
40
+ @action.===("patch me").should == false
41
+ @action.===("if I can").should == false
42
+ end
43
+ end
44
+
45
+ describe ActionFilter, "#load" do
46
+ before :each do
47
+ @tag = SpecTag.new "tag(comment):description"
48
+ end
49
+
50
+ it "creates a filter from a single tag" do
51
+ MSpec.should_receive(:read_tags).with("tag").and_return([@tag])
52
+ MatchFilter.should_receive(:new).with(nil, "description")
53
+ ActionFilter.new("tag", nil).load
54
+ end
55
+
56
+ it "creates a filter from an array of tags" do
57
+ MSpec.should_receive(:read_tags).with("tag", "key").and_return([@tag])
58
+ MatchFilter.should_receive(:new).with(nil, "description")
59
+ ActionFilter.new(["tag", "key"], nil).load
60
+ end
61
+
62
+ it "creates a filter from both tags and descriptions" do
63
+ MSpec.should_receive(:read_tags).and_return([@tag])
64
+ filter = ActionFilter.new("tag", ["match me", "again"])
65
+ MatchFilter.should_receive(:new).with(nil, "description")
66
+ filter.load
67
+ end
68
+ end
69
+
70
+ describe ActionFilter, "#register" do
71
+ it "registers itself with MSpec for the :load, :unload actions" do
72
+ filter = ActionFilter.new
73
+ MSpec.should_receive(:register).with(:load, filter)
74
+ filter.register
75
+ end
76
+ end
77
+
78
+ describe ActionFilter, "#unregister" do
79
+ it "unregisters itself with MSpec for the :load, :unload actions" do
80
+ filter = ActionFilter.new
81
+ MSpec.should_receive(:unregister).with(:load, filter)
82
+ filter.unregister
83
+ end
84
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/actions/gdb'
3
+ require 'mspec/runner/mspec'
4
+ require 'mspec/runner/state'
5
+
6
+ describe GdbAction do
7
+ before :each do
8
+ MSpec.stub!(:read_tags).and_return([])
9
+ end
10
+
11
+ it "creates an MatchFilter with its tag and desc arguments" do
12
+ filter = mock('action filter', :null_object => true)
13
+ MatchFilter.should_receive(:new).with(nil, "some", "thing").and_return(filter)
14
+ GdbAction.new ["tag", "key"], ["some", "thing"]
15
+ end
16
+ end
17
+
18
+ describe GdbAction, "#before" do
19
+ before :each do
20
+ MSpec.stub!(:read_tags).and_return([])
21
+ @state = SpecState.new "Catch#me", "if you can"
22
+ end
23
+
24
+ it "does not invoke the debugger if the description does not match" do
25
+ Kernel.should_not_receive(:yield_gdb)
26
+ action = GdbAction.new nil, "match"
27
+ action.before @state
28
+ end
29
+
30
+ it "invokes the debugger if the description matches" do
31
+ Kernel.should_receive(:yield_gdb).with(true)
32
+ action = GdbAction.new nil, "can"
33
+ action.before @state
34
+ end
35
+ end
36
+
37
+ describe GdbAction, "#register" do
38
+ before :each do
39
+ MSpec.stub!(:read_tags).and_return([])
40
+ MSpec.stub!(:register)
41
+ @action = GdbAction.new nil, nil
42
+ end
43
+
44
+ it "registers itself with MSpec for the :before action" do
45
+ MSpec.should_receive(:register).with(:before, @action)
46
+ @action.register
47
+ end
48
+ end
49
+
50
+ describe GdbAction, "#unregister" do
51
+ before :each do
52
+ MSpec.stub!(:read_tags).and_return([])
53
+ MSpec.stub!(:unregister)
54
+ @action = GdbAction.new nil, nil
55
+ end
56
+
57
+ it "unregisters itself with MSpec for the :before action" do
58
+ MSpec.should_receive(:unregister).with(:before, @action)
59
+ @action.unregister
60
+ end
61
+ end
@@ -0,0 +1,253 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/actions/tag'
3
+ require 'mspec/runner/mspec'
4
+ require 'mspec/runner/state'
5
+ require 'mspec/runner/tag'
6
+
7
+ describe TagAction do
8
+ before :each do
9
+ MSpec.stub!(:read_tags).and_return([])
10
+ end
11
+
12
+ it "creates an MatchFilter with its tag and desc arguments" do
13
+ filter = mock('action filter', :null_object => true)
14
+ MatchFilter.should_receive(:new).with(nil, "some", "thing").and_return(filter)
15
+ TagAction.new :add, :all, nil, nil, ["tag", "key"], ["some", "thing"]
16
+ end
17
+ end
18
+
19
+ describe TagAction, "#===" do
20
+ before :each do
21
+ MSpec.stub!(:read_tags).and_return(["match"])
22
+ @action = TagAction.new :add, :fail, nil, nil, nil, ["catch", "if you"]
23
+ end
24
+
25
+ it "returns true if there are no filters" do
26
+ action = TagAction.new :add, :all, nil, nil
27
+ action.===("anything").should == true
28
+ end
29
+
30
+ it "returns true if the argument matches any of the descriptions" do
31
+ @action.===("catch").should == true
32
+ @action.===("if you can").should == true
33
+ end
34
+
35
+ it "returns false if the argument does not match any of the descriptions" do
36
+ @action.===("patch me").should == false
37
+ @action.===("if I can").should == false
38
+ end
39
+ end
40
+
41
+ describe TagAction, "#outcome?" do
42
+ before :each do
43
+ MSpec.stub!(:read_tags).and_return([])
44
+ @state = SpecState.new "describe", "it"
45
+ @exception = [nil, Exception.new("failed")]
46
+ end
47
+
48
+ it "returns true if outcome is :fail and the spec fails" do
49
+ action = TagAction.new :add, :fail, nil, nil, nil, nil
50
+ @state.exceptions << @exception
51
+ action.outcome?(@state).should == true
52
+ end
53
+
54
+ it "returns false if the outcome is :fail and the spec passes" do
55
+ action = TagAction.new :add, :fail, nil, nil, nil, nil
56
+ action.outcome?(@state).should == false
57
+ end
58
+
59
+ it "returns true if the outcome is :pass and the spec passes" do
60
+ action = TagAction.new :del, :pass, nil, nil, nil, nil
61
+ action.outcome?(@state).should == true
62
+ end
63
+
64
+ it "returns false if the outcome is :pass and the spec fails" do
65
+ action = TagAction.new :del, :pass, nil, nil, nil, nil
66
+ @state.exceptions << @exception
67
+ action.outcome?(@state).should == false
68
+ end
69
+
70
+ it "returns true if the outcome is :all" do
71
+ action = TagAction.new :add, :all, nil, nil, nil, nil
72
+ @state.exceptions << @exception
73
+ action.outcome?(@state).should == true
74
+ end
75
+ end
76
+
77
+ describe TagAction, "#after when action is :add" do
78
+ before :each do
79
+ MSpec.stub!(:read_tags).and_return([])
80
+ @state = SpecState.new "Catch#me", "if you can"
81
+ @tag = SpecTag.new "tag(comment):Catch#me if you can"
82
+ SpecTag.stub!(:new).and_return(@tag)
83
+ @exception = [nil, Exception.new("failed")]
84
+ end
85
+
86
+ it "does not write a tag if the description does not match" do
87
+ MSpec.should_not_receive(:write_tag)
88
+ action = TagAction.new :add, :all, "tag", "comment", nil, "match"
89
+ action.after @state
90
+ end
91
+
92
+ it "does not write a tag if outcome is :fail and the spec passed" do
93
+ MSpec.should_not_receive(:write_tag)
94
+ action = TagAction.new :add, :fail, "tag", "comment", nil, "can"
95
+ action.after @state
96
+ end
97
+
98
+ it "writes a tag if the outcome is :fail and the spec failed" do
99
+ MSpec.should_receive(:write_tag).with(@tag)
100
+ action = TagAction.new :add, :fail, "tag", "comment", nil, "can"
101
+ @state.exceptions << @exception
102
+ action.after @state
103
+ end
104
+
105
+ it "does not write a tag if outcome is :pass and the spec failed" do
106
+ MSpec.should_not_receive(:write_tag)
107
+ action = TagAction.new :add, :pass, "tag", "comment", nil, "can"
108
+ @state.exceptions << @exception
109
+ action.after @state
110
+ end
111
+
112
+ it "writes a tag if the outcome is :pass and the spec passed" do
113
+ MSpec.should_receive(:write_tag).with(@tag)
114
+ action = TagAction.new :add, :pass, "tag", "comment", nil, "can"
115
+ action.after @state
116
+ end
117
+
118
+ it "writes a tag if the outcome is :all" do
119
+ MSpec.should_receive(:write_tag).with(@tag)
120
+ action = TagAction.new :add, :all, "tag", "comment", nil, "can"
121
+ action.after @state
122
+ end
123
+ end
124
+
125
+ describe TagAction, "#after when action is :del" do
126
+ before :each do
127
+ MSpec.stub!(:read_tags).and_return([])
128
+ @state = SpecState.new "Catch#me", "if you can"
129
+ @tag = SpecTag.new "tag(comment):Catch#me if you can"
130
+ SpecTag.stub!(:new).and_return(@tag)
131
+ @exception = [nil, Exception.new("failed")]
132
+ end
133
+
134
+ it "does not delete a tag if the description does not match" do
135
+ MSpec.should_not_receive(:delete_tag)
136
+ action = TagAction.new :del, :all, "tag", "comment", nil, "match"
137
+ action.after @state
138
+ end
139
+
140
+ it "does not delete a tag if outcome is :fail and the spec passed" do
141
+ MSpec.should_not_receive(:delete_tag)
142
+ action = TagAction.new :del, :fail, "tag", "comment", nil, "can"
143
+ action.after @state
144
+ end
145
+
146
+ it "deletes a tag if the outcome is :fail and the spec failed" do
147
+ MSpec.should_receive(:delete_tag).with(@tag)
148
+ action = TagAction.new :del, :fail, "tag", "comment", nil, "can"
149
+ @state.exceptions << @exception
150
+ action.after @state
151
+ end
152
+
153
+ it "does not delete a tag if outcome is :pass and the spec failed" do
154
+ MSpec.should_not_receive(:delete_tag)
155
+ action = TagAction.new :del, :pass, "tag", "comment", nil, "can"
156
+ @state.exceptions << @exception
157
+ action.after @state
158
+ end
159
+
160
+ it "deletes a tag if the outcome is :pass and the spec passed" do
161
+ MSpec.should_receive(:delete_tag).with(@tag)
162
+ action = TagAction.new :del, :pass, "tag", "comment", nil, "can"
163
+ action.after @state
164
+ end
165
+
166
+ it "deletes a tag if the outcome is :all" do
167
+ MSpec.should_receive(:delete_tag).with(@tag)
168
+ action = TagAction.new :del, :all, "tag", "comment", nil, "can"
169
+ action.after @state
170
+ end
171
+ end
172
+
173
+ describe TagAction, "#finish" do
174
+ before :each do
175
+ $stdout = @out = IOStub.new
176
+ @state = SpecState.new "Catch#me", "if you can"
177
+ MSpec.stub!(:write_tag).and_return(true)
178
+ MSpec.stub!(:delete_tag).and_return(true)
179
+ end
180
+
181
+ after :each do
182
+ $stdout = STDOUT
183
+ end
184
+
185
+ it "reports no specs tagged if none where tagged" do
186
+ action = TagAction.new :add, :fail, "tag", "comment", nil, "can"
187
+ action.stub!(:outcome?).and_return(false)
188
+ action.after @state
189
+ action.finish
190
+ @out.should == "\nTagAction: no specs were tagged with 'tag'\n"
191
+ end
192
+
193
+ it "reports no specs tagged if none where tagged" do
194
+ action = TagAction.new :del, :fail, "tag", "comment", nil, "can"
195
+ action.stub!(:outcome?).and_return(false)
196
+ action.after @state
197
+ action.finish
198
+ @out.should == "\nTagAction: no tags 'tag' were deleted\n"
199
+ end
200
+
201
+ it "reports the spec descriptions that were tagged" do
202
+ action = TagAction.new :add, :fail, "tag", "comment", nil, "can"
203
+ action.stub!(:outcome?).and_return(true)
204
+ action.after @state
205
+ action.finish
206
+ @out.should ==
207
+ %[
208
+ TagAction: specs tagged with 'tag':
209
+
210
+ Catch#me if you can
211
+ ]
212
+ end
213
+
214
+ it "reports the spec descriptions for the tags that were deleted" do
215
+ action = TagAction.new :del, :fail, "tag", "comment", nil, "can"
216
+ action.stub!(:outcome?).and_return(true)
217
+ action.after @state
218
+ action.finish
219
+ @out.should ==
220
+ %[
221
+ TagAction: tag 'tag' deleted for specs:
222
+
223
+ Catch#me if you can
224
+ ]
225
+ end
226
+ end
227
+
228
+ describe TagAction, "#register" do
229
+ before :each do
230
+ MSpec.stub!(:register)
231
+ MSpec.stub!(:read_tags).and_return([])
232
+ @action = TagAction.new :add, :all, nil, nil, nil, nil
233
+ end
234
+
235
+ it "registers itself with MSpec for the :after action" do
236
+ MSpec.should_receive(:register).with(:after, @action)
237
+ MSpec.should_receive(:register).with(:finish, @action)
238
+ @action.register
239
+ end
240
+ end
241
+
242
+ describe TagAction, "#unregister" do
243
+ before :each do
244
+ MSpec.stub!(:unregister)
245
+ MSpec.stub!(:read_tags).and_return([])
246
+ @action = TagAction.new :add, :all, nil, nil, nil, nil
247
+ end
248
+
249
+ it "unregisters itself with MSpec for the :after action" do
250
+ MSpec.should_receive(:unregister).with(:after, @action)
251
+ @action.unregister
252
+ end
253
+ end