rspec-core 3.0.0.beta2 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +1 -0
  5. data/Changelog.md +297 -57
  6. data/README.md +16 -13
  7. data/lib/rspec/core.rb +55 -84
  8. data/lib/rspec/core/backport_random.rb +35 -3
  9. data/lib/rspec/core/backtrace_formatter.rb +4 -13
  10. data/lib/rspec/core/configuration.rb +330 -114
  11. data/lib/rspec/core/configuration_options.rb +38 -22
  12. data/lib/rspec/core/drb.rb +111 -0
  13. data/lib/rspec/core/dsl.rb +8 -2
  14. data/lib/rspec/core/example.rb +203 -94
  15. data/lib/rspec/core/example_group.rb +344 -316
  16. data/lib/rspec/core/filter_manager.rb +135 -90
  17. data/lib/rspec/core/flat_map.rb +1 -0
  18. data/lib/rspec/core/formatters.rb +50 -14
  19. data/lib/rspec/core/formatters/base_formatter.rb +32 -138
  20. data/lib/rspec/core/formatters/base_text_formatter.rb +32 -253
  21. data/lib/rspec/core/formatters/console_codes.rb +65 -0
  22. data/lib/rspec/core/formatters/deprecation_formatter.rb +24 -15
  23. data/lib/rspec/core/formatters/documentation_formatter.rb +7 -10
  24. data/lib/rspec/core/formatters/helpers.rb +15 -9
  25. data/lib/rspec/core/formatters/html_formatter.rb +17 -16
  26. data/lib/rspec/core/formatters/html_printer.rb +1 -0
  27. data/lib/rspec/core/formatters/json_formatter.rb +18 -20
  28. data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
  29. data/lib/rspec/core/formatters/progress_formatter.rb +6 -7
  30. data/lib/rspec/core/formatters/snippet_extractor.rb +8 -6
  31. data/lib/rspec/core/hooks.rb +131 -125
  32. data/lib/rspec/core/memoized_helpers.rb +31 -26
  33. data/lib/rspec/core/metadata.rb +277 -184
  34. data/lib/rspec/core/metadata_filter.rb +86 -0
  35. data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
  36. data/lib/rspec/core/mocking_adapters/flexmock.rb +1 -1
  37. data/lib/rspec/core/mocking_adapters/mocha.rb +1 -1
  38. data/lib/rspec/core/mocking_adapters/null.rb +1 -1
  39. data/lib/rspec/core/mocking_adapters/rr.rb +2 -1
  40. data/lib/rspec/core/mocking_adapters/rspec.rb +1 -1
  41. data/lib/rspec/core/notifications.rb +435 -24
  42. data/lib/rspec/core/option_parser.rb +16 -25
  43. data/lib/rspec/core/ordering.rb +3 -1
  44. data/lib/rspec/core/pending.rb +57 -33
  45. data/lib/rspec/core/project_initializer.rb +2 -0
  46. data/lib/rspec/core/project_initializer/spec_helper.rb +5 -4
  47. data/lib/rspec/core/rake_task.rb +45 -20
  48. data/lib/rspec/core/reporter.rb +50 -22
  49. data/lib/rspec/core/ruby_project.rb +1 -0
  50. data/lib/rspec/core/runner.rb +93 -39
  51. data/lib/rspec/core/shared_context.rb +7 -5
  52. data/lib/rspec/core/shared_example_group.rb +85 -77
  53. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  54. data/lib/rspec/core/version.rb +3 -1
  55. data/lib/rspec/core/warnings.rb +35 -17
  56. data/lib/rspec/core/world.rb +57 -5
  57. metadata +56 -369
  58. metadata.gz.sig +3 -3
  59. data/features/README.md +0 -13
  60. data/features/Upgrade.md +0 -352
  61. data/features/command_line/README.md +0 -25
  62. data/features/command_line/dry_run.feature +0 -29
  63. data/features/command_line/example_name_option.feature +0 -97
  64. data/features/command_line/exit_status.feature +0 -82
  65. data/features/command_line/fail_fast.feature +0 -26
  66. data/features/command_line/format_option.feature +0 -75
  67. data/features/command_line/init.feature +0 -57
  68. data/features/command_line/line_number_appended_to_path.feature +0 -140
  69. data/features/command_line/line_number_option.feature +0 -58
  70. data/features/command_line/order.feature +0 -25
  71. data/features/command_line/pattern_option.feature +0 -49
  72. data/features/command_line/rake_task.feature +0 -122
  73. data/features/command_line/randomization.feature +0 -63
  74. data/features/command_line/require_option.feature +0 -43
  75. data/features/command_line/ruby.feature +0 -23
  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 -39
  79. data/features/configuration/backtrace_exclusion_patterns.feature +0 -105
  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/enable_global_dsl.feature +0 -54
  84. data/features/configuration/fail_fast.feature +0 -77
  85. data/features/configuration/failure_exit_code.feature +0 -36
  86. data/features/configuration/order_and_seed.feature +0 -3
  87. data/features/configuration/output_stream.feature +0 -24
  88. data/features/configuration/overriding_global_ordering.feature +0 -93
  89. data/features/configuration/pattern.feature +0 -38
  90. data/features/configuration/profile.feature +0 -220
  91. data/features/configuration/read_options_from_file.feature +0 -90
  92. data/features/configuration/run_all_when_everything_filtered.feature +0 -76
  93. data/features/example_groups/aliasing.feature +0 -48
  94. data/features/example_groups/basic_structure.feature +0 -55
  95. data/features/example_groups/shared_context.feature +0 -74
  96. data/features/example_groups/shared_examples.feature +0 -286
  97. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
  98. data/features/filtering/exclusion_filters.feature +0 -135
  99. data/features/filtering/if_and_unless.feature +0 -138
  100. data/features/filtering/inclusion_filters.feature +0 -101
  101. data/features/formatters/configurable_colors.feature +0 -31
  102. data/features/formatters/custom_formatter.feature +0 -68
  103. data/features/formatters/json_formatter.feature +0 -30
  104. data/features/formatters/regression_tests.feature +0 -95
  105. data/features/formatters/text_formatter.feature +0 -46
  106. data/features/helper_methods/arbitrary_methods.feature +0 -40
  107. data/features/helper_methods/let.feature +0 -50
  108. data/features/helper_methods/modules.feature +0 -146
  109. data/features/hooks/around_hooks.feature +0 -344
  110. data/features/hooks/before_and_after_hooks.feature +0 -427
  111. data/features/hooks/filtering.feature +0 -232
  112. data/features/metadata/current_example.feature +0 -56
  113. data/features/metadata/described_class.feature +0 -17
  114. data/features/metadata/user_defined.feature +0 -100
  115. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  116. data/features/mock_framework_integration/use_flexmock.feature +0 -94
  117. data/features/mock_framework_integration/use_mocha.feature +0 -95
  118. data/features/mock_framework_integration/use_rr.feature +0 -96
  119. data/features/mock_framework_integration/use_rspec.feature +0 -95
  120. data/features/pending_and_skipped_examples/README.md +0 -3
  121. data/features/pending_and_skipped_examples/pending_examples.feature +0 -118
  122. data/features/pending_and_skipped_examples/skipped_examples.feature +0 -106
  123. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  124. data/features/step_definitions/additional_cli_steps.rb +0 -83
  125. data/features/subject/explicit_subject.feature +0 -101
  126. data/features/subject/implicit_subject.feature +0 -63
  127. data/features/subject/one_liner_syntax.feature +0 -71
  128. data/features/support/env.rb +0 -21
  129. data/features/support/require_expect_syntax_in_aruba_specs.rb +0 -16
  130. data/features/support/rubinius.rb +0 -6
  131. data/lib/rspec/core/command_line.rb +0 -35
  132. data/lib/rspec/core/drb_command_line.rb +0 -26
  133. data/lib/rspec/core/drb_options.rb +0 -87
  134. data/lib/rspec/core/formatters/legacy_formatter.rb +0 -227
  135. data/lib/rspec/core/shared_example_group/collection.rb +0 -27
  136. data/spec/command_line/order_spec.rb +0 -211
  137. data/spec/rspec/core/backtrace_formatter_spec.rb +0 -230
  138. data/spec/rspec/core/command_line_spec.rb +0 -112
  139. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  140. data/spec/rspec/core/configuration_options_spec.rb +0 -409
  141. data/spec/rspec/core/configuration_spec.rb +0 -1479
  142. data/spec/rspec/core/drb_command_line_spec.rb +0 -102
  143. data/spec/rspec/core/drb_options_spec.rb +0 -193
  144. data/spec/rspec/core/dsl_spec.rb +0 -88
  145. data/spec/rspec/core/example_group_spec.rb +0 -1533
  146. data/spec/rspec/core/example_spec.rb +0 -642
  147. data/spec/rspec/core/filter_manager_spec.rb +0 -229
  148. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -64
  149. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -303
  150. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -208
  151. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -75
  152. data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
  153. data/spec/rspec/core/formatters/html_formatted-2.1.0.html +0 -392
  154. data/spec/rspec/core/formatters/html_formatted.html +0 -397
  155. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -122
  156. data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -206
  157. data/spec/rspec/core/formatters/legacy_formatter_spec.rb +0 -137
  158. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -43
  159. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
  160. data/spec/rspec/core/formatters_spec.rb +0 -120
  161. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  162. data/spec/rspec/core/hooks_spec.rb +0 -294
  163. data/spec/rspec/core/memoized_helpers_spec.rb +0 -495
  164. data/spec/rspec/core/metadata_spec.rb +0 -491
  165. data/spec/rspec/core/option_parser_spec.rb +0 -262
  166. data/spec/rspec/core/ordering_spec.rb +0 -102
  167. data/spec/rspec/core/pending_example_spec.rb +0 -117
  168. data/spec/rspec/core/pending_spec.rb +0 -8
  169. data/spec/rspec/core/project_initializer_spec.rb +0 -73
  170. data/spec/rspec/core/rake_task_spec.rb +0 -146
  171. data/spec/rspec/core/random_spec.rb +0 -47
  172. data/spec/rspec/core/reporter_spec.rb +0 -155
  173. data/spec/rspec/core/resources/a_bar.rb +0 -0
  174. data/spec/rspec/core/resources/a_foo.rb +0 -0
  175. data/spec/rspec/core/resources/a_spec.rb +0 -1
  176. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  177. data/spec/rspec/core/resources/formatter_specs.rb +0 -58
  178. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  179. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  180. data/spec/rspec/core/ruby_project_spec.rb +0 -26
  181. data/spec/rspec/core/runner_spec.rb +0 -151
  182. data/spec/rspec/core/shared_context_spec.rb +0 -102
  183. data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -57
  184. data/spec/rspec/core/shared_example_group_spec.rb +0 -114
  185. data/spec/rspec/core/warnings_spec.rb +0 -29
  186. data/spec/rspec/core/world_spec.rb +0 -142
  187. data/spec/rspec/core_spec.rb +0 -91
  188. data/spec/spec_helper.rb +0 -160
  189. data/spec/support/config_options_helper.rb +0 -13
  190. data/spec/support/formatter_support.rb +0 -83
  191. data/spec/support/helper_methods.rb +0 -26
  192. data/spec/support/isolate_load_path_mutation.rb +0 -5
  193. data/spec/support/isolated_directory.rb +0 -10
  194. data/spec/support/isolated_home_directory.rb +0 -16
  195. data/spec/support/legacy_formatter_using_sub_classing_example.rb +0 -87
  196. data/spec/support/matchers.rb +0 -85
  197. data/spec/support/mathn_integration_support.rb +0 -12
  198. data/spec/support/old_style_formatter_example.rb +0 -69
  199. data/spec/support/shared_example_groups.rb +0 -13
  200. data/spec/support/spec_files.rb +0 -44
  201. data/spec/support/stderr_splitter.rb +0 -36
@@ -1,229 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec::Core
4
- RSpec.describe FilterManager do
5
- def opposite(name)
6
- name =~ /^in/ ? name.sub(/^(in)/,'ex') : name.sub(/^(ex)/,'in')
7
- end
8
-
9
- %w[include inclusions exclude exclusions].each_slice(2) do |name, type|
10
- describe "##{name}" do
11
- it "merges #{type}" do
12
- filter_manager = FilterManager.new
13
- filter_manager.exclusions.clear # defaults
14
- filter_manager.send name, :foo => :bar
15
- filter_manager.send name, :baz => :bam
16
- expect(filter_manager.send(type)).to eq(:foo => :bar, :baz => :bam)
17
- end
18
-
19
- it "overrides previous #{type} with (via merge)" do
20
- filter_manager = FilterManager.new
21
- filter_manager.exclusions.clear # defaults
22
- filter_manager.send name, :foo => 1
23
- filter_manager.send name, :foo => 2
24
- expect(filter_manager.send(type)).to eq(:foo => 2)
25
- end
26
-
27
- it "deletes matching opposites" do
28
- filter_manager = FilterManager.new
29
- filter_manager.exclusions.clear # defaults
30
- filter_manager.send opposite(name), :foo => 1
31
- filter_manager.send name, :foo => 2
32
- expect(filter_manager.send(type)).to eq(:foo => 2)
33
- expect(filter_manager.send(opposite(type))).to be_empty
34
- end
35
-
36
- if name == "include"
37
- [:locations, :line_numbers, :full_description].each do |filter|
38
- context "with :#{filter}" do
39
- it "clears previous inclusions" do
40
- filter_manager = FilterManager.new
41
- filter_manager.include :foo => :bar
42
- filter_manager.include filter => "value"
43
- expect(filter_manager.inclusions).to eq({filter => "value"})
44
- end
45
-
46
- it "clears previous exclusion" do
47
- filter_manager = FilterManager.new
48
- filter_manager.include :foo => :bar
49
- filter_manager.include filter => "value"
50
- expect(filter_manager.exclusions).to be_empty
51
- end
52
-
53
- it "does nothing when :#{filter} previously set" do
54
- filter_manager = FilterManager.new
55
- filter_manager.include filter => "a_value"
56
- filter_manager.include :foo => :bar
57
- expect(filter_manager.inclusions).to eq(filter => "a_value")
58
- end
59
- end
60
- end
61
- end
62
- end
63
-
64
- describe "##{name}!" do
65
- it "replaces existing #{type}" do
66
- filter_manager = FilterManager.new
67
- filter_manager.exclusions.clear # defaults
68
- filter_manager.send name, :foo => 1, :bar => 2
69
- filter_manager.send "#{name}!", :foo => 3
70
- expect(filter_manager.send(type)).to eq(:foo => 3)
71
- end
72
-
73
- it "deletes matching opposites" do
74
- filter_manager = FilterManager.new
75
- filter_manager.exclusions.clear # defaults
76
- filter_manager.send opposite(name), :foo => 1
77
- filter_manager.send "#{name}!", :foo => 2
78
- expect(filter_manager.send(type)).to eq(:foo => 2)
79
- expect(filter_manager.send(opposite(type))).to be_empty
80
- end
81
- end
82
-
83
- describe "##{name}_with_low_priority" do
84
- it "ignores new #{type} if same key exists" do
85
- filter_manager = FilterManager.new
86
- filter_manager.exclusions.clear # defaults
87
- filter_manager.send name, :foo => 1
88
- filter_manager.send "#{name}_with_low_priority", :foo => 2
89
- expect(filter_manager.send(type)).to eq(:foo => 1)
90
- end
91
-
92
- it "ignores new #{type} if same key exists in opposite" do
93
- filter_manager = FilterManager.new
94
- filter_manager.exclusions.clear # defaults
95
- filter_manager.send opposite(name), :foo => 1
96
- filter_manager.send "#{name}_with_low_priority", :foo => 1
97
- expect(filter_manager.send(type)).to be_empty
98
- expect(filter_manager.send(opposite(type))).to eq(:foo => 1)
99
- end
100
-
101
- it "keeps new #{type} if same key exists in opposite but values are different" do
102
- filter_manager = FilterManager.new
103
- filter_manager.exclusions.clear # defaults
104
- filter_manager.send opposite(name), :foo => 1
105
- filter_manager.send "#{name}_with_low_priority", :foo => 2
106
- expect(filter_manager.send(type)).to eq(:foo => 2)
107
- expect(filter_manager.send(opposite(type))).to eq(:foo => 1)
108
- end
109
- end
110
- end
111
-
112
- describe "#prune" do
113
- def filterable_object_with(args = {})
114
- object = double('a filterable object')
115
- allow(object).to receive(:any_apply?) { |f| Metadata.new(args).any_apply?(f) }
116
- object
117
- end
118
-
119
- it "includes objects with tags matching inclusions" do
120
- included = filterable_object_with({:foo => :bar})
121
- excluded = filterable_object_with
122
- filter_manager = FilterManager.new
123
- filter_manager.include :foo => :bar
124
- expect(filter_manager.prune([included, excluded])).to eq([included])
125
- end
126
-
127
- it "excludes objects with tags matching exclusions" do
128
- included = filterable_object_with
129
- excluded = filterable_object_with({:foo => :bar})
130
- filter_manager = FilterManager.new
131
- filter_manager.exclude :foo => :bar
132
- expect(filter_manager.prune([included, excluded])).to eq([included])
133
- end
134
-
135
- it "prefers exclusion when matches previously set inclusion" do
136
- included = filterable_object_with
137
- excluded = filterable_object_with({:foo => :bar})
138
- filter_manager = FilterManager.new
139
- filter_manager.include :foo => :bar
140
- filter_manager.exclude :foo => :bar
141
- expect(filter_manager.prune([included, excluded])).to eq([included])
142
- end
143
-
144
- it "prefers inclusion when matches previously set exclusion" do
145
- included = filterable_object_with({:foo => :bar})
146
- excluded = filterable_object_with
147
- filter_manager = FilterManager.new
148
- filter_manager.exclude :foo => :bar
149
- filter_manager.include :foo => :bar
150
- expect(filter_manager.prune([included, excluded])).to eq([included])
151
- end
152
-
153
- it "prefers previously set inclusion when exclusion matches but has lower priority" do
154
- included = filterable_object_with({:foo => :bar})
155
- excluded = filterable_object_with
156
- filter_manager = FilterManager.new
157
- filter_manager.include :foo => :bar
158
- filter_manager.exclude_with_low_priority :foo => :bar
159
- expect(filter_manager.prune([included, excluded])).to eq([included])
160
- end
161
-
162
- it "prefers previously set exclusion when inclusion matches but has lower priority" do
163
- included = filterable_object_with
164
- excluded = filterable_object_with({:foo => :bar})
165
- filter_manager = FilterManager.new
166
- filter_manager.exclude :foo => :bar
167
- filter_manager.include_with_low_priority :foo => :bar
168
- expect(filter_manager.prune([included, excluded])).to eq([included])
169
- end
170
- end
171
-
172
- describe "#inclusions#description" do
173
- it 'cleans up the description' do
174
- project_dir = File.expand_path('.')
175
- expect(lambda { }.inspect).to include(project_dir)
176
- expect(lambda { }.inspect).to include(' (lambda)') if RUBY_VERSION > '1.9'
177
- expect(lambda { }.inspect).to include('0x')
178
-
179
- filter_manager = FilterManager.new
180
- filter_manager.include :foo => lambda { }
181
-
182
- expect(filter_manager.inclusions.description).not_to include(project_dir)
183
- expect(filter_manager.inclusions.description).not_to include(' (lambda)')
184
- expect(filter_manager.inclusions.description).not_to include('0x')
185
- end
186
- end
187
-
188
- describe "#exclusions#description" do
189
- it 'cleans up the description' do
190
- project_dir = File.expand_path('.')
191
- expect(lambda { }.inspect).to include(project_dir)
192
- expect(lambda { }.inspect).to include(' (lambda)') if RUBY_VERSION > '1.9'
193
- expect(lambda { }.inspect).to include('0x')
194
-
195
- filter_manager = FilterManager.new
196
- filter_manager.exclude :foo => lambda { }
197
-
198
- expect(filter_manager.exclusions.description).not_to include(project_dir)
199
- expect(filter_manager.exclusions.description).not_to include(' (lambda)')
200
- expect(filter_manager.exclusions.description).not_to include('0x')
201
- end
202
-
203
- it 'returns `{}` when it only contains the default filters' do
204
- filter_manager = FilterManager.new
205
- expect(filter_manager.exclusions.description).to eq({}.inspect)
206
- end
207
-
208
- it 'includes other filters' do
209
- filter_manager = FilterManager.new
210
- filter_manager.exclude :foo => :bar
211
- expect(filter_manager.exclusions.description).to eq({ :foo => :bar }.inspect)
212
- end
213
-
214
- it 'includes an overriden :if filter' do
215
- allow(RSpec).to receive(:deprecate)
216
- filter_manager = FilterManager.new
217
- filter_manager.exclude :if => :custom_filter
218
- expect(filter_manager.exclusions.description).to eq({ :if => :custom_filter }.inspect)
219
- end
220
-
221
- it 'includes an overriden :unless filter' do
222
- allow(RSpec).to receive(:deprecate)
223
- filter_manager = FilterManager.new
224
- filter_manager.exclude :unless => :custom_filter
225
- expect(filter_manager.exclusions.description).to eq({ :unless => :custom_filter }.inspect)
226
- end
227
- end
228
- end
229
- end
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
- require 'rspec/core/formatters/base_formatter'
3
-
4
- RSpec.describe RSpec::Core::Formatters::BaseFormatter do
5
- include FormatterSupport
6
-
7
- describe "read_failed_line" do
8
- it "deals gracefully with a heterogeneous language stack trace" do
9
- exception = double(:Exception, :backtrace => [
10
- "at Object.prototypeMethod (foo:331:18)",
11
- "at Array.forEach (native)",
12
- "at a_named_javascript_function (/some/javascript/file.js:39:5)",
13
- "/some/line/of/ruby.rb:14"
14
- ])
15
- example = double(:Example, :file_path => __FILE__)
16
- expect {
17
- formatter.send(:read_failed_line, exception, example)
18
- }.not_to raise_error
19
- end
20
-
21
- it "deals gracefully with a security error" do
22
- exception = double(:Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"])
23
- example = double(:Example, :file_path => __FILE__)
24
- safely do
25
- expect {
26
- formatter.send(:read_failed_line, exception, example)
27
- }.not_to raise_error
28
- end
29
- end
30
-
31
- context "when ruby reports a bogus line number in the stack trace" do
32
- it "reports the filename and that it was unable to find the matching line" do
33
- exception = double(:Exception, :backtrace => [ "#{__FILE__}:10000000" ])
34
- example = double(:Example, :file_path => __FILE__)
35
-
36
- msg = formatter.send(:read_failed_line, exception, example)
37
- expect(msg).to include("Unable to find matching line")
38
- end
39
- end
40
-
41
- context "when String alias to_int to_i" do
42
- before do
43
- String.class_eval do
44
- alias :to_int :to_i
45
- end
46
- end
47
-
48
- after do
49
- String.class_eval do
50
- undef to_int
51
- end
52
- end
53
-
54
- it "doesn't hang when file exists" do
55
- exception = double(:Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"])
56
-
57
- example = double(:Example, :file_path => __FILE__)
58
- expect(formatter.send(:read_failed_line, exception, example)).to eql(
59
- %Q{ exception = double(:Exception, :backtrace => [ "\#{__FILE__}:\#{__LINE__}"])\n})
60
- end
61
-
62
- end
63
- end
64
- end
@@ -1,303 +0,0 @@
1
- require 'spec_helper'
2
- require 'rspec/core/formatters/base_text_formatter'
3
-
4
- RSpec.describe RSpec::Core::Formatters::BaseTextFormatter do
5
- include FormatterSupport
6
-
7
- describe "#dump_summary" do
8
- it "with 0s outputs pluralized (excluding pending)" do
9
- send_notification :dump_summary, summary_notification(0, 0, 0, 0)
10
- expect(output.string).to match("0 examples, 0 failures")
11
- end
12
-
13
- it "with 1s outputs singular (including pending)" do
14
- send_notification :dump_summary, summary_notification(1, 1, 1, 1)
15
- expect(output.string).to match("1 example, 1 failure, 1 pending")
16
- end
17
-
18
- it "with 2s outputs pluralized (including pending)" do
19
- send_notification :dump_summary, summary_notification(2, 2, 2, 2)
20
- expect(output.string).to match("2 examples, 2 failures, 2 pending")
21
- end
22
- end
23
-
24
- describe "#dump_commands_to_rerun_failed_examples" do
25
- it "includes command to re-run each failed example" do
26
- group = RSpec::Core::ExampleGroup.describe("example group") do
27
- it("fails") { fail }
28
- end
29
- line = __LINE__ - 2
30
- group.run(reporter)
31
- formatter.dump_commands_to_rerun_failed_examples
32
- expect(output.string).to include("rspec #{RSpec::Core::Metadata::relative_path("#{__FILE__}:#{line}")} # example group fails")
33
- end
34
- end
35
-
36
- describe "#dump_failures" do
37
- let(:group) { RSpec::Core::ExampleGroup.describe("group name") }
38
-
39
- before { allow(RSpec.configuration).to receive(:color_enabled?) { false } }
40
-
41
- def run_all_and_dump_failures
42
- group.run(reporter)
43
- send_notification :dump_failures, null_notification
44
- end
45
-
46
- it "preserves formatting" do
47
- group.example("example name") { expect("this").to eq("that") }
48
-
49
- run_all_and_dump_failures
50
-
51
- expect(output.string).to match(/group name example name/m)
52
- expect(output.string).to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
53
- end
54
-
55
- context "with an exception without a message" do
56
- it "does not throw NoMethodError" do
57
- exception_without_message = Exception.new()
58
- allow(exception_without_message).to receive(:message) { nil }
59
- group.example("example name") { raise exception_without_message }
60
- expect { run_all_and_dump_failures }.not_to raise_error
61
- end
62
-
63
- it "preserves ancestry" do
64
- example = group.example("example name") { raise "something" }
65
- run_all_and_dump_failures
66
- expect(example.example_group.parent_groups.size).to eq 1
67
- end
68
- end
69
-
70
- context "with an exception that has an exception instance as its message" do
71
- it "does not raise NoMethodError" do
72
- gonzo_exception = RuntimeError.new
73
- allow(gonzo_exception).to receive(:message) { gonzo_exception }
74
- group.example("example name") { raise gonzo_exception }
75
- expect { run_all_and_dump_failures }.not_to raise_error
76
- end
77
- end
78
-
79
- context "with an instance of an anonymous exception class" do
80
- it "substitutes '(anonymous error class)' for the missing class name" do
81
- exception = Class.new(StandardError).new
82
- group.example("example name") { raise exception }
83
- run_all_and_dump_failures
84
- expect(output.string).to include('(anonymous error class)')
85
- end
86
- end
87
-
88
- context "with an exception class other than RSpec" do
89
- it "does not show the error class" do
90
- group.example("example name") { raise NameError.new('foo') }
91
- run_all_and_dump_failures
92
- expect(output.string).to match(/NameError/m)
93
- end
94
- end
95
-
96
- context "with a failed expectation (rspec-expectations)" do
97
- it "does not show the error class" do
98
- group.example("example name") { expect("this").to eq("that") }
99
- run_all_and_dump_failures
100
- expect(output.string).not_to match(/RSpec/m)
101
- end
102
- end
103
-
104
- context "with a failed message expectation (rspec-mocks)" do
105
- it "does not show the error class" do
106
- group.example("example name") { expect("this").to receive("that") }
107
- run_all_and_dump_failures
108
- expect(output.string).not_to match(/RSpec/m)
109
- end
110
- end
111
-
112
- context 'for #share_examples_for' do
113
- it 'outputs the name and location' do
114
-
115
- group.share_examples_for 'foo bar' do
116
- it("example name") { expect("this").to eq("that") }
117
- end
118
-
119
- line = __LINE__.next
120
- group.it_should_behave_like('foo bar')
121
-
122
- run_all_and_dump_failures
123
-
124
- expect(output.string).to include(
125
- 'Shared Example Group: "foo bar" called from ' +
126
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
127
- )
128
- end
129
-
130
- context 'that contains nested example groups' do
131
- it 'outputs the name and location' do
132
- group.share_examples_for 'foo bar' do
133
- describe 'nested group' do
134
- it("example name") { expect("this").to eq("that") }
135
- end
136
- end
137
-
138
- line = __LINE__.next
139
- group.it_should_behave_like('foo bar')
140
-
141
- run_all_and_dump_failures
142
-
143
- expect(output.string).to include(
144
- 'Shared Example Group: "foo bar" called from ' +
145
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
146
- )
147
- end
148
- end
149
- end
150
- end
151
-
152
- describe "#dump_profile_slowest_examples", :slow do
153
- example_line_number = nil
154
-
155
- before do
156
- group = RSpec::Core::ExampleGroup.describe("group") do
157
- example("example") do |example|
158
- # make it look slow without actually taking up precious time
159
- example.clock = class_double(RSpec::Core::Time, :now => RSpec::Core::Time.now + 0.5)
160
- end
161
- example_line_number = __LINE__ - 4
162
- end
163
- group.run(reporter)
164
-
165
- allow(formatter).to receive(:examples) { group.examples }
166
- allow(RSpec.configuration).to receive(:profile_examples) { 10 }
167
- end
168
-
169
- it "names the example" do
170
- formatter.dump_profile_slowest_examples
171
- expect(output.string).to match(/group example/m)
172
- end
173
-
174
- it "prints the time" do
175
- formatter.dump_profile_slowest_examples
176
- expect(output.string).to match(/0(\.\d+)? seconds/)
177
- end
178
-
179
- it "prints the path" do
180
- formatter.dump_profile_slowest_examples
181
- filename = __FILE__.split(File::SEPARATOR).last
182
-
183
- expect(output.string).to match(/#{filename}\:#{example_line_number}/)
184
- end
185
-
186
- it "prints the percentage taken from the total runtime" do
187
- formatter.dump_profile_slowest_examples
188
- expect(output.string).to match(/, 100.0% of total time\):/)
189
- end
190
- end
191
-
192
- describe "#dump_profile_slowest_example_groups", :slow do
193
- let(:group) do
194
- RSpec::Core::ExampleGroup.describe("slow group") do
195
- example("example") do |example|
196
- # make it look slow without actually taking up precious time
197
- example.clock = class_double(RSpec::Core::Time, :now => RSpec::Core::Time.now + 0.5)
198
- end
199
- end
200
- end
201
-
202
- before do
203
- group.run(reporter)
204
- allow(RSpec.configuration).to receive(:profile_examples) { 10 }
205
- end
206
-
207
- context "with one example group" do
208
- before { allow(formatter).to receive(:examples) { group.examples } }
209
-
210
- it "doesn't profile a single example group" do
211
- formatter.dump_profile_slowest_example_groups
212
- expect(output.string).not_to match(/slowest example groups/)
213
- end
214
- end
215
-
216
- context "with multiple example groups" do
217
- before do
218
- group2 = RSpec::Core::ExampleGroup.describe("fast group") do
219
- example("example 1") { }
220
- example("example 2") { }
221
- end
222
- group2.run(reporter)
223
-
224
- allow(formatter).to receive(:examples) { group.examples + group2.examples }
225
- end
226
-
227
- it "prints the slowest example groups" do
228
- formatter.dump_profile_slowest_example_groups
229
- expect(output.string).to match(/slowest example groups/)
230
- end
231
-
232
- it "prints the time" do
233
- formatter.dump_profile_slowest_example_groups
234
- expect(output.string).to match(/0(\.\d+)? seconds/)
235
- end
236
-
237
- it "ranks the example groups by average time" do
238
- formatter.dump_profile_slowest_example_groups
239
- expect(output.string).to match(/slow group(.*)fast group/m)
240
- end
241
- end
242
-
243
- it "depends on parent_groups to get the top level example group" do
244
- ex = ""
245
- group.describe("group 2") do
246
- describe "group 3" do
247
- ex = example("nested example 1")
248
- end
249
- end
250
-
251
- expect(ex.example_group.parent_groups.last).to eq(group)
252
- end
253
- end
254
-
255
- describe "custom_colors" do
256
- it "uses the custom success color" do
257
- RSpec.configure do |config|
258
- config.color_enabled = true
259
- config.tty = true
260
- config.success_color = :cyan
261
- end
262
- send_notification :dump_summary, summary_notification(0, 1, 0, 0)
263
- expect(output.string).to include("\e[36m")
264
- end
265
- end
266
-
267
- describe "#colorize" do
268
- it "accepts a VT100 integer code and formats the text with it" do
269
- expect(formatter.colorize('abc', 32)).to eq "\e[32mabc\e[0m"
270
- end
271
-
272
- it "accepts a symbol as a color parameter and translates it to the correct integer code, then formats the text with it" do
273
- expect(formatter.colorize('abc', :green)).to eq "\e[32mabc\e[0m"
274
- end
275
-
276
- 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
277
- expect(formatter.colorize('abc', :cyan)).to eq "\e[36mabc\e[0m"
278
- end
279
- end
280
-
281
- described_class::VT100_COLORS.each do |name, number|
282
- next if name == :black
283
-
284
- describe "##{name}" do
285
- before do
286
- allow(RSpec.configuration).to receive(:color_enabled?) { true }
287
- allow(RSpec).to receive(:deprecate)
288
- end
289
-
290
- it "prints the text using the color code for #{name}" do
291
- expect(formatter.send(name, "text")).to eq("\e[#{number}mtext\e[0m")
292
- end
293
-
294
- it "prints a deprecation warning" do
295
- expect(RSpec).to receive(:deprecate) {|*args|
296
- expect(args.first).to match(/#{name}/)
297
- }
298
- formatter.send(name, "text")
299
- end
300
- end
301
- end
302
-
303
- end