rspec-core 2.11.1 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +3 -1
  5. data/Changelog.md +1814 -29
  6. data/{License.txt → LICENSE.md} +6 -4
  7. data/README.md +197 -48
  8. data/exe/rspec +2 -23
  9. data/lib/rspec/autorun.rb +1 -0
  10. data/lib/rspec/core/backtrace_formatter.rb +65 -0
  11. data/lib/rspec/core/bisect/coordinator.rb +62 -0
  12. data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
  13. data/lib/rspec/core/bisect/fork_runner.rb +138 -0
  14. data/lib/rspec/core/bisect/server.rb +61 -0
  15. data/lib/rspec/core/bisect/shell_command.rb +126 -0
  16. data/lib/rspec/core/bisect/shell_runner.rb +73 -0
  17. data/lib/rspec/core/bisect/utilities.rb +69 -0
  18. data/lib/rspec/core/configuration.rb +1846 -407
  19. data/lib/rspec/core/configuration_options.rb +154 -50
  20. data/lib/rspec/core/did_you_mean.rb +46 -0
  21. data/lib/rspec/core/drb.rb +120 -0
  22. data/lib/rspec/core/dsl.rb +90 -18
  23. data/lib/rspec/core/example.rb +488 -152
  24. data/lib/rspec/core/example_group.rb +733 -294
  25. data/lib/rspec/core/example_status_persister.rb +235 -0
  26. data/lib/rspec/core/filter_manager.rb +175 -147
  27. data/lib/rspec/core/flat_map.rb +20 -0
  28. data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
  29. data/lib/rspec/core/formatters/base_formatter.rb +32 -130
  30. data/lib/rspec/core/formatters/base_text_formatter.rb +62 -190
  31. data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
  32. data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
  33. data/lib/rspec/core/formatters/console_codes.rb +76 -0
  34. data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
  35. data/lib/rspec/core/formatters/documentation_formatter.rb +62 -27
  36. data/lib/rspec/core/formatters/exception_presenter.rb +521 -0
  37. data/lib/rspec/core/formatters/failure_list_formatter.rb +23 -0
  38. data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
  39. data/lib/rspec/core/formatters/helpers.rb +93 -14
  40. data/lib/rspec/core/formatters/html_formatter.rb +104 -415
  41. data/lib/rspec/core/formatters/html_printer.rb +414 -0
  42. data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
  43. data/lib/rspec/core/formatters/json_formatter.rb +102 -0
  44. data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
  45. data/lib/rspec/core/formatters/progress_formatter.rb +12 -15
  46. data/lib/rspec/core/formatters/protocol.rb +182 -0
  47. data/lib/rspec/core/formatters/snippet_extractor.rb +115 -39
  48. data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
  49. data/lib/rspec/core/formatters.rb +279 -0
  50. data/lib/rspec/core/hooks.rb +451 -300
  51. data/lib/rspec/core/invocations.rb +87 -0
  52. data/lib/rspec/core/memoized_helpers.rb +580 -0
  53. data/lib/rspec/core/metadata.rb +395 -173
  54. data/lib/rspec/core/metadata_filter.rb +255 -0
  55. data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
  56. data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
  57. data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
  58. data/lib/rspec/core/mocking_adapters/null.rb +14 -0
  59. data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
  60. data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
  61. data/lib/rspec/core/notifications.rb +521 -0
  62. data/lib/rspec/core/option_parser.rb +208 -64
  63. data/lib/rspec/core/ordering.rb +169 -0
  64. data/lib/rspec/core/output_wrapper.rb +29 -0
  65. data/lib/rspec/core/pending.rb +115 -59
  66. data/lib/rspec/core/profiler.rb +34 -0
  67. data/lib/rspec/core/project_initializer/.rspec +1 -0
  68. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +98 -0
  69. data/lib/rspec/core/project_initializer.rb +26 -65
  70. data/lib/rspec/core/rake_task.rb +140 -131
  71. data/lib/rspec/core/reporter.rb +207 -44
  72. data/lib/rspec/core/ruby_project.rb +15 -6
  73. data/lib/rspec/core/runner.rb +180 -44
  74. data/lib/rspec/core/sandbox.rb +37 -0
  75. data/lib/rspec/core/set.rb +54 -0
  76. data/lib/rspec/core/shared_context.rb +25 -19
  77. data/lib/rspec/core/shared_example_group.rb +229 -54
  78. data/lib/rspec/core/shell_escape.rb +49 -0
  79. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  80. data/lib/rspec/core/version.rb +3 -1
  81. data/lib/rspec/core/warnings.rb +40 -0
  82. data/lib/rspec/core/world.rb +208 -49
  83. data/lib/rspec/core.rb +166 -80
  84. data.tar.gz.sig +0 -0
  85. metadata +230 -445
  86. metadata.gz.sig +0 -0
  87. data/exe/autospec +0 -13
  88. data/features/Autotest.md +0 -38
  89. data/features/README.md +0 -17
  90. data/features/Upgrade.md +0 -364
  91. data/features/command_line/README.md +0 -28
  92. data/features/command_line/example_name_option.feature +0 -101
  93. data/features/command_line/exit_status.feature +0 -83
  94. data/features/command_line/format_option.feature +0 -81
  95. data/features/command_line/init.feature +0 -18
  96. data/features/command_line/line_number_appended_to_path.feature +0 -140
  97. data/features/command_line/line_number_option.feature +0 -58
  98. data/features/command_line/order.feature +0 -29
  99. data/features/command_line/pattern_option.feature +0 -31
  100. data/features/command_line/rake_task.feature +0 -68
  101. data/features/command_line/ruby.feature +0 -22
  102. data/features/command_line/tag.feature +0 -91
  103. data/features/configuration/alias_example_to.feature +0 -48
  104. data/features/configuration/custom_settings.feature +0 -84
  105. data/features/configuration/default_path.feature +0 -38
  106. data/features/configuration/fail_fast.feature +0 -77
  107. data/features/configuration/read_options_from_file.feature +0 -87
  108. data/features/example_groups/basic_structure.feature +0 -55
  109. data/features/example_groups/shared_context.feature +0 -74
  110. data/features/example_groups/shared_examples.feature +0 -204
  111. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
  112. data/features/filtering/exclusion_filters.feature +0 -139
  113. data/features/filtering/if_and_unless.feature +0 -168
  114. data/features/filtering/inclusion_filters.feature +0 -105
  115. data/features/filtering/run_all_when_everything_filtered.feature +0 -46
  116. data/features/formatters/custom_formatter.feature +0 -36
  117. data/features/formatters/text_formatter.feature +0 -46
  118. data/features/helper_methods/arbitrary_methods.feature +0 -40
  119. data/features/helper_methods/let.feature +0 -50
  120. data/features/helper_methods/modules.feature +0 -149
  121. data/features/hooks/around_hooks.feature +0 -343
  122. data/features/hooks/before_and_after_hooks.feature +0 -423
  123. data/features/hooks/filtering.feature +0 -234
  124. data/features/metadata/current_example.feature +0 -17
  125. data/features/metadata/described_class.feature +0 -17
  126. data/features/metadata/user_defined.feature +0 -113
  127. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  128. data/features/mock_framework_integration/use_flexmock.feature +0 -96
  129. data/features/mock_framework_integration/use_mocha.feature +0 -97
  130. data/features/mock_framework_integration/use_rr.feature +0 -98
  131. data/features/mock_framework_integration/use_rspec.feature +0 -97
  132. data/features/pending/pending_examples.feature +0 -229
  133. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  134. data/features/step_definitions/additional_cli_steps.rb +0 -30
  135. data/features/subject/attribute_of_subject.feature +0 -124
  136. data/features/subject/explicit_subject.feature +0 -82
  137. data/features/subject/implicit_receiver.feature +0 -29
  138. data/features/subject/implicit_subject.feature +0 -63
  139. data/features/support/env.rb +0 -12
  140. data/lib/autotest/discover.rb +0 -1
  141. data/lib/autotest/rspec2.rb +0 -73
  142. data/lib/rspec/core/backward_compatibility.rb +0 -65
  143. data/lib/rspec/core/command_line.rb +0 -36
  144. data/lib/rspec/core/deprecation.rb +0 -36
  145. data/lib/rspec/core/drb_command_line.rb +0 -26
  146. data/lib/rspec/core/drb_options.rb +0 -87
  147. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  148. data/lib/rspec/core/extensions/kernel.rb +0 -9
  149. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  150. data/lib/rspec/core/extensions/ordered.rb +0 -21
  151. data/lib/rspec/core/extensions.rb +0 -4
  152. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  153. data/lib/rspec/core/let.rb +0 -110
  154. data/lib/rspec/core/load_path.rb +0 -3
  155. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  156. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  157. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  158. data/lib/rspec/core/mocking/with_mocha.rb +0 -29
  159. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  160. data/lib/rspec/core/mocking/with_rspec.rb +0 -23
  161. data/lib/rspec/core/subject.rb +0 -219
  162. data/spec/autotest/discover_spec.rb +0 -19
  163. data/spec/autotest/failed_results_re_spec.rb +0 -45
  164. data/spec/autotest/rspec_spec.rb +0 -123
  165. data/spec/command_line/order_spec.rb +0 -137
  166. data/spec/rspec/core/command_line_spec.rb +0 -108
  167. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  168. data/spec/rspec/core/configuration_options_spec.rb +0 -377
  169. data/spec/rspec/core/configuration_spec.rb +0 -1196
  170. data/spec/rspec/core/deprecations_spec.rb +0 -66
  171. data/spec/rspec/core/drb_command_line_spec.rb +0 -108
  172. data/spec/rspec/core/drb_options_spec.rb +0 -180
  173. data/spec/rspec/core/dsl_spec.rb +0 -17
  174. data/spec/rspec/core/example_group_spec.rb +0 -1098
  175. data/spec/rspec/core/example_spec.rb +0 -370
  176. data/spec/rspec/core/filter_manager_spec.rb +0 -256
  177. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -80
  178. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -363
  179. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -88
  180. data/spec/rspec/core/formatters/helpers_spec.rb +0 -66
  181. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +0 -410
  182. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +0 -409
  183. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -416
  184. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -416
  185. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -82
  186. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
  187. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -18
  188. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +0 -410
  189. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +0 -409
  190. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +0 -416
  191. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +0 -416
  192. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -83
  193. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  194. data/spec/rspec/core/hooks_spec.rb +0 -250
  195. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  196. data/spec/rspec/core/let_spec.rb +0 -55
  197. data/spec/rspec/core/metadata_spec.rb +0 -447
  198. data/spec/rspec/core/option_parser_spec.rb +0 -166
  199. data/spec/rspec/core/pending_example_spec.rb +0 -220
  200. data/spec/rspec/core/project_initializer_spec.rb +0 -130
  201. data/spec/rspec/core/rake_task_spec.rb +0 -138
  202. data/spec/rspec/core/reporter_spec.rb +0 -103
  203. data/spec/rspec/core/resources/a_bar.rb +0 -0
  204. data/spec/rspec/core/resources/a_foo.rb +0 -0
  205. data/spec/rspec/core/resources/a_spec.rb +0 -1
  206. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  207. data/spec/rspec/core/resources/formatter_specs.rb +0 -60
  208. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  209. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  210. data/spec/rspec/core/ruby_project_spec.rb +0 -24
  211. data/spec/rspec/core/runner_spec.rb +0 -81
  212. data/spec/rspec/core/shared_context_spec.rb +0 -67
  213. data/spec/rspec/core/shared_example_group_spec.rb +0 -84
  214. data/spec/rspec/core/subject_spec.rb +0 -244
  215. data/spec/rspec/core/world_spec.rb +0 -144
  216. data/spec/rspec/core_spec.rb +0 -35
  217. data/spec/spec_helper.rb +0 -98
  218. data/spec/support/config_options_helper.rb +0 -24
  219. data/spec/support/helper_methods.rb +0 -5
  220. data/spec/support/matchers.rb +0 -65
  221. data/spec/support/shared_example_groups.rb +0 -41
  222. data/spec/support/spec_files.rb +0 -44
@@ -1,1098 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class SelfObserver
4
- def self.cache
5
- @cache ||= []
6
- end
7
-
8
- def initialize
9
- self.class.cache << self
10
- end
11
- end
12
-
13
- module RSpec::Core
14
- describe ExampleGroup do
15
- it_behaves_like "metadata hash builder" do
16
- def metadata_hash(*args)
17
- group = ExampleGroup.describe('example description', *args)
18
- group.metadata
19
- end
20
- end
21
-
22
- context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to false' do
23
- before(:each) do
24
- RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = false }
25
- end
26
-
27
- it 'processes string args as part of the description' do
28
- group = ExampleGroup.describe("some", "separate", "strings")
29
- group.description.should eq("some separate strings")
30
- end
31
-
32
- it 'processes symbol args as part of the description' do
33
- Kernel.stub(:warn) # to silence Symbols as args warning
34
- group = ExampleGroup.describe(:some, :separate, :symbols)
35
- group.description.should eq("some separate symbols")
36
- end
37
- end
38
-
39
- context 'when RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values is set to true' do
40
- let(:group) { ExampleGroup.describe(:symbol) }
41
-
42
- before(:each) do
43
- RSpec.configure { |c| c.treat_symbols_as_metadata_keys_with_true_values = true }
44
- end
45
-
46
- it 'does not treat the first argument as a metadata key even if it is a symbol' do
47
- group.metadata.should_not include(:symbol)
48
- end
49
-
50
- it 'treats the first argument as part of the description when it is a symbol' do
51
- group.description.should eq("symbol")
52
- end
53
- end
54
-
55
- describe "top level group" do
56
- it "runs its children" do
57
- examples_run = []
58
- group = ExampleGroup.describe("parent") do
59
- describe("child") do
60
- it "does something" do
61
- examples_run << example
62
- end
63
- end
64
- end
65
-
66
- group.run
67
- examples_run.should have(1).example
68
- end
69
-
70
- context "with a failure in the top level group" do
71
- it "runs its children " do
72
- examples_run = []
73
- group = ExampleGroup.describe("parent") do
74
- it "fails" do
75
- examples_run << example
76
- raise "fail"
77
- end
78
- describe("child") do
79
- it "does something" do
80
- examples_run << example
81
- end
82
- end
83
- end
84
-
85
- group.run
86
- examples_run.should have(2).examples
87
- end
88
- end
89
-
90
- describe "descendants" do
91
- it "returns self + all descendants" do
92
- group = ExampleGroup.describe("parent") do
93
- describe("child") do
94
- describe("grandchild 1") {}
95
- describe("grandchild 2") {}
96
- end
97
- end
98
- group.descendants.size.should eq(4)
99
- end
100
- end
101
- end
102
-
103
- describe "child" do
104
- it "is known by parent" do
105
- parent = ExampleGroup.describe
106
- child = parent.describe
107
- parent.children.should eq([child])
108
- end
109
-
110
- it "is not registered in world" do
111
- world = RSpec::Core::World.new
112
- parent = ExampleGroup.describe
113
- world.register(parent)
114
- parent.describe
115
- world.example_groups.should eq([parent])
116
- end
117
- end
118
-
119
- describe "filtering" do
120
- let(:world) { World.new }
121
-
122
- shared_examples "matching filters" do
123
- context "inclusion" do
124
- before do
125
- filter_manager = FilterManager.new
126
- filter_manager.include filter_metadata
127
- world.stub(:filter_manager => filter_manager)
128
- end
129
-
130
- it "includes examples in groups matching filter" do
131
- group = ExampleGroup.describe("does something", spec_metadata)
132
- group.stub(:world) { world }
133
- all_examples = [ group.example("first"), group.example("second") ]
134
-
135
- group.filtered_examples.should eq(all_examples)
136
- end
137
-
138
- it "includes examples directly matching filter" do
139
- group = ExampleGroup.describe("does something")
140
- group.stub(:world) { world }
141
- filtered_examples = [
142
- group.example("first", spec_metadata),
143
- group.example("second", spec_metadata)
144
- ]
145
- group.example("third (not-filtered)")
146
-
147
- group.filtered_examples.should eq(filtered_examples)
148
- end
149
- end
150
-
151
- context "exclusion" do
152
- before do
153
- filter_manager = FilterManager.new
154
- filter_manager.exclude filter_metadata
155
- world.stub(:filter_manager => filter_manager)
156
- end
157
-
158
- it "excludes examples in groups matching filter" do
159
- group = ExampleGroup.describe("does something", spec_metadata)
160
- group.stub(:world) { world }
161
- [ group.example("first"), group.example("second") ]
162
-
163
- group.filtered_examples.should be_empty
164
- end
165
-
166
- it "excludes examples directly matching filter" do
167
- group = ExampleGroup.describe("does something")
168
- group.stub(:world) { world }
169
- [
170
- group.example("first", spec_metadata),
171
- group.example("second", spec_metadata)
172
- ]
173
- unfiltered_example = group.example("third (not-filtered)")
174
-
175
- group.filtered_examples.should eq([unfiltered_example])
176
- end
177
- end
178
- end
179
-
180
- context "matching false" do
181
- let(:spec_metadata) { { :awesome => false }}
182
-
183
- context "against false" do
184
- let(:filter_metadata) { { :awesome => false }}
185
- include_examples "matching filters"
186
- end
187
-
188
- context "against 'false'" do
189
- let(:filter_metadata) { { :awesome => 'false' }}
190
- include_examples "matching filters"
191
- end
192
-
193
- context "against :false" do
194
- let(:filter_metadata) { { :awesome => :false }}
195
- include_examples "matching filters"
196
- end
197
- end
198
-
199
- context "matching true" do
200
- let(:spec_metadata) { { :awesome => true }}
201
-
202
- context "against true" do
203
- let(:filter_metadata) { { :awesome => true }}
204
- include_examples "matching filters"
205
- end
206
-
207
- context "against 'true'" do
208
- let(:filter_metadata) { { :awesome => 'true' }}
209
- include_examples "matching filters"
210
- end
211
-
212
- context "against :true" do
213
- let(:filter_metadata) { { :awesome => :true }}
214
- include_examples "matching filters"
215
- end
216
- end
217
-
218
- context "matching a string" do
219
- let(:spec_metadata) { { :type => 'special' }}
220
-
221
- context "against a string" do
222
- let(:filter_metadata) { { :type => 'special' }}
223
- include_examples "matching filters"
224
- end
225
-
226
- context "against a symbol" do
227
- let(:filter_metadata) { { :type => :special }}
228
- include_examples "matching filters"
229
- end
230
- end
231
-
232
- context "matching a symbol" do
233
- let(:spec_metadata) { { :type => :special }}
234
-
235
- context "against a string" do
236
- let(:filter_metadata) { { :type => 'special' }}
237
- include_examples "matching filters"
238
- end
239
-
240
- context "against a symbol" do
241
- let(:filter_metadata) { { :type => :special }}
242
- include_examples "matching filters"
243
- end
244
- end
245
-
246
- context "with no filters" do
247
- it "returns all" do
248
- group = ExampleGroup.describe
249
- group.stub(:world) { world }
250
- example = group.example("does something")
251
- group.filtered_examples.should eq([example])
252
- end
253
- end
254
-
255
- context "with no examples or groups that match filters" do
256
- it "returns none" do
257
- filter_manager = FilterManager.new
258
- filter_manager.include :awesome => false
259
- world.stub(:filter_manager => filter_manager)
260
- group = ExampleGroup.describe
261
- group.stub(:world) { world }
262
- group.example("does something")
263
- group.filtered_examples.should eq([])
264
- end
265
- end
266
- end
267
-
268
- describe '#described_class' do
269
-
270
- context "with a constant as the first parameter" do
271
- it "is that constant" do
272
- ExampleGroup.describe(Object) { }.described_class.should eq(Object)
273
- end
274
- end
275
-
276
- context "with a string as the first parameter" do
277
- it "is nil" do
278
- ExampleGroup.describe("i'm a computer") { }.described_class.should be_nil
279
- end
280
- end
281
-
282
- context "with a constant in an outer group" do
283
- context "and a string in an inner group" do
284
- it "is the top level constant" do
285
- group = ExampleGroup.describe(String) do
286
- describe :symbol do
287
- example "described_class is String" do
288
- described_class.should eq(String)
289
- end
290
- end
291
- end
292
-
293
- group.run.should be_true
294
- end
295
- end
296
-
297
- context "and metadata redefinition after `described_class` call" do
298
- it "is the redefined level constant" do
299
- group = ExampleGroup.describe(String) do
300
- described_class
301
- metadata[:example_group][:described_class] = Object
302
- describe :symbol do
303
- example "described_class is Object" do
304
- described_class.should eq(Object)
305
- end
306
- end
307
- end
308
-
309
- group.run.should be_true
310
- end
311
- end
312
- end
313
-
314
- context "in a nested group" do
315
- it "inherits the described class/module from the outer group" do
316
- group = ExampleGroup.describe(String) do
317
- describe Array do
318
- example "desribes is String" do
319
- described_class.should eq(String)
320
- end
321
- end
322
- end
323
-
324
- group.run.should be_true, "expected examples in group to pass"
325
- end
326
- end
327
- end
328
-
329
- describe '#described_class' do
330
- it "is the same as described_class" do
331
- self.class.described_class.should eq(self.class.described_class)
332
- end
333
- end
334
-
335
- describe '#description' do
336
- it "grabs the description from the metadata" do
337
- group = ExampleGroup.describe(Object, "my desc") { }
338
- group.description.should eq(group.metadata[:example_group][:description])
339
- end
340
- end
341
-
342
- describe '#metadata' do
343
- it "adds the third parameter to the metadata" do
344
- ExampleGroup.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
345
- end
346
-
347
- it "adds the the file_path to metadata" do
348
- ExampleGroup.describe(Object) { }.metadata[:example_group][:file_path].should eq(relative_path(__FILE__))
349
- end
350
-
351
- it "has a reader for file_path" do
352
- ExampleGroup.describe(Object) { }.file_path.should eq(relative_path(__FILE__))
353
- end
354
-
355
- it "adds the line_number to metadata" do
356
- ExampleGroup.describe(Object) { }.metadata[:example_group][:line_number].should eq(__LINE__)
357
- end
358
- end
359
-
360
- [:focus, :focused].each do |example_alias|
361
- describe "##{example_alias}" do
362
- let(:focused_example) { ExampleGroup.describe.send example_alias, "a focused example" }
363
-
364
- it 'defines an example that can be filtered with :focused => true' do
365
- focused_example.metadata[:focused].should be_true
366
- end
367
-
368
- it 'defines an example that can be filtered with :focus => true' do
369
- focused_example.metadata[:focus].should be_true
370
- end
371
- end
372
- end
373
-
374
- describe "#before, after, and around hooks" do
375
- it "runs the before alls in order" do
376
- group = ExampleGroup.describe
377
- order = []
378
- group.before(:all) { order << 1 }
379
- group.before(:all) { order << 2 }
380
- group.before(:all) { order << 3 }
381
- group.example("example") {}
382
-
383
- group.run
384
-
385
- order.should eq([1,2,3])
386
- end
387
-
388
- it "runs the before eachs in order" do
389
- group = ExampleGroup.describe
390
- order = []
391
- group.before(:each) { order << 1 }
392
- group.before(:each) { order << 2 }
393
- group.before(:each) { order << 3 }
394
- group.example("example") {}
395
-
396
- group.run
397
-
398
- order.should eq([1,2,3])
399
- end
400
-
401
- it "runs the after eachs in reverse order" do
402
- group = ExampleGroup.describe
403
- order = []
404
- group.after(:each) { order << 1 }
405
- group.after(:each) { order << 2 }
406
- group.after(:each) { order << 3 }
407
- group.example("example") {}
408
-
409
- group.run
410
-
411
- order.should eq([3,2,1])
412
- end
413
-
414
- it "runs the after alls in reverse order" do
415
- group = ExampleGroup.describe
416
- order = []
417
- group.after(:all) { order << 1 }
418
- group.after(:all) { order << 2 }
419
- group.after(:all) { order << 3 }
420
- group.example("example") {}
421
-
422
- group.run
423
-
424
- order.should eq([3,2,1])
425
- end
426
-
427
- it "only runs before/after(:all) hooks from example groups that have specs that run" do
428
- hooks_run = []
429
-
430
- RSpec.configure do |c|
431
- c.filter_run :focus => true
432
- end
433
-
434
- unfiltered_group = ExampleGroup.describe "unfiltered" do
435
- before(:all) { hooks_run << :unfiltered_before_all }
436
- after(:all) { hooks_run << :unfiltered_after_all }
437
-
438
- context "a subcontext" do
439
- it("has an example") { }
440
- end
441
- end
442
-
443
- filtered_group = ExampleGroup.describe "filtered", :focus => true do
444
- before(:all) { hooks_run << :filtered_before_all }
445
- after(:all) { hooks_run << :filtered_after_all }
446
-
447
- context "a subcontext" do
448
- it("has an example") { }
449
- end
450
- end
451
-
452
- unfiltered_group.run
453
- filtered_group.run
454
-
455
- hooks_run.should eq([:filtered_before_all, :filtered_after_all])
456
- end
457
-
458
- it "runs before_all_defined_in_config, before all, before each, example, after each, after all, after_all_defined_in_config in that order" do
459
- order = []
460
-
461
- RSpec.configure do |c|
462
- c.before(:all) { order << :before_all_defined_in_config }
463
- c.after(:all) { order << :after_all_defined_in_config }
464
- end
465
-
466
- group = ExampleGroup.describe
467
- group.before(:all) { order << :top_level_before_all }
468
- group.before(:each) { order << :before_each }
469
- group.after(:each) { order << :after_each }
470
- group.after(:all) { order << :top_level_after_all }
471
- group.example("top level example") { order << :top_level_example }
472
-
473
- context1 = group.describe("context 1")
474
- context1.before(:all) { order << :nested_before_all }
475
- context1.example("nested example 1") { order << :nested_example_1 }
476
-
477
- context2 = group.describe("context 2")
478
- context2.after(:all) { order << :nested_after_all }
479
- context2.example("nested example 2") { order << :nested_example_2 }
480
-
481
- group.run
482
-
483
- order.should eq([
484
- :before_all_defined_in_config,
485
- :top_level_before_all,
486
- :before_each,
487
- :top_level_example,
488
- :after_each,
489
- :nested_before_all,
490
- :before_each,
491
- :nested_example_1,
492
- :after_each,
493
- :before_each,
494
- :nested_example_2,
495
- :after_each,
496
- :nested_after_all,
497
- :top_level_after_all,
498
- :after_all_defined_in_config
499
- ])
500
- end
501
-
502
- context "after(:all)" do
503
- let(:outer) { ExampleGroup.describe }
504
- let(:inner) { outer.describe }
505
-
506
- it "has access to state defined before(:all)" do
507
- outer.before(:all) { @outer = "outer" }
508
- inner.before(:all) { @inner = "inner" }
509
-
510
- outer.after(:all) do
511
- @outer.should eq("outer")
512
- @inner.should eq("inner")
513
- end
514
- inner.after(:all) do
515
- @inner.should eq("inner")
516
- @outer.should eq("outer")
517
- end
518
-
519
- outer.run
520
- end
521
-
522
- it "cleans up ivars in after(:all)" do
523
- outer.before(:all) { @outer = "outer" }
524
- inner.before(:all) { @inner = "inner" }
525
-
526
- outer.run
527
-
528
- inner.before_all_ivars[:@inner].should be_nil
529
- inner.before_all_ivars[:@outer].should be_nil
530
- outer.before_all_ivars[:@inner].should be_nil
531
- outer.before_all_ivars[:@outer].should be_nil
532
- end
533
- end
534
-
535
- it "treats an error in before(:each) as a failure" do
536
- group = ExampleGroup.describe
537
- group.before(:each) { raise "error in before each" }
538
- example = group.example("equality") { 1.should eq(2) }
539
- group.run.should be(false)
540
-
541
- example.metadata[:execution_result][:exception].message.should eq("error in before each")
542
- end
543
-
544
- it "treats an error in before(:all) as a failure" do
545
- group = ExampleGroup.describe
546
- group.before(:all) { raise "error in before all" }
547
- example = group.example("equality") { 1.should eq(2) }
548
- group.run.should be_false
549
-
550
- example.metadata.should_not be_nil
551
- example.metadata[:execution_result].should_not be_nil
552
- example.metadata[:execution_result][:exception].should_not be_nil
553
- example.metadata[:execution_result][:exception].message.should eq("error in before all")
554
- end
555
-
556
- it "treats an error in before(:all) as a failure for a spec in a nested group" do
557
- example = nil
558
- group = ExampleGroup.describe do
559
- before(:all) { raise "error in before all" }
560
-
561
- describe "nested" do
562
- example = it("equality") { 1.should eq(2) }
563
- end
564
- end
565
- group.run
566
-
567
- example.metadata.should_not be_nil
568
- example.metadata[:execution_result].should_not be_nil
569
- example.metadata[:execution_result][:exception].should_not be_nil
570
- example.metadata[:execution_result][:exception].message.should eq("error in before all")
571
- end
572
-
573
- context "when an error occurs in an after(:all) hook" do
574
- before(:each) do
575
- RSpec.configuration.reporter.stub(:message)
576
- end
577
-
578
- let(:group) do
579
- ExampleGroup.describe do
580
- after(:all) { raise "error in after all" }
581
- it("equality") { 1.should eq(1) }
582
- end
583
- end
584
-
585
- it "allows the example to pass" do
586
- group.run
587
- example = group.examples.first
588
- example.metadata.should_not be_nil
589
- example.metadata[:execution_result].should_not be_nil
590
- example.metadata[:execution_result][:status].should eq("passed")
591
- end
592
-
593
- it "rescues the error and prints it out" do
594
- RSpec.configuration.reporter.should_receive(:message).with(/error in after all/)
595
- group.run
596
- end
597
- end
598
-
599
- it "has no 'running example' within before(:all)" do
600
- group = ExampleGroup.describe
601
- running_example = :none
602
- group.before(:all) { running_example = example }
603
- group.example("no-op") { }
604
- group.run
605
- running_example.should be(nil)
606
- end
607
-
608
- it "has access to example options within before(:each)" do
609
- group = ExampleGroup.describe
610
- option = nil
611
- group.before(:each) { option = example.options[:data] }
612
- group.example("no-op", :data => :sample) { }
613
- group.run
614
- option.should eq(:sample)
615
- end
616
-
617
- it "has access to example options within after(:each)" do
618
- group = ExampleGroup.describe
619
- option = nil
620
- group.after(:each) { option = example.options[:data] }
621
- group.example("no-op", :data => :sample) { }
622
- group.run
623
- option.should eq(:sample)
624
- end
625
-
626
- it "has no 'running example' within after(:all)" do
627
- group = ExampleGroup.describe
628
- running_example = :none
629
- group.after(:all) { running_example = example }
630
- group.example("no-op") { }
631
- group.run
632
- running_example.should be(nil)
633
- end
634
- end
635
-
636
- %w[pending xit xspecify xexample].each do |method_name|
637
- describe "::#{method_name}" do
638
- before do
639
- @group = ExampleGroup.describe
640
- @group.send(method_name, "is pending") { }
641
- end
642
-
643
- it "generates a pending example" do
644
- @group.run
645
- @group.examples.first.should be_pending
646
- end
647
-
648
- it "sets the pending message", :if => method_name == 'pending' do
649
- @group.run
650
- @group.examples.first.metadata[:execution_result][:pending_message].should eq(RSpec::Core::Pending::NO_REASON_GIVEN)
651
- end
652
-
653
- it "sets the pending message", :unless => method_name == 'pending' do
654
- @group.run
655
- @group.examples.first.metadata[:execution_result][:pending_message].should eq("Temporarily disabled with #{method_name}")
656
- end
657
- end
658
- end
659
-
660
- describe "adding examples" do
661
-
662
- it "allows adding an example using 'it'" do
663
- group = ExampleGroup.describe
664
- group.it("should do something") { }
665
- group.examples.size.should eq(1)
666
- end
667
-
668
- it "exposes all examples at examples" do
669
- group = ExampleGroup.describe
670
- group.it("should do something 1") { }
671
- group.it("should do something 2") { }
672
- group.it("should do something 3") { }
673
- group.should have(3).examples
674
- end
675
-
676
- it "maintains the example order" do
677
- group = ExampleGroup.describe
678
- group.it("should 1") { }
679
- group.it("should 2") { }
680
- group.it("should 3") { }
681
- group.examples[0].description.should eq('should 1')
682
- group.examples[1].description.should eq('should 2')
683
- group.examples[2].description.should eq('should 3')
684
- end
685
-
686
- end
687
-
688
- describe Object, "describing nested example_groups", :little_less_nested => 'yep' do
689
-
690
- describe "A sample nested group", :nested_describe => "yep" do
691
- it "sets the described class to the described class of the outer most group" do
692
- example.example_group.described_class.should eq(ExampleGroup)
693
- end
694
-
695
- it "sets the description to 'A sample nested describe'" do
696
- example.example_group.description.should eq('A sample nested group')
697
- end
698
-
699
- it "has top level metadata from the example_group and its ancestors" do
700
- example.example_group.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
701
- end
702
-
703
- it "exposes the parent metadata to the contained examples" do
704
- example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
705
- end
706
- end
707
-
708
- end
709
-
710
- describe "#run_examples" do
711
-
712
- let(:reporter) { double("reporter").as_null_object }
713
-
714
- it "returns true if all examples pass" do
715
- group = ExampleGroup.describe('group') do
716
- example('ex 1') { 1.should eq(1) }
717
- example('ex 2') { 1.should eq(1) }
718
- end
719
- group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered) }
720
- group.run(reporter).should be_true
721
- end
722
-
723
- it "returns false if any of the examples fail" do
724
- group = ExampleGroup.describe('group') do
725
- example('ex 1') { 1.should eq(1) }
726
- example('ex 2') { 1.should eq(2) }
727
- end
728
- group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered) }
729
- group.run(reporter).should be_false
730
- end
731
-
732
- it "runs all examples, regardless of any of them failing" do
733
- group = ExampleGroup.describe('group') do
734
- example('ex 1') { 1.should eq(2) }
735
- example('ex 2') { 1.should eq(1) }
736
- end
737
- group.stub(:filtered_examples) { group.examples.extend(Extensions::Ordered) }
738
- group.filtered_examples.each do |example|
739
- example.should_receive(:run)
740
- end
741
- group.run(reporter).should be_false
742
- end
743
- end
744
-
745
- describe "how instance variables are inherited" do
746
- before(:all) do
747
- @before_all_top_level = 'before_all_top_level'
748
- end
749
-
750
- before(:each) do
751
- @before_each_top_level = 'before_each_top_level'
752
- end
753
-
754
- it "can access a before each ivar at the same level" do
755
- @before_each_top_level.should eq('before_each_top_level')
756
- end
757
-
758
- it "can access a before all ivar at the same level" do
759
- @before_all_top_level.should eq('before_all_top_level')
760
- end
761
-
762
- it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.8 do
763
- example.example_group.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
764
- end
765
-
766
- it "can access the before all ivars in the before_all_ivars hash", :ruby => 1.9 do
767
- example.example_group.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
768
- end
769
-
770
- describe "but now I am nested" do
771
- it "can access a parent example groups before each ivar at a nested level" do
772
- @before_each_top_level.should eq('before_each_top_level')
773
- end
774
-
775
- it "can access a parent example groups before all ivar at a nested level" do
776
- @before_all_top_level.should eq("before_all_top_level")
777
- end
778
-
779
- it "changes to before all ivars from within an example do not persist outside the current describe" do
780
- @before_all_top_level = "ive been changed"
781
- end
782
-
783
- describe "accessing a before_all ivar that was changed in a parent example_group" do
784
- it "does not have access to the modified version" do
785
- @before_all_top_level.should eq('before_all_top_level')
786
- end
787
- end
788
- end
789
-
790
- end
791
-
792
- describe "ivars are not shared across examples" do
793
- it "(first example)" do
794
- @a = 1
795
- defined?(@b).should be_false
796
- end
797
-
798
- it "(second example)" do
799
- @b = 2
800
- defined?(@a).should be_false
801
- end
802
- end
803
-
804
-
805
- describe "#top_level_description" do
806
- it "returns the description from the outermost example group" do
807
- group = nil
808
- ExampleGroup.describe("top") do
809
- context "middle" do
810
- group = describe "bottom" do
811
- end
812
- end
813
- end
814
-
815
- group.top_level_description.should eq("top")
816
- end
817
- end
818
-
819
- describe "#run" do
820
- let(:reporter) { double("reporter").as_null_object }
821
-
822
- context "with fail_fast? => true" do
823
- it "does not run examples after the failed example" do
824
- group = RSpec::Core::ExampleGroup.describe
825
- group.stub(:fail_fast?) { true }
826
- examples_run = []
827
- group.example('example 1') { examples_run << self }
828
- group.example('example 2') { examples_run << self; fail; }
829
- group.example('example 3') { examples_run << self }
830
-
831
- group.run
832
-
833
- examples_run.length.should eq(2)
834
- end
835
- end
836
-
837
- context "with RSpec.wants_to_quit=true" do
838
- let(:group) { RSpec::Core::ExampleGroup.describe }
839
-
840
- before do
841
- RSpec.stub(:wants_to_quit) { true }
842
- RSpec.stub(:clear_remaining_example_groups)
843
- end
844
-
845
- it "returns without starting the group" do
846
- reporter.should_not_receive(:example_group_started)
847
- group.run(reporter)
848
- end
849
-
850
- context "at top level" do
851
- it "purges remaining groups" do
852
- RSpec.should_receive(:clear_remaining_example_groups)
853
- group.run(reporter)
854
- end
855
- end
856
-
857
- context "in a nested group" do
858
- it "does not purge remaining groups" do
859
- nested_group = group.describe
860
- RSpec.should_not_receive(:clear_remaining_example_groups)
861
- nested_group.run(reporter)
862
- end
863
- end
864
- end
865
-
866
- context "with all examples passing" do
867
- it "returns true" do
868
- group = RSpec::Core::ExampleGroup.describe("something") do
869
- it "does something" do
870
- # pass
871
- end
872
- describe "nested" do
873
- it "does something else" do
874
- # pass
875
- end
876
- end
877
- end
878
-
879
- group.run(reporter).should be_true
880
- end
881
- end
882
-
883
- context "with top level example failing" do
884
- it "returns false" do
885
- group = RSpec::Core::ExampleGroup.describe("something") do
886
- it "does something (wrong - fail)" do
887
- raise "fail"
888
- end
889
- describe "nested" do
890
- it "does something else" do
891
- # pass
892
- end
893
- end
894
- end
895
-
896
- group.run(reporter).should be_false
897
- end
898
- end
899
-
900
- context "with nested example failing" do
901
- it "returns true" do
902
- group = RSpec::Core::ExampleGroup.describe("something") do
903
- it "does something" do
904
- # pass
905
- end
906
- describe "nested" do
907
- it "does something else (wrong -fail)" do
908
- raise "fail"
909
- end
910
- end
911
- end
912
-
913
- group.run(reporter).should be_false
914
- end
915
- end
916
- end
917
-
918
- %w[include_examples include_context].each do |name|
919
- describe "##{name}" do
920
- before do
921
- shared_examples "named this" do
922
- example("does something") {}
923
- end
924
- end
925
-
926
- it "includes the named examples" do
927
- group = ExampleGroup.describe
928
- group.send(name, "named this")
929
- group.examples.first.description.should eq("does something")
930
- end
931
-
932
- it "raises a helpful error message when shared content is not found" do
933
- group = ExampleGroup.describe
934
- expect do
935
- group.send(name, "shared stuff")
936
- end.to raise_error(ArgumentError, /Could not find .* "shared stuff"/)
937
- end
938
-
939
- it "passes parameters to the shared content" do
940
- passed_params = {}
941
-
942
- shared_examples "named this with params" do |param1, param2|
943
- it("has access to the given parameters") do
944
- passed_params[:param1] = param1
945
- passed_params[:param2] = param2
946
- end
947
- end
948
-
949
- group = ExampleGroup.describe
950
- group.send(name, "named this with params", :value1, :value2)
951
- group.run
952
-
953
- passed_params.should eq({ :param1 => :value1, :param2 => :value2 })
954
- end
955
-
956
- it "adds shared instance methods to the group" do
957
- shared_examples "named this with params" do |param1|
958
- def foo; end
959
- end
960
- group = ExampleGroup.describe('fake group')
961
- group.send(name, "named this with params", :a)
962
- group.public_instance_methods.map{|m| m.to_s}.should include("foo")
963
- end
964
-
965
- it "evals the shared example group only once" do
966
- eval_count = 0
967
- shared_examples("named this with params") { |p| eval_count += 1 }
968
- group = ExampleGroup.describe('fake group')
969
- group.send(name, "named this with params", :a)
970
- eval_count.should eq(1)
971
- end
972
-
973
- it "evals the block when given" do
974
- key = "#{__FILE__}:#{__LINE__}"
975
- shared_examples(key) do
976
- it("does something") do
977
- foo.should eq("bar")
978
- end
979
- end
980
- group = ExampleGroup.describe do
981
- send name, key do
982
- def foo; "bar"; end
983
- end
984
- end
985
- group.run.should be_true
986
- end
987
- end
988
- end
989
-
990
- describe "#it_should_behave_like" do
991
- it "creates a nested group" do
992
- shared_examples_for("thing") {}
993
- group = ExampleGroup.describe('fake group')
994
- group.it_should_behave_like("thing")
995
- group.should have(1).children
996
- end
997
-
998
- it "creates a nested group for a class" do
999
- klass = Class.new
1000
- shared_examples_for(klass) {}
1001
- group = ExampleGroup.describe('fake group')
1002
- group.it_should_behave_like(klass)
1003
- group.should have(1).children
1004
- end
1005
-
1006
- it "adds shared examples to nested group" do
1007
- shared_examples_for("thing") do
1008
- it("does something")
1009
- end
1010
- group = ExampleGroup.describe('fake group')
1011
- shared_group = group.it_should_behave_like("thing")
1012
- shared_group.should have(1).examples
1013
- end
1014
-
1015
- it "adds shared instance methods to nested group" do
1016
- shared_examples_for("thing") do
1017
- def foo; end
1018
- end
1019
- group = ExampleGroup.describe('fake group')
1020
- shared_group = group.it_should_behave_like("thing")
1021
- shared_group.public_instance_methods.map{|m| m.to_s}.should include("foo")
1022
- end
1023
-
1024
- it "adds shared class methods to nested group" do
1025
- shared_examples_for("thing") do
1026
- def self.foo; end
1027
- end
1028
- group = ExampleGroup.describe('fake group')
1029
- shared_group = group.it_should_behave_like("thing")
1030
- shared_group.methods.map{|m| m.to_s}.should include("foo")
1031
- end
1032
-
1033
- it "passes parameters to the shared example group" do
1034
- passed_params = {}
1035
-
1036
- shared_examples_for("thing") do |param1, param2|
1037
- it("has access to the given parameters") do
1038
- passed_params[:param1] = param1
1039
- passed_params[:param2] = param2
1040
- end
1041
- end
1042
-
1043
- group = ExampleGroup.describe("group") do
1044
- it_should_behave_like "thing", :value1, :value2
1045
- end
1046
- group.run
1047
-
1048
- passed_params.should eq({ :param1 => :value1, :param2 => :value2 })
1049
- end
1050
-
1051
- it "adds shared instance methods to nested group" do
1052
- shared_examples_for("thing") do |param1|
1053
- def foo; end
1054
- end
1055
- group = ExampleGroup.describe('fake group')
1056
- shared_group = group.it_should_behave_like("thing", :a)
1057
- shared_group.public_instance_methods.map{|m| m.to_s}.should include("foo")
1058
- end
1059
-
1060
- it "evals the shared example group only once" do
1061
- eval_count = 0
1062
- shared_examples_for("thing") { |p| eval_count += 1 }
1063
- group = ExampleGroup.describe('fake group')
1064
- group.it_should_behave_like("thing", :a)
1065
- eval_count.should eq(1)
1066
- end
1067
-
1068
- context "given a block" do
1069
- it "evaluates the block in nested group" do
1070
- scopes = []
1071
- shared_examples_for("thing") do
1072
- it("gets run in the nested group") do
1073
- scopes << self.class
1074
- end
1075
- end
1076
- group = ExampleGroup.describe("group") do
1077
- it_should_behave_like "thing" do
1078
- it("gets run in the same nested group") do
1079
- scopes << self.class
1080
- end
1081
- end
1082
- end
1083
- group.run
1084
-
1085
- scopes[0].should be(scopes[1])
1086
- end
1087
- end
1088
-
1089
- it "raises a helpful error message when shared context is not found" do
1090
- expect do
1091
- ExampleGroup.describe do
1092
- it_should_behave_like "shared stuff"
1093
- end
1094
- end.to raise_error(ArgumentError,%q|Could not find shared examples "shared stuff"|)
1095
- end
1096
- end
1097
- end
1098
- end