rspec-core 3.0.0.beta2 → 3.0.0.rc1

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 (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,227 +0,0 @@
1
- require "spec_helper"
2
-
3
- module RSpec::Core
4
- RSpec.describe "config block hook filtering" do
5
- describe "unfiltered hooks" do
6
- it "is run" do
7
- filters = []
8
- RSpec.configure do |c|
9
- c.before(:all) { filters << "before all in config"}
10
- c.around(:each) {|example| filters << "around each in config"; example.run}
11
- c.before(:each) { filters << "before each in config"}
12
- c.after(:each) { filters << "after each in config"}
13
- c.after(:all) { filters << "after all in config"}
14
- end
15
- group = ExampleGroup.describe
16
- group.example("example") {}
17
- group.run
18
- expect(filters).to eq([
19
- "before all in config",
20
- "around each in config",
21
- "before each in config",
22
- "after each in config",
23
- "after all in config"
24
- ])
25
- end
26
- end
27
-
28
- describe "hooks with single filters" do
29
-
30
- context "with no scope specified" do
31
- it "is run around|before|after :each if the filter matches the example group's filter" do
32
- filters = []
33
- RSpec.configure do |c|
34
- c.around(:match => true) {|example| filters << "around each in config"; example.run}
35
- c.before(:match => true) { filters << "before each in config"}
36
- c.after(:match => true) { filters << "after each in config"}
37
- end
38
- group = ExampleGroup.describe(:match => true)
39
- group.example("example") {}
40
- group.run
41
- expect(filters).to eq([
42
- "around each in config",
43
- "before each in config",
44
- "after each in config"
45
- ])
46
- end
47
- end
48
-
49
- it "is run if the filter matches the example group's filter" do
50
- filters = []
51
- RSpec.configure do |c|
52
- c.before(:all, :match => true) { filters << "before all in config"}
53
- c.around(:each, :match => true) {|example| filters << "around each in config"; example.run}
54
- c.before(:each, :match => true) { filters << "before each in config"}
55
- c.after(:each, :match => true) { filters << "after each in config"}
56
- c.after(:all, :match => true) { filters << "after all in config"}
57
- end
58
- group = ExampleGroup.describe(:match => true)
59
- group.example("example") {}
60
- group.run
61
- expect(filters).to eq([
62
- "before all in config",
63
- "around each in config",
64
- "before each in config",
65
- "after each in config",
66
- "after all in config"
67
- ])
68
- end
69
-
70
- it "runs before|after :all hooks on matching nested example groups" do
71
- filters = []
72
- RSpec.configure do |c|
73
- c.before(:all, :match => true) { filters << :before_all }
74
- c.after(:all, :match => true) { filters << :after_all }
75
- end
76
-
77
- example_1_filters = example_2_filters = nil
78
-
79
- group = ExampleGroup.describe "group" do
80
- it("example 1") { example_1_filters = filters.dup }
81
- describe "subgroup", :match => true do
82
- it("example 2") { example_2_filters = filters.dup }
83
- end
84
- end
85
- group.run
86
-
87
- expect(example_1_filters).to be_empty
88
- expect(example_2_filters).to eq([:before_all])
89
- expect(filters).to eq([:before_all, :after_all])
90
- end
91
-
92
- it "runs before|after :all hooks only on the highest level group that matches the filter" do
93
- filters = []
94
- RSpec.configure do |c|
95
- c.before(:all, :match => true) { filters << :before_all }
96
- c.after(:all, :match => true) { filters << :after_all }
97
- end
98
-
99
- example_1_filters = example_2_filters = example_3_filters = nil
100
-
101
- group = ExampleGroup.describe "group", :match => true do
102
- it("example 1") { example_1_filters = filters.dup }
103
- describe "subgroup", :match => true do
104
- it("example 2") { example_2_filters = filters.dup }
105
- describe "sub-subgroup", :match => true do
106
- it("example 3") { example_3_filters = filters.dup }
107
- end
108
- end
109
- end
110
- group.run
111
-
112
- expect(example_1_filters).to eq([:before_all])
113
- expect(example_2_filters).to eq([:before_all])
114
- expect(example_3_filters).to eq([:before_all])
115
-
116
- expect(filters).to eq([:before_all, :after_all])
117
- end
118
-
119
- it "does not run if the filter doesn't match the example group's filter" do
120
- filters = []
121
- RSpec.configure do |c|
122
- c.before(:all, :match => false) { filters << "before all in config"}
123
- c.around(:each, :match => false) {|example| filters << "around each in config"; example.run}
124
- c.before(:each, :match => false) { filters << "before each in config"}
125
- c.after(:each, :match => false) { filters << "after each in config"}
126
- c.after(:all, :match => false) { filters << "after all in config"}
127
- end
128
- group = ExampleGroup.describe(:match => true)
129
- group.example("example") {}
130
- group.run
131
- expect(filters).to eq([])
132
- end
133
-
134
- context "when the hook filters apply to individual examples instead of example groups" do
135
- let(:each_filters) { [] }
136
- let(:all_filters) { [] }
137
-
138
- let(:group) do
139
- md = example_metadata
140
- ExampleGroup.describe do
141
- it("example", md) { }
142
- end
143
- end
144
-
145
- def filters
146
- each_filters + all_filters
147
- end
148
-
149
- before(:each) do
150
- af, ef = all_filters, each_filters
151
-
152
- RSpec.configure do |c|
153
- c.before(:all, :foo => :bar) { af << "before all in config"}
154
- c.around(:each, :foo => :bar) {|example| ef << "around each in config"; example.run}
155
- c.before(:each, :foo => :bar) { ef << "before each in config"}
156
- c.after(:each, :foo => :bar) { ef << "after each in config"}
157
- c.after(:all, :foo => :bar) { af << "after all in config"}
158
- end
159
-
160
- group.run
161
- end
162
-
163
- describe 'an example with matching metadata' do
164
- let(:example_metadata) { { :foo => :bar } }
165
-
166
- it "runs the `:each` hooks" do
167
- expect(each_filters).to eq([
168
- 'around each in config',
169
- 'before each in config',
170
- 'after each in config'
171
- ])
172
- end
173
-
174
- it "does not run the `:all` hooks" do
175
- expect(all_filters).to be_empty
176
- end
177
- end
178
-
179
- describe 'an example without matching metadata' do
180
- let(:example_metadata) { { :foo => :bazz } }
181
-
182
- it "does not run any of the hooks" do
183
- expect(filters).to be_empty
184
- end
185
- end
186
- end
187
- end
188
-
189
- describe "hooks with multiple filters" do
190
- it "is run if all hook filters match the group's filters" do
191
- filters = []
192
- RSpec.configure do |c|
193
- c.before(:all, :one => 1) { filters << "before all in config"}
194
- c.around(:each, :two => 2, :one => 1) {|example| filters << "around each in config"; example.run}
195
- c.before(:each, :one => 1, :two => 2) { filters << "before each in config"}
196
- c.after(:each, :one => 1, :two => 2, :three => 3) { filters << "after each in config"}
197
- c.after(:all, :one => 1, :three => 3) { filters << "after all in config"}
198
- end
199
- group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
200
- group.example("example") {}
201
- group.run
202
- expect(filters).to eq([
203
- "before all in config",
204
- "around each in config",
205
- "before each in config",
206
- "after each in config",
207
- "after all in config"
208
- ])
209
- end
210
-
211
- it "does not run if some hook filters don't match the group's filters" do
212
- filters = []
213
- RSpec.configure do |c|
214
- c.before(:all, :one => 1, :four => 4) { filters << "before all in config"}
215
- c.around(:each, :two => 2, :four => 4) {|example| filters << "around each in config"; example.run}
216
- c.before(:each, :one => 1, :two => 2, :four => 4) { filters << "before each in config"}
217
- c.after(:each, :one => 1, :two => 2, :three => 3, :four => 4) { filters << "after each in config"}
218
- c.after(:all, :one => 1, :three => 3, :four => 4) { filters << "after all in config"}
219
- end
220
- group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
221
- group.example("example") {}
222
- group.run
223
- expect(filters).to eq([])
224
- end
225
- end
226
- end
227
- end
@@ -1,294 +0,0 @@
1
- require "spec_helper"
2
-
3
- module RSpec::Core
4
- RSpec.describe Hooks do
5
- class HooksHost
6
- include Hooks
7
-
8
- def parent_groups
9
- []
10
- end
11
- end
12
-
13
- [:before, :after, :around].each do |type|
14
- [:each, :all].each do |scope|
15
- next if type == :around && scope == :all
16
-
17
- describe "##{type}(#{scope})" do
18
- it_behaves_like "metadata hash builder" do
19
- define_method :metadata_hash do |*args|
20
- instance = HooksHost.new
21
- args.unshift scope if scope
22
- hooks = instance.send(type, *args) {}
23
- hooks.first.options
24
- end
25
- end
26
- end
27
- end
28
-
29
- describe "##{type}(no scope)" do
30
- let(:instance) { HooksHost.new }
31
-
32
- it "defaults to :each scope if no arguments are given" do
33
- hooks = instance.send(type) {}
34
- hook = hooks.first
35
- expect(instance.hooks[type][:each]).to include(hook)
36
- end
37
-
38
- it "defaults to :each scope if the only argument is a metadata hash" do
39
- hooks = instance.send(type, :foo => :bar) {}
40
- hook = hooks.first
41
- expect(instance.hooks[type][:each]).to include(hook)
42
- end
43
-
44
- it "raises an error if only metadata symbols are given as arguments" do
45
- expect { instance.send(type, :foo, :bar) {} }.to raise_error(ArgumentError)
46
- end
47
- end
48
- end
49
-
50
- [:before, :after].each do |type|
51
- [:each, :all, :suite].each do |scope|
52
- describe "##{type}(#{scope.inspect})" do
53
- let(:instance) { HooksHost.new }
54
- let!(:hook) do
55
- hooks = instance.send(type, scope) {}
56
- hooks.first
57
- end
58
-
59
- it "does not make #{scope.inspect} a metadata key" do
60
- expect(hook.options).to be_empty
61
- end
62
-
63
- it "is scoped to #{scope.inspect}" do
64
- expect(instance.hooks[type][scope]).to include(hook)
65
- end
66
-
67
- it 'does not run when in dry run mode' do
68
- RSpec.configuration.dry_run = true
69
-
70
- expect { |b|
71
- instance.send(type, scope, &b)
72
- instance.hooks.run(type, scope)
73
- }.not_to yield_control
74
- end
75
- end
76
- end
77
- end
78
-
79
- describe "#around" do
80
- context "when not running the example within the around block" do
81
- it "does not run the example" do
82
- examples = []
83
- group = ExampleGroup.describe do
84
- around do
85
- end
86
- it "foo" do
87
- examples << self
88
- end
89
- end
90
- group.run
91
- expect(examples).to eq([])
92
- end
93
- end
94
-
95
- context "when running the example within the around block" do
96
- it "runs the example" do
97
- examples = []
98
- group = ExampleGroup.describe do
99
- around do |example|
100
- example.run
101
- end
102
- it "foo" do
103
- examples << self
104
- end
105
- end
106
- group.run
107
- expect(examples.count).to eq(1)
108
- end
109
-
110
- it "exposes example metadata to each around hook" do
111
- foos = {}
112
- group = ExampleGroup.describe do
113
- around do |ex|
114
- foos[:first] = ex.metadata[:foo]
115
- ex.run
116
- end
117
- around do |ex|
118
- foos[:second] = ex.metadata[:foo]
119
- ex.run
120
- end
121
- it "does something", :foo => :bar do
122
- end
123
- end
124
-
125
- group.run
126
- expect(foos).to eq({:first => :bar, :second => :bar})
127
- end
128
- end
129
-
130
- context "when running the example within a block passed to a method" do
131
- it "runs the example" do
132
- examples = []
133
- group = ExampleGroup.describe do
134
- def yielder
135
- yield
136
- end
137
-
138
- around do |example|
139
- yielder { example.run }
140
- end
141
-
142
- it "foo" do
143
- examples << self
144
- end
145
- end
146
- group.run
147
- expect(examples.count).to eq(1)
148
- end
149
- end
150
- end
151
-
152
- [:all, :each].each do |scope|
153
- describe "prepend_before(#{scope})" do
154
- it "adds to the front of the list of before(:#{scope}) hooks" do
155
- messages = []
156
-
157
- RSpec.configure { |config| config.before(scope) { messages << "config 3" } }
158
- RSpec.configure { |config| config.prepend_before(scope) { messages << "config 2" } }
159
- RSpec.configure { |config| config.before(scope) { messages << "config 4" } }
160
- RSpec.configure { |config| config.prepend_before(scope) { messages << "config 1" } }
161
-
162
- group = ExampleGroup.describe { example {} }
163
- group.before(scope) { messages << "group 3" }
164
- group.prepend_before(scope) { messages << "group 2" }
165
- group.before(scope) { messages << "group 4" }
166
- group.prepend_before(scope) { messages << "group 1" }
167
-
168
- group.run
169
-
170
- expect(messages).to eq([
171
- 'group 1',
172
- 'group 2',
173
- 'config 1',
174
- 'config 2',
175
- 'config 3',
176
- 'config 4',
177
- 'group 3',
178
- 'group 4'
179
- ])
180
- end
181
- end
182
-
183
- describe "append_before(#{scope})" do
184
- it "adds to the back of the list of before(:#{scope}) hooks (same as `before`)" do
185
- messages = []
186
-
187
- RSpec.configure { |config| config.before(scope) { messages << "config 1" } }
188
- RSpec.configure { |config| config.append_before(scope) { messages << "config 2" } }
189
- RSpec.configure { |config| config.before(scope) { messages << "config 3" } }
190
-
191
- group = ExampleGroup.describe { example {} }
192
- group.before(scope) { messages << "group 1" }
193
- group.append_before(scope) { messages << "group 2" }
194
- group.before(scope) { messages << "group 3" }
195
-
196
- group.run
197
-
198
- expect(messages).to eq([
199
- 'config 1',
200
- 'config 2',
201
- 'config 3',
202
- 'group 1',
203
- 'group 2',
204
- 'group 3'
205
- ])
206
- end
207
- end
208
-
209
- describe "prepend_after(#{scope})" do
210
- it "adds to the front of the list of after(:#{scope}) hooks (same as `after`)" do
211
- messages = []
212
-
213
- RSpec.configure { |config| config.after(scope) { messages << "config 3" } }
214
- RSpec.configure { |config| config.prepend_after(scope) { messages << "config 2" } }
215
- RSpec.configure { |config| config.after(scope) { messages << "config 1" } }
216
-
217
- group = ExampleGroup.describe { example {} }
218
- group.after(scope) { messages << "group 3" }
219
- group.prepend_after(scope) { messages << "group 2" }
220
- group.after(scope) { messages << "group 1" }
221
-
222
- group.run
223
-
224
- expect(messages).to eq([
225
- 'group 1',
226
- 'group 2',
227
- 'group 3',
228
- 'config 1',
229
- 'config 2',
230
- 'config 3'
231
- ])
232
- end
233
- end
234
-
235
- describe "append_after(#{scope})" do
236
- it "adds to the back of the list of after(:#{scope}) hooks" do
237
- messages = []
238
-
239
- RSpec.configure { |config| config.after(scope) { messages << "config 2" } }
240
- RSpec.configure { |config| config.append_after(scope) { messages << "config 3" } }
241
- RSpec.configure { |config| config.after(scope) { messages << "config 1" } }
242
- RSpec.configure { |config| config.append_after(scope) { messages << "config 4" } }
243
-
244
- group = ExampleGroup.describe { example {} }
245
- group.after(scope) { messages << "group 2" }
246
- group.append_after(scope) { messages << "group 3" }
247
- group.after(scope) { messages << "group 1" }
248
- group.append_after(scope) { messages << "group 4" }
249
-
250
- group.run
251
-
252
- expect(messages).to eq([
253
- 'group 1',
254
- 'group 2',
255
- 'config 1',
256
- 'config 2',
257
- 'config 3',
258
- 'config 4',
259
- 'group 3',
260
- 'group 4'
261
- ])
262
- end
263
- end
264
- end
265
-
266
- describe "lambda" do
267
- it "can be used as a hook" do
268
- messages = []
269
- count = 0
270
- hook = lambda {|e| messages << "hook #{count = count + 1}"; e.run }
271
-
272
- RSpec.configure do |c|
273
- c.around(:each, &hook)
274
- c.around(:each, &hook)
275
- end
276
-
277
- group = ExampleGroup.describe { example { messages << "example" } }
278
- group.run
279
- expect(messages).to eq ["hook 1", "hook 2", "example"]
280
- end
281
- end
282
-
283
- it "only defines methods that are intended to be part of RSpec's public API (+ `hooks`)" do
284
- expect(Hooks.private_instance_methods).to eq([])
285
-
286
- expect(Hooks.instance_methods.map(&:to_sym)).to match_array([
287
- :before, :after, :around,
288
- :append_before, :append_after,
289
- :prepend_before, :prepend_after,
290
- :hooks
291
- ])
292
- end
293
- end
294
- end