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,524 +0,0 @@
1
- require 'spec_helper'
2
- require 'rspec/core/formatters/base_text_formatter'
3
-
4
- describe RSpec::Core::Formatters::BaseTextFormatter do
5
- let(:output) { StringIO.new }
6
- let(:formatter) { RSpec::Core::Formatters::BaseTextFormatter.new(output) }
7
-
8
- context "when closing the formatter", :isolated_directory => true do
9
- it 'does not close an already closed output stream' do
10
- output = File.new("./output_to_close", "w")
11
- formatter = described_class.new(output)
12
- output.close
13
-
14
- expect { formatter.close }.not_to raise_error
15
- end
16
- end
17
-
18
- describe "#summary_line" do
19
- it "with 0s outputs pluralized (excluding pending)" do
20
- expect(formatter.summary_line(0,0,0)).to eq("0 examples, 0 failures")
21
- end
22
-
23
- it "with 1s outputs singular (including pending)" do
24
- expect(formatter.summary_line(1,1,1)).to eq("1 example, 1 failure, 1 pending")
25
- end
26
-
27
- it "with 2s outputs pluralized (including pending)" do
28
- expect(formatter.summary_line(2,2,2)).to eq("2 examples, 2 failures, 2 pending")
29
- end
30
- end
31
-
32
- describe "#dump_commands_to_rerun_failed_examples" do
33
- it "includes command to re-run each failed example" do
34
- group = RSpec::Core::ExampleGroup.describe("example group") do
35
- it("fails") { fail }
36
- end
37
- line = __LINE__ - 2
38
- group.run(formatter)
39
- formatter.dump_commands_to_rerun_failed_examples
40
- expect(output.string).to include("rspec #{RSpec::Core::Metadata::relative_path("#{__FILE__}:#{line}")} # example group fails")
41
- end
42
- end
43
-
44
- describe "#dump_failures" do
45
- let(:group) { RSpec::Core::ExampleGroup.describe("group name") }
46
-
47
- before { RSpec.configuration.stub(:color_enabled?) { false } }
48
-
49
- def run_all_and_dump_failures
50
- group.run(formatter)
51
- formatter.dump_failures
52
- end
53
-
54
- it "preserves formatting" do
55
- group.example("example name") { expect("this").to eq("that") }
56
-
57
- run_all_and_dump_failures
58
-
59
- expect(output.string).to match(/group name example name/m)
60
- expect(output.string).to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
61
- end
62
-
63
- context "with an exception without a message" do
64
- it "does not throw NoMethodError" do
65
- exception_without_message = Exception.new()
66
- exception_without_message.stub(:message) { nil }
67
- group.example("example name") { raise exception_without_message }
68
- expect { run_all_and_dump_failures }.not_to raise_error
69
- end
70
-
71
- it "preserves ancestry" do
72
- example = group.example("example name") { raise "something" }
73
- run_all_and_dump_failures
74
- expect(example.example_group.parent_groups.size).to eq 1
75
- end
76
- end
77
-
78
- context "with an exception that has an exception instance as its message" do
79
- it "does not raise NoMethodError" do
80
- gonzo_exception = RuntimeError.new
81
- gonzo_exception.stub(:message) { gonzo_exception }
82
- group.example("example name") { raise gonzo_exception }
83
- expect { run_all_and_dump_failures }.not_to raise_error
84
- end
85
- end
86
-
87
- context "with an instance of an anonymous exception class" do
88
- it "substitutes '(anonymous error class)' for the missing class name" do
89
- exception = Class.new(StandardError).new
90
- group.example("example name") { raise exception }
91
- run_all_and_dump_failures
92
- expect(output.string).to include('(anonymous error class)')
93
- end
94
- end
95
-
96
- context "with an exception class other than RSpec" do
97
- it "does not show the error class" do
98
- group.example("example name") { raise NameError.new('foo') }
99
- run_all_and_dump_failures
100
- expect(output.string).to match(/NameError/m)
101
- end
102
- end
103
-
104
- context "with a failed expectation (rspec-expectations)" do
105
- it "does not show the error class" do
106
- group.example("example name") { expect("this").to eq("that") }
107
- run_all_and_dump_failures
108
- expect(output.string).not_to match(/RSpec/m)
109
- end
110
- end
111
-
112
- context "with a failed message expectation (rspec-mocks)" do
113
- it "does not show the error class" do
114
- group.example("example name") { "this".should_receive("that") }
115
- run_all_and_dump_failures
116
- expect(output.string).not_to match(/RSpec/m)
117
- end
118
- end
119
-
120
- context 'for #share_examples_for' do
121
- it 'outputs the name and location' do
122
-
123
- group.share_examples_for 'foo bar' do
124
- it("example name") { expect("this").to eq("that") }
125
- end
126
-
127
- line = __LINE__.next
128
- group.it_should_behave_like('foo bar')
129
-
130
- run_all_and_dump_failures
131
-
132
- expect(output.string).to include(
133
- 'Shared Example Group: "foo bar" called from ' +
134
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
135
- )
136
- end
137
-
138
- context 'that contains nested example groups' do
139
- it 'outputs the name and location' do
140
- group.share_examples_for 'foo bar' do
141
- describe 'nested group' do
142
- it("example name") { expect("this").to eq("that") }
143
- end
144
- end
145
-
146
- line = __LINE__.next
147
- group.it_should_behave_like('foo bar')
148
-
149
- run_all_and_dump_failures
150
-
151
- expect(output.string).to include(
152
- 'Shared Example Group: "foo bar" called from ' +
153
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
154
- )
155
- end
156
- end
157
- end
158
-
159
- context 'for #share_as' do
160
- before { allow(RSpec).to receive(:deprecate) }
161
-
162
- it 'outputs the name and location' do
163
-
164
- group.share_as :FooBar do
165
- it("example name") { expect("this").to eq("that") }
166
- end
167
-
168
- line = __LINE__.next
169
- group.send(:include, FooBar)
170
-
171
- run_all_and_dump_failures
172
-
173
- expect(output.string).to include(
174
- 'Shared Example Group: "FooBar" called from ' +
175
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
176
- )
177
- end
178
-
179
- context 'that contains nested example groups' do
180
- it 'outputs the name and location' do
181
-
182
- group.share_as :NestedFoo do
183
- describe 'nested group' do
184
- describe 'hell' do
185
- it("example name") { expect("this").to eq("that") }
186
- end
187
- end
188
- end
189
-
190
- line = __LINE__.next
191
- group.send(:include, NestedFoo)
192
-
193
- run_all_and_dump_failures
194
-
195
- expect(output.string).to include(
196
- 'Shared Example Group: "NestedFoo" called from ' +
197
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
198
- )
199
- end
200
- end
201
- end
202
- end
203
-
204
- describe "#dump_pending" do
205
- let(:group) { RSpec::Core::ExampleGroup.describe("group name") }
206
-
207
- before { RSpec.configuration.stub(:color_enabled?) { false } }
208
-
209
- def run_all_and_dump_pending
210
- group.run(formatter)
211
- formatter.dump_pending
212
- end
213
-
214
- context "with show_failures_in_pending_blocks setting enabled" do
215
- before { RSpec.configuration.instance_variable_set(:@show_failures_in_pending_blocks, true) }
216
-
217
- it "preserves formatting" do
218
- group.example("example name") { pending { expect("this").to eq("that") } }
219
-
220
- run_all_and_dump_pending
221
-
222
- expect(output.string).to match(/group name example name/m)
223
- expect(output.string).to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
224
- end
225
-
226
- context "with an exception without a message" do
227
- it "does not throw NoMethodError" do
228
- exception_without_message = Exception.new()
229
- exception_without_message.stub(:message) { nil }
230
- group.example("example name") { pending { raise exception_without_message } }
231
- expect { run_all_and_dump_pending }.not_to raise_error
232
- end
233
- end
234
-
235
- context "with an exception class other than RSpec" do
236
- it "does not show the error class" do
237
- group.example("example name") { pending { raise NameError.new('foo') } }
238
- run_all_and_dump_pending
239
- expect(output.string).to match(/NameError/m)
240
- end
241
- end
242
-
243
- context "with a failed expectation (rspec-expectations)" do
244
- it "does not show the error class" do
245
- group.example("example name") { pending { expect("this").to eq("that") } }
246
- run_all_and_dump_pending
247
- expect(output.string).not_to match(/RSpec/m)
248
- end
249
- end
250
-
251
- context "with a failed message expectation (rspec-mocks)" do
252
- it "does not show the error class" do
253
- group.example("example name") { pending { "this".should_receive("that") } }
254
- run_all_and_dump_pending
255
- expect(output.string).not_to match(/RSpec/m)
256
- end
257
- end
258
-
259
- context 'for #share_examples_for' do
260
- it 'outputs the name and location' do
261
-
262
- group.share_examples_for 'foo bar' do
263
- it("example name") { pending { expect("this").to eq("that") } }
264
- end
265
-
266
- line = __LINE__.next
267
- group.it_should_behave_like('foo bar')
268
-
269
- run_all_and_dump_pending
270
-
271
- expect(output.string).to include(
272
- 'Shared Example Group: "foo bar" called from ' +
273
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
274
- )
275
- end
276
-
277
- context 'that contains nested example groups' do
278
- it 'outputs the name and location' do
279
- group.share_examples_for 'foo bar' do
280
- describe 'nested group' do
281
- it("example name") { pending { expect("this").to eq("that") } }
282
- end
283
- end
284
-
285
- line = __LINE__.next
286
- group.it_should_behave_like('foo bar')
287
-
288
- run_all_and_dump_pending
289
-
290
- expect(output.string).to include(
291
- 'Shared Example Group: "foo bar" called from ' +
292
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
293
- )
294
- end
295
- end
296
- end
297
-
298
- context 'for #share_as' do
299
- before { allow(RSpec).to receive(:deprecate) }
300
-
301
- it 'outputs the name and location' do
302
-
303
- group.share_as :FooBar2 do
304
- it("example name") { pending { expect("this").to eq("that") } }
305
- end
306
-
307
- line = __LINE__.next
308
- group.send(:include, FooBar2)
309
-
310
- run_all_and_dump_pending
311
-
312
- expect(output.string).to include(
313
- 'Shared Example Group: "FooBar2" called from ' +
314
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
315
- )
316
- end
317
-
318
- context 'that contains nested example groups' do
319
- it 'outputs the name and location' do
320
-
321
- group.share_as :NestedFoo2 do
322
- describe 'nested group' do
323
- describe 'hell' do
324
- it("example name") { pending { expect("this").to eq("that") } }
325
- end
326
- end
327
- end
328
-
329
- line = __LINE__.next
330
- group.send(:include, NestedFoo2)
331
-
332
- run_all_and_dump_pending
333
-
334
- expect(output.string).to include(
335
- 'Shared Example Group: "NestedFoo2" called from ' +
336
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
337
- )
338
- end
339
- end
340
- end
341
- end
342
-
343
- context "with show_failures_in_pending_blocks setting disabled" do
344
- before { RSpec.configuration.stub(:show_failures_in_pending_blocks?) { false } }
345
-
346
- it "does not output the failure information" do
347
- group.example("example name") { pending { expect("this").to eq("that") } }
348
- run_all_and_dump_pending
349
- expect(output.string).not_to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
350
- end
351
- end
352
- end
353
-
354
- describe "#dump_profile_slowest_examples" do
355
- example_line_number = nil
356
-
357
- before do
358
- group = RSpec::Core::ExampleGroup.describe("group") do
359
- # Use a sleep so there is some measurable time, to ensure
360
- # the reported percent is 100%, not 0%.
361
- example("example") { sleep 0.001 }
362
- example_line_number = __LINE__ - 1
363
- end
364
- group.run(double('reporter').as_null_object)
365
-
366
- formatter.stub(:examples) { group.examples }
367
- RSpec.configuration.stub(:profile_examples) { 10 }
368
- end
369
-
370
- it "names the example" do
371
- formatter.dump_profile_slowest_examples
372
- expect(output.string).to match(/group example/m)
373
- end
374
-
375
- it "prints the time" do
376
- formatter.dump_profile_slowest_examples
377
- expect(output.string).to match(/0(\.\d+)? seconds/)
378
- end
379
-
380
- it "prints the path" do
381
- formatter.dump_profile_slowest_examples
382
- filename = __FILE__.split(File::SEPARATOR).last
383
-
384
- expect(output.string).to match(/#{filename}\:#{example_line_number}/)
385
- end
386
-
387
- it "prints the percentage taken from the total runtime" do
388
- formatter.dump_profile_slowest_examples
389
- expect(output.string).to match(/, 100.0% of total time\):/)
390
- end
391
- end
392
-
393
- describe "#dump_profile_slowest_example_groups" do
394
- let(:group) do
395
- RSpec::Core::ExampleGroup.describe("slow group") do
396
- # Use a sleep so there is some measurable time, to ensure
397
- # the reported percent is 100%, not 0%.
398
- example("example") { sleep 0.01 }
399
- end
400
- end
401
- let(:rpt) { double('reporter').as_null_object }
402
-
403
- before do
404
- group.run(rpt)
405
- RSpec.configuration.stub(:profile_examples) { 10 }
406
- end
407
-
408
- context "with one example group" do
409
- before { formatter.stub(:examples) { group.examples } }
410
-
411
- it "doesn't profile a single example group" do
412
- formatter.dump_profile_slowest_example_groups
413
- expect(output.string).not_to match(/slowest example groups/)
414
- end
415
- end
416
-
417
- context "with multiple example groups" do
418
- before do
419
- group2 = RSpec::Core::ExampleGroup.describe("fast group") do
420
- example("example 1") { sleep 0.004 }
421
- example("example 2") { sleep 0.007 }
422
- end
423
- group2.run(rpt)
424
-
425
- formatter.stub(:examples) { group.examples + group2.examples }
426
- end
427
-
428
- it "prints the slowest example groups" do
429
- formatter.dump_profile_slowest_example_groups
430
- expect(output.string).to match(/slowest example groups/)
431
- end
432
-
433
- it "prints the time" do
434
- formatter.dump_profile_slowest_example_groups
435
- expect(output.string).to match(/0(\.\d+)? seconds/)
436
- end
437
-
438
- it "ranks the example groups by average time" do
439
- formatter.dump_profile_slowest_example_groups
440
- expect(output.string).to match(/slow group(.*)fast group/m)
441
- end
442
- end
443
-
444
- it "depends on parent_groups to get the top level example group" do
445
- ex = ""
446
- group.describe("group 2") do
447
- describe "group 3" do
448
- ex = example("nested example 1")
449
- end
450
- end
451
-
452
- expect(ex.example_group.parent_groups.last).to eq(group)
453
- end
454
- end
455
-
456
- describe "custom_colors" do
457
- it "uses the custom success color" do
458
- RSpec.configure do |config|
459
- config.color = true
460
- config.tty = true
461
- config.success_color = :cyan
462
- end
463
- formatter.dump_summary(0,1,0,0)
464
- expect(output.string).to include("\e[36m")
465
- end
466
- end
467
-
468
- describe "#colorize" do
469
- before do
470
- allow(RSpec.configuration).to receive(:color_enabled?) { true }
471
- end
472
-
473
- it "accepts a VT100 integer code and formats the text with it" do
474
- expect(formatter.colorize('abc', 32)).to eq "\e[32mabc\e[0m"
475
- end
476
-
477
- it "accepts a symbol as a color parameter and translates it to the correct integer code, then formats the text with it" do
478
- expect(formatter.colorize('abc', :green)).to eq "\e[32mabc\e[0m"
479
- end
480
-
481
- it "accepts a non-default color symbol as a parameter and translates it to the correct integer code, then formats the text with it" do
482
- expect(formatter.colorize('abc', :cyan)).to eq "\e[36mabc\e[0m"
483
- end
484
- end
485
-
486
- describe "#const_missing name" do
487
-
488
- it "warns of deprecation for VT100_COLORS" do
489
- expect_deprecation_with_call_site __FILE__, __LINE__ + 1
490
- expect(described_class::VT100_COLORS).to eq RSpec::Core::Formatters::ConsoleCodes::VT100_CODES
491
- end
492
-
493
- it "warns of deprecation for VT100_COLOR_CODES" do
494
- expect_deprecation_with_call_site __FILE__, __LINE__ + 1
495
- expect(described_class::VT100_COLOR_CODES).to eq RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.to_set
496
- end
497
-
498
- it "behaves normally for other constants" do
499
- expect { described_class::NoSuchConst }.to raise_error(NameError)
500
- end
501
- end
502
-
503
- RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.each do |name, number|
504
- next if name == :black || name == :bold
505
-
506
- describe "##{name}" do
507
- before do
508
- allow(RSpec.configuration).to receive(:color_enabled?) { true }
509
- allow(RSpec).to receive(:deprecate)
510
- end
511
-
512
- it "prints the text using the color code for #{name}" do
513
- expect(formatter.send(name, "text")).to eq("\e[#{number}mtext\e[0m")
514
- end
515
-
516
- it "prints a deprecation warning" do
517
- expect(RSpec).to receive(:deprecate) {|*args|
518
- expect(args.first).to match(/#{name}/)
519
- }
520
- formatter.send(name, "text")
521
- end
522
- end
523
- end
524
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
- require 'rspec/core/formatters/console_codes'
3
-
4
- RSpec.describe "RSpec::Core::Formatters::ConsoleCodes" do
5
- let(:console_codes) { RSpec::Core::Formatters::ConsoleCodes }
6
-
7
- describe "#console_code_for(code_or_symbol)" do
8
- context "when given a VT100 integer code" do
9
- it "returns the code" do
10
- expect(console_codes.console_code_for(32)).to eq 32
11
- end
12
- end
13
-
14
- context "when given a symbolic name" do
15
- it "returns the code" do
16
- expect(console_codes.console_code_for(:green)).to eq 32
17
- end
18
- end
19
-
20
- context "when given a nonexistant code" do
21
- it "returns the code for white" do
22
- expect(console_codes.console_code_for(:octarine)).to eq 37
23
- end
24
- end
25
- end
26
-
27
- describe "#wrap" do
28
- before do
29
- allow(RSpec.configuration).to receive(:color_enabled?) { true }
30
- end
31
-
32
- context "when given a VT100 integer code" do
33
- it "formats the text with it" do
34
- expect(console_codes.wrap('abc', 32)).to eq "\e[32mabc\e[0m"
35
- end
36
- end
37
-
38
- context "when given a symbolic color name" do
39
- it "translates it to the correct integer code and formats the text with it" do
40
- expect(console_codes.wrap('abc', :green)).to eq "\e[32mabc\e[0m"
41
- end
42
- end
43
-
44
- context "when given :bold" do
45
- it "formats the text as bold" do
46
- expect(console_codes.wrap('abc', :bold)).to eq "\e[1mabc\e[0m"
47
- end
48
- end
49
- end
50
- end