rspec-core 2.99.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +1 -0
  4. data/Changelog.md +339 -1
  5. data/License.txt +1 -0
  6. data/README.md +19 -37
  7. data/exe/rspec +2 -23
  8. data/lib/rspec/core/backport_random.rb +336 -0
  9. data/lib/rspec/core/backtrace_formatter.rb +70 -0
  10. data/lib/rspec/core/configuration.rb +479 -577
  11. data/lib/rspec/core/configuration_options.rb +71 -54
  12. data/lib/rspec/core/drb.rb +111 -0
  13. data/lib/rspec/core/dsl.rb +86 -18
  14. data/lib/rspec/core/example.rb +267 -119
  15. data/lib/rspec/core/example_group.rb +381 -393
  16. data/lib/rspec/core/filter_manager.rb +133 -114
  17. data/lib/rspec/core/flat_map.rb +18 -0
  18. data/lib/rspec/core/formatters/base_formatter.rb +51 -125
  19. data/lib/rspec/core/formatters/base_text_formatter.rb +34 -286
  20. data/lib/rspec/core/formatters/console_codes.rb +24 -1
  21. data/lib/rspec/core/formatters/deprecation_formatter.rb +25 -26
  22. data/lib/rspec/core/formatters/documentation_formatter.rb +27 -25
  23. data/lib/rspec/core/formatters/helpers.rb +14 -36
  24. data/lib/rspec/core/formatters/html_formatter.rb +58 -65
  25. data/lib/rspec/core/formatters/html_printer.rb +12 -18
  26. data/lib/rspec/core/formatters/json_formatter.rb +54 -31
  27. data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
  28. data/lib/rspec/core/formatters/progress_formatter.rb +11 -15
  29. data/lib/rspec/core/formatters/snippet_extractor.rb +22 -11
  30. data/lib/rspec/core/formatters.rb +90 -43
  31. data/lib/rspec/core/hooks.rb +325 -270
  32. data/lib/rspec/core/memoized_helpers.rb +45 -156
  33. data/lib/rspec/core/metadata.rb +284 -236
  34. data/lib/rspec/core/metadata_filter.rb +86 -0
  35. data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
  36. data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
  37. data/lib/rspec/core/mocking_adapters/null.rb +12 -0
  38. data/lib/rspec/core/mocking_adapters/rr.rb +29 -0
  39. data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
  40. data/lib/rspec/core/notifications.rb +511 -0
  41. data/lib/rspec/core/option_parser.rb +49 -74
  42. data/lib/rspec/core/ordering.rb +156 -0
  43. data/lib/rspec/core/pending.rb +94 -96
  44. data/lib/rspec/core/project_initializer/.rspec +3 -0
  45. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +78 -0
  46. data/lib/rspec/core/project_initializer.rb +24 -64
  47. data/lib/rspec/core/rake_task.rb +44 -130
  48. data/lib/rspec/core/reporter.rb +76 -59
  49. data/lib/rspec/core/ruby_project.rb +2 -1
  50. data/lib/rspec/core/runner.rb +117 -52
  51. data/lib/rspec/core/shared_context.rb +10 -10
  52. data/lib/rspec/core/shared_example_group.rb +108 -121
  53. data/lib/rspec/core/version.rb +3 -1
  54. data/lib/rspec/core/warnings.rb +40 -0
  55. data/lib/rspec/core/world.rb +66 -10
  56. data/lib/rspec/core.rb +64 -104
  57. data.tar.gz.sig +3 -0
  58. metadata +75 -322
  59. metadata.gz.sig +1 -0
  60. data/exe/autospec +0 -13
  61. data/features/Autotest.md +0 -38
  62. data/features/README.md +0 -17
  63. data/features/Upgrade.md +0 -364
  64. data/features/command_line/README.md +0 -28
  65. data/features/command_line/example_name_option.feature +0 -97
  66. data/features/command_line/exit_status.feature +0 -82
  67. data/features/command_line/format_option.feature +0 -75
  68. data/features/command_line/init.feature +0 -18
  69. data/features/command_line/line_number_appended_to_path.feature +0 -140
  70. data/features/command_line/line_number_option.feature +0 -53
  71. data/features/command_line/order.feature +0 -26
  72. data/features/command_line/pattern_option.feature +0 -49
  73. data/features/command_line/rake_task.feature +0 -122
  74. data/features/command_line/require_option.feature +0 -43
  75. data/features/command_line/ruby.feature +0 -22
  76. data/features/command_line/tag.feature +0 -98
  77. data/features/command_line/warnings_option.feature +0 -29
  78. data/features/configuration/alias_example_to.feature +0 -48
  79. data/features/configuration/backtrace_clean_patterns.feature +0 -102
  80. data/features/configuration/custom_settings.feature +0 -84
  81. data/features/configuration/default_path.feature +0 -38
  82. data/features/configuration/deprecation_stream.feature +0 -58
  83. data/features/configuration/fail_fast.feature +0 -77
  84. data/features/configuration/failure_exit_code.feature +0 -36
  85. data/features/configuration/order_and_seed.feature +0 -3
  86. data/features/configuration/output_stream.feature +0 -24
  87. data/features/configuration/pattern.feature +0 -38
  88. data/features/configuration/profile.feature +0 -220
  89. data/features/configuration/read_options_from_file.feature +0 -90
  90. data/features/configuration/run_all_when_everything_filtered.feature +0 -76
  91. data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
  92. data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
  93. data/features/example_groups/basic_structure.feature +0 -55
  94. data/features/example_groups/shared_context.feature +0 -74
  95. data/features/example_groups/shared_examples.feature +0 -294
  96. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -197
  97. data/features/filtering/exclusion_filters.feature +0 -138
  98. data/features/filtering/if_and_unless.feature +0 -168
  99. data/features/filtering/inclusion_filters.feature +0 -105
  100. data/features/formatters/configurable_colors.feature +0 -31
  101. data/features/formatters/custom_formatter.feature +0 -36
  102. data/features/formatters/json_formatter.feature +0 -30
  103. data/features/formatters/text_formatter.feature +0 -46
  104. data/features/helper_methods/arbitrary_methods.feature +0 -40
  105. data/features/helper_methods/let.feature +0 -50
  106. data/features/helper_methods/modules.feature +0 -149
  107. data/features/hooks/around_hooks.feature +0 -343
  108. data/features/hooks/before_and_after_hooks.feature +0 -427
  109. data/features/hooks/filtering.feature +0 -234
  110. data/features/metadata/current_example.feature +0 -56
  111. data/features/metadata/described_class.feature +0 -17
  112. data/features/metadata/user_defined.feature +0 -113
  113. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  114. data/features/mock_framework_integration/use_flexmock.feature +0 -96
  115. data/features/mock_framework_integration/use_mocha.feature +0 -97
  116. data/features/mock_framework_integration/use_rr.feature +0 -98
  117. data/features/mock_framework_integration/use_rspec.feature +0 -97
  118. data/features/pending/pending_examples.feature +0 -229
  119. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  120. data/features/step_definitions/additional_cli_steps.rb +0 -49
  121. data/features/subject/attribute_of_subject.feature +0 -124
  122. data/features/subject/explicit_subject.feature +0 -101
  123. data/features/subject/implicit_subject.feature +0 -63
  124. data/features/subject/one_liner_syntax.feature +0 -71
  125. data/features/support/env.rb +0 -14
  126. data/features/support/rubinius.rb +0 -6
  127. data/lib/autotest/discover.rb +0 -10
  128. data/lib/autotest/rspec2.rb +0 -77
  129. data/lib/rspec/core/backtrace_cleaner.rb +0 -46
  130. data/lib/rspec/core/backward_compatibility.rb +0 -55
  131. data/lib/rspec/core/caller_filter.rb +0 -60
  132. data/lib/rspec/core/command_line.rb +0 -47
  133. data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
  134. data/lib/rspec/core/deprecation.rb +0 -26
  135. data/lib/rspec/core/drb_command_line.rb +0 -26
  136. data/lib/rspec/core/drb_options.rb +0 -87
  137. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  138. data/lib/rspec/core/extensions/kernel.rb +0 -9
  139. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  140. data/lib/rspec/core/extensions/ordered.rb +0 -27
  141. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  142. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  143. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  144. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  145. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  146. data/lib/rspec/core/mocking/with_rspec.rb +0 -27
  147. data/lib/rspec/core/shared_example_group/collection.rb +0 -45
  148. data/spec/autotest/discover_spec.rb +0 -49
  149. data/spec/autotest/failed_results_re_spec.rb +0 -45
  150. data/spec/autotest/rspec_spec.rb +0 -133
  151. data/spec/command_line/order_spec.rb +0 -204
  152. data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
  153. data/spec/rspec/core/caller_filter_spec.rb +0 -58
  154. data/spec/rspec/core/command_line_spec.rb +0 -127
  155. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  156. data/spec/rspec/core/configuration_options_spec.rb +0 -417
  157. data/spec/rspec/core/configuration_spec.rb +0 -2072
  158. data/spec/rspec/core/deprecation_spec.rb +0 -27
  159. data/spec/rspec/core/deprecations_spec.rb +0 -59
  160. data/spec/rspec/core/drb_command_line_spec.rb +0 -102
  161. data/spec/rspec/core/drb_options_spec.rb +0 -193
  162. data/spec/rspec/core/dsl_spec.rb +0 -25
  163. data/spec/rspec/core/example_group_spec.rb +0 -1337
  164. data/spec/rspec/core/example_spec.rb +0 -502
  165. data/spec/rspec/core/filter_manager_spec.rb +0 -246
  166. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -108
  167. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -524
  168. data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
  169. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -263
  170. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -89
  171. data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
  172. data/spec/rspec/core/formatters/html_formatted.html +0 -397
  173. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -131
  174. data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -115
  175. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
  176. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
  177. data/spec/rspec/core/formatters/text_mate_formatted.html +0 -397
  178. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
  179. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  180. data/spec/rspec/core/hooks_spec.rb +0 -269
  181. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  182. data/spec/rspec/core/memoized_helpers_spec.rb +0 -776
  183. data/spec/rspec/core/metadata_spec.rb +0 -514
  184. data/spec/rspec/core/option_parser_spec.rb +0 -297
  185. data/spec/rspec/core/pending_example_spec.rb +0 -260
  186. data/spec/rspec/core/pending_spec.rb +0 -27
  187. data/spec/rspec/core/project_initializer_spec.rb +0 -130
  188. data/spec/rspec/core/rake_task_spec.rb +0 -202
  189. data/spec/rspec/core/reporter_spec.rb +0 -167
  190. data/spec/rspec/core/resources/a_bar.rb +0 -0
  191. data/spec/rspec/core/resources/a_foo.rb +0 -0
  192. data/spec/rspec/core/resources/a_spec.rb +0 -1
  193. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  194. data/spec/rspec/core/resources/formatter_specs.rb +0 -60
  195. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  196. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  197. data/spec/rspec/core/ruby_project_spec.rb +0 -26
  198. data/spec/rspec/core/runner_spec.rb +0 -82
  199. data/spec/rspec/core/shared_context_spec.rb +0 -114
  200. data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -70
  201. data/spec/rspec/core/shared_example_group_spec.rb +0 -138
  202. data/spec/rspec/core/world_spec.rb +0 -142
  203. data/spec/rspec/core_spec.rb +0 -108
  204. data/spec/spec_helper.rb +0 -135
  205. data/spec/support/config_options_helper.rb +0 -15
  206. data/spec/support/helper_methods.rb +0 -55
  207. data/spec/support/in_sub_process.rb +0 -37
  208. data/spec/support/isolate_load_path_mutation.rb +0 -6
  209. data/spec/support/isolated_directory.rb +0 -10
  210. data/spec/support/isolated_home_directory.rb +0 -16
  211. data/spec/support/matchers.rb +0 -65
  212. data/spec/support/mathn_integration_support.rb +0 -12
  213. data/spec/support/sandboxed_mock_space.rb +0 -116
  214. data/spec/support/shared_example_groups.rb +0 -42
  215. data/spec/support/silence_dsl_deprecations.rb +0 -32
  216. data/spec/support/spec_files.rb +0 -44
@@ -1,502 +0,0 @@
1
- require 'spec_helper'
2
- require 'pp'
3
- require 'stringio'
4
-
5
- describe RSpec::Core::Example, :parent_metadata => 'sample' do
6
- let(:example_group) do
7
- RSpec::Core::ExampleGroup.describe('group description')
8
- end
9
-
10
- let(:example_instance) do
11
- example_group.example('example description') { }
12
- end
13
-
14
- it_behaves_like "metadata hash builder" do
15
- def metadata_hash(*args)
16
- example = example_group.example('example description', *args)
17
- example.metadata
18
- end
19
- end
20
-
21
- def capture_stdout
22
- orig_stdout = $stdout
23
- $stdout = StringIO.new
24
- yield
25
- $stdout.string
26
- ensure
27
- $stdout = orig_stdout
28
- end
29
-
30
- it "can be pretty printed" do
31
- output = ignoring_warnings { capture_stdout { pp example_instance } }
32
- expect(output).to include("RSpec::Core::Example")
33
- end
34
-
35
- describe "#exception" do
36
- it "supplies the first exception raised, if any" do
37
- RSpec.configuration.output_stream = StringIO.new
38
-
39
- example = example_group.example { raise "first" }
40
- example_group.after { raise "second" }
41
- example_group.run
42
- expect(example.exception.message).to eq("first")
43
- end
44
-
45
- it "returns nil if there is no exception" do
46
- example = example_group.example('example') { }
47
- example_group.run
48
- expect(example.exception).to be_nil
49
- end
50
- end
51
-
52
- describe "when there is an explicit description" do
53
- context "when RSpec.configuration.format_docstrings is set to a block" do
54
- it "formats the description using the block" do
55
- RSpec.configuration.format_docstrings { |s| s.strip }
56
- example = example_group.example(' an example with whitespace ') {}
57
- example_group.run
58
- expect(example.description).to eql('an example with whitespace')
59
- end
60
- end
61
- end
62
-
63
- describe "when there is no explicit description" do
64
- def expect_with(*frameworks)
65
- RSpec.configuration.stub(:expecting_with_rspec?).and_return(frameworks.include?(:rspec))
66
-
67
- if frameworks.include?(:stdlib)
68
- example_group.class_eval do
69
- def assert(val)
70
- raise "Expected #{val} to be true" unless val
71
- end
72
- end
73
- end
74
- end
75
-
76
- context "when RSpec.configuration.format_docstrings is set to a block" do
77
- it "formats the description using the block" do
78
- RSpec.configuration.format_docstrings { |s| s.upcase }
79
- example_group.example { expect(5).to eq(5) }
80
- example_group.run
81
- pattern = /EXAMPLE AT #{relative_path(__FILE__).upcase}:#{__LINE__ - 2}/
82
- expect(example_group.examples.first.description).to match(pattern)
83
- end
84
- end
85
-
86
- context "when `expect_with :rspec` is configured" do
87
- before(:each) { expect_with :rspec }
88
-
89
- it "uses the matcher-generated description" do
90
- example_group.example { expect(5).to eq(5) }
91
- example_group.run
92
- expect(example_group.examples.first.description).to eq("should eq 5")
93
- end
94
-
95
- it "uses the matcher-generated description in the full description" do
96
- example_group.example { expect(5).to eq(5) }
97
- example_group.run
98
- expect(example_group.examples.first.full_description).to eq("group description should eq 5")
99
- end
100
-
101
- it "uses the file and line number if there is no matcher-generated description" do
102
- example = example_group.example {}
103
- example_group.run
104
- expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
105
- end
106
-
107
- it "uses the file and line number if there is an error before the matcher" do
108
- example = example_group.example { expect(5).to eq(5) }
109
- example_group.before { raise }
110
- example_group.run
111
- expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 3}/)
112
- end
113
- end
114
-
115
- context "when `expect_with :rspec, :stdlib` is configured" do
116
- before(:each) { expect_with :rspec, :stdlib }
117
-
118
- it "uses the matcher-generated description" do
119
- example_group.example { expect(5).to eq(5) }
120
- example_group.run
121
- expect(example_group.examples.first.description).to eq("should eq 5")
122
- end
123
-
124
- it "uses the file and line number if there is no matcher-generated description" do
125
- example = example_group.example {}
126
- example_group.run
127
- expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
128
- end
129
-
130
- it "uses the file and line number if there is an error before the matcher" do
131
- example = example_group.example { expect(5).to eq(5) }
132
- example_group.before { raise }
133
- example_group.run
134
- expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 3}/)
135
- end
136
- end
137
-
138
- context "when `expect_with :stdlib` is configured" do
139
- before(:each) { expect_with :stdlib }
140
-
141
- it "does not attempt to get the generated description from RSpec::Matchers" do
142
- RSpec::Matchers.should_not_receive(:generated_description)
143
- example_group.example { assert 5 == 5 }
144
- example_group.run
145
- end
146
-
147
- it "uses the file and line number" do
148
- example = example_group.example { assert 5 == 5 }
149
- example_group.run
150
- expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
151
- end
152
- end
153
- end
154
-
155
- describe "#described_class" do
156
- it "returns the class (if any) of the outermost example group" do
157
- expect(described_class).to eq(RSpec::Core::Example)
158
- end
159
- end
160
-
161
- describe "accessing metadata within a running example" do
162
- it "has a reference to itself when running" do |ex|
163
- expect(ex.description).to eq("has a reference to itself when running")
164
- end
165
-
166
- it "can access the example group's top level metadata as if it were its own" do |ex|
167
- expect(ex.example_group.metadata).to include(:parent_metadata => 'sample')
168
- expect(ex.metadata).to include(:parent_metadata => 'sample')
169
- end
170
- end
171
-
172
- describe "accessing options within a running example" do
173
- it "can look up option values by key", :demo => :data do |ex|
174
- expect(ex.metadata[:demo]).to eq(:data)
175
- end
176
- end
177
-
178
- describe "#run" do
179
- it "sets its reference to the example group instance to nil" do
180
- group = RSpec::Core::ExampleGroup.describe do
181
- example('example') { expect(1).to eq(1) }
182
- end
183
- group.run
184
- expect(group.examples.first.instance_variable_get("@example_group_instance")).to be_nil
185
- end
186
-
187
- it "runs after(:each) when the example passes" do
188
- after_run = false
189
- group = RSpec::Core::ExampleGroup.describe do
190
- after(:each) { after_run = true }
191
- example('example') { expect(1).to eq(1) }
192
- end
193
- group.run
194
- expect(after_run).to be_truthy, "expected after(:each) to be run"
195
- end
196
-
197
- it "runs after(:each) when the example fails" do
198
- after_run = false
199
- group = RSpec::Core::ExampleGroup.describe do
200
- after(:each) { after_run = true }
201
- example('example') { expect(1).to eq(2) }
202
- end
203
- group.run
204
- expect(after_run).to be_truthy, "expected after(:each) to be run"
205
- end
206
-
207
- it "runs after(:each) when the example raises an Exception" do
208
- after_run = false
209
- group = RSpec::Core::ExampleGroup.describe do
210
- after(:each) { after_run = true }
211
- example('example') { raise "this error" }
212
- end
213
- group.run
214
- expect(after_run).to be_truthy, "expected after(:each) to be run"
215
- end
216
-
217
- context "with an after(:each) that raises" do
218
- it "runs subsequent after(:each)'s" do
219
- after_run = false
220
- group = RSpec::Core::ExampleGroup.describe do
221
- after(:each) { after_run = true }
222
- after(:each) { raise "FOO" }
223
- example('example') { expect(1).to eq(1) }
224
- end
225
- group.run
226
- expect(after_run).to be_truthy, "expected after(:each) to be run"
227
- end
228
-
229
- it "stores the exception" do
230
- group = RSpec::Core::ExampleGroup.describe
231
- group.after(:each) { raise "FOO" }
232
- example = group.example('example') { expect(1).to eq(1) }
233
-
234
- group.run
235
-
236
- expect(example.metadata[:execution_result][:exception].message).to eq("FOO")
237
- end
238
- end
239
-
240
- it "wraps before/after(:each) inside around" do
241
- results = []
242
- group = RSpec::Core::ExampleGroup.describe do
243
- around(:each) do |e|
244
- results << "around (before)"
245
- e.run
246
- results << "around (after)"
247
- end
248
- before(:each) { results << "before" }
249
- after(:each) { results << "after" }
250
- example { results << "example" }
251
- end
252
-
253
- group.run
254
- expect(results).to eq([
255
- "around (before)",
256
- "before",
257
- "example",
258
- "after",
259
- "around (after)"
260
- ])
261
- end
262
-
263
- context "clearing ivars" do
264
- it "sets ivars to nil to prep them for GC" do
265
- group = RSpec::Core::ExampleGroup.describe do
266
- before(:all) { @before_all = :before_all }
267
- before(:each) { @before_each = :before_each }
268
- after(:each) { @after_each = :after_each }
269
- after(:all) { @after_all = :after_all }
270
- end
271
- group.example("does something") do
272
- expect(@before_all).to eq(:before_all)
273
- expect(@before_each).to eq(:before_each)
274
- end
275
- expect(group.run(double.as_null_object)).to be_truthy
276
- group.new do |example|
277
- %w[@before_all @before_each @after_each @after_all].each do |ivar|
278
- expect(example.instance_variable_get(ivar)).to be_nil
279
- end
280
- end
281
- end
282
-
283
- it "does not impact the before_all_ivars which are copied to each example" do
284
- group = RSpec::Core::ExampleGroup.describe do
285
- before(:all) { @before_all = "abc" }
286
- example("first") { expect(@before_all).not_to be_nil }
287
- example("second") { expect(@before_all).not_to be_nil }
288
- end
289
- expect(group.run).to be_truthy
290
- end
291
- end
292
-
293
- context 'when the example raises an error' do
294
- def run_and_capture_reported_message(group)
295
- reported_msg = nil
296
- # We can't use should_receive(:message).with(/.../) here,
297
- # because if that fails, it would fail within our example-under-test,
298
- # and since there's already two errors, it would just be reported again.
299
- RSpec.configuration.reporter.stub(:message) { |msg| reported_msg = msg }
300
- group.run
301
- reported_msg
302
- end
303
-
304
- it "prints any around hook errors rather than silencing them" do
305
- group = RSpec::Core::ExampleGroup.describe do
306
- around(:each) { |e| e.run; raise "around" }
307
- example("e") { raise "example" }
308
- end
309
-
310
- message = run_and_capture_reported_message(group)
311
- expect(message).to match(/An error occurred in an around.* hook/i)
312
- end
313
-
314
- it "prints any after hook errors rather than silencing them" do
315
- group = RSpec::Core::ExampleGroup.describe do
316
- after(:each) { raise "after" }
317
- example("e") { raise "example" }
318
- end
319
-
320
- message = run_and_capture_reported_message(group)
321
- expect(message).to match(/An error occurred in an after.* hook/i)
322
- end
323
-
324
- it "does not print mock expectation errors" do
325
- group = RSpec::Core::ExampleGroup.describe do
326
- example do
327
- foo = double
328
- foo.should_receive(:bar)
329
- raise "boom"
330
- end
331
- end
332
-
333
- message = run_and_capture_reported_message(group)
334
- expect(message).to be_nil
335
- end
336
-
337
- it "leaves a raised exception unmodified (GH-1103)" do
338
- # set the backtrace, otherwise MRI will build a whole new object,
339
- # and thus mess with our expectations. Rubinius and JRuby are not
340
- # affected.
341
- exception = StandardError.new
342
- exception.set_backtrace([])
343
-
344
- group = RSpec::Core::ExampleGroup.describe do
345
- example { raise exception.freeze }
346
- end
347
- group.run
348
-
349
- actual = group.examples.first.metadata[:execution_result][:exception]
350
- expect(actual.__id__).to eq(exception.__id__)
351
- end
352
- end
353
- end
354
-
355
- describe "#pending" do
356
- context "in the example" do
357
- it "sets the example to pending" do
358
- group = RSpec::Core::ExampleGroup.describe do
359
- example { pending }
360
- end
361
- group.run
362
- expect(group.examples.first).to be_pending
363
- end
364
-
365
- it "allows post-example processing in around hooks (see https://github.com/rspec/rspec-core/issues/322)" do
366
- blah = nil
367
- group = RSpec::Core::ExampleGroup.describe do
368
- around do |example|
369
- example.run
370
- blah = :success
371
- end
372
- example { pending }
373
- end
374
- group.run
375
- expect(blah).to be(:success)
376
- end
377
-
378
- context "with a block" do
379
- it "sets the example to pending if block fails" do
380
- group = RSpec::Core::ExampleGroup.describe do
381
- example do
382
- pending { expect(1).to eq(2) }
383
- end
384
- end
385
- group.run
386
- expect(group.examples.first.metadata[:execution_result][:status]).to eq('pending')
387
- expect(group.examples.first.metadata[:execution_result][:pending_fixed]).to eq(false)
388
- end
389
-
390
- it "fails if block is fixed, i.e. does not raise" do
391
- group = RSpec::Core::ExampleGroup.describe do
392
- example do
393
- pending {}
394
- end
395
- end
396
- group.run
397
- expect(group.examples.first.metadata[:execution_result][:status]).to eq('failed')
398
- expect(group.examples.first.metadata[:execution_result][:pending_fixed]).to eq(true)
399
- end
400
- end
401
- end
402
-
403
- context "in before(:each)" do
404
- it "sets each example to pending" do
405
- group = RSpec::Core::ExampleGroup.describe do
406
- before(:each) { pending }
407
- example {}
408
- example {}
409
- end
410
- group.run
411
- expect(group.examples.first).to be_pending
412
- expect(group.examples.last).to be_pending
413
- end
414
- end
415
-
416
- context "in before(:all)" do
417
- it "sets each example to pending" do
418
- group = RSpec::Core::ExampleGroup.describe do
419
- before(:all) { pending }
420
- example {}
421
- example {}
422
- end
423
- group.run
424
- expect(group.examples.first).to be_pending
425
- expect(group.examples.last).to be_pending
426
- end
427
- end
428
-
429
- context "in around(:each)" do
430
- it "sets the example to pending" do
431
- group = RSpec::Core::ExampleGroup.describe do
432
- around(:each) { pending }
433
- example {}
434
- end
435
- group.run
436
- expect(group.examples.first).to be_pending
437
- end
438
- end
439
- end
440
-
441
- describe "timing" do
442
- it "uses RSpec::Core::Time as to not be affected by changes to time in examples" do
443
- reporter = double(:reporter).as_null_object
444
- group = RSpec::Core::ExampleGroup.describe
445
- example = group.example
446
- example.__send__ :start, reporter
447
- Time.stub(:now => Time.utc(2012, 10, 1))
448
- example.__send__ :finish, reporter
449
- expect(example.metadata[:execution_result][:run_time]).to be < 0.2
450
- end
451
- end
452
-
453
- it "does not interfere with per-example randomness when running examples in a random order" do
454
- values = []
455
-
456
- RSpec.configuration.order = :random
457
-
458
- RSpec::Core::ExampleGroup.describe do
459
- # The bug was only triggered when the examples
460
- # were in nested contexts; see https://github.com/rspec/rspec-core/pull/837
461
- context { example { values << rand } }
462
- context { example { values << rand } }
463
- end.run
464
-
465
- expect(values.uniq).to have(2).values
466
- end
467
-
468
- describe "optional block argument" do
469
- it "contains the example" do |ex|
470
- expect(ex).to be_an(RSpec::Core::Example)
471
- expect(ex.description).to match(/contains the example/)
472
- end
473
- end
474
-
475
- %w[example running_example].each do |accessor|
476
- describe accessor do
477
- before { allow_deprecation }
478
-
479
- it "is deprecated" do
480
- expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{accessor}/)
481
- send(accessor)
482
- end
483
-
484
- it "returns the current running example" do |ex|
485
- expect(send(accessor)).to eq ex
486
- end
487
- end
488
- end
489
-
490
- describe "setting the current example" do
491
- it "sets RSpec.current_example to the example that is currently running" do
492
- group = RSpec::Core::ExampleGroup.describe("an example group")
493
-
494
- current_examples = []
495
- example1 = group.example("example 1") { current_examples << RSpec.current_example }
496
- example2 = group.example("example 2") { current_examples << RSpec.current_example }
497
-
498
- group.run
499
- expect(current_examples).to eq([example1, example2])
500
- end
501
- end
502
- end