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,514 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Core
5
- describe Metadata do
6
-
7
- describe '.relative_path' do
8
- let(:here) { File.expand_path(".") }
9
- it "transforms absolute paths to relative paths" do
10
- expect(Metadata.relative_path(here)).to eq "."
11
- end
12
- it "transforms absolute paths to relative paths anywhere in its argument" do
13
- expect(Metadata.relative_path("foo #{here} bar")).to eq "foo . bar"
14
- end
15
- it "returns nil if passed an unparseable file:line combo" do
16
- expect(Metadata.relative_path("-e:1")).to be_nil
17
- end
18
- # I have no idea what line = line.sub(/\A([^:]+:\d+)$/, '\\1') is supposed to do
19
- it "gracefully returns nil if run in a secure thread" do
20
- safely do
21
- value = Metadata.relative_path(".")
22
- # on some rubies, File.expand_path is not a security error, so accept "." as well
23
- expect([nil, "."]).to include(value)
24
- end
25
- end
26
-
27
- end
28
-
29
- describe "#process" do
30
- Metadata::RESERVED_KEYS.each do |key|
31
- it "prohibits :#{key} as a hash key" do
32
- m = Metadata.new
33
- expect do
34
- m.process('group', key => {})
35
- end.to raise_error(/:#{key} is not allowed/)
36
- end
37
- end
38
-
39
- it "uses :caller if passed as part of the user metadata" do
40
- m = Metadata.new
41
- m.process('group', :caller => ['example_file:42'])
42
- expect(m[:example_group][:location]).to eq("example_file:42")
43
- end
44
- end
45
-
46
- describe "#filter_applies?" do
47
- let(:parent_group_metadata) { Metadata.new.process('parent group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
48
- let(:group_metadata) { Metadata.new(parent_group_metadata).process('group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
49
- let(:example_metadata) { group_metadata.for_example('example', :caller => ["foo_spec.rb:#{__LINE__}"], :if => true) }
50
- let(:next_example_metadata) { group_metadata.for_example('next_example', :caller => ["foo_spec.rb:#{example_line_number + 2}"]) }
51
- let(:world) { World.new }
52
-
53
- before { RSpec.stub(:world) { world } }
54
-
55
- shared_examples_for "matching by line number" do
56
- let(:preceeding_declaration_lines) {{
57
- parent_group_metadata[:example_group][:line_number] => parent_group_metadata[:example_group][:line_number],
58
- group_metadata[:example_group][:line_number] => group_metadata[:example_group][:line_number],
59
- example_metadata[:line_number] => example_metadata[:line_number],
60
- (example_metadata[:line_number] + 1) => example_metadata[:line_number],
61
- (example_metadata[:line_number] + 2) => example_metadata[:line_number] + 2,
62
- }}
63
- before do
64
- world.should_receive(:preceding_declaration_line).at_least(:once).and_return do |v|
65
- preceeding_declaration_lines[v]
66
- end
67
- end
68
-
69
- it "matches the group when the line_number is the example group line number" do
70
- # this call doesn't really make sense since filter_applies? is only called
71
- # for example metadata not group metadata
72
- expect(group_metadata.filter_applies?(condition_key, group_condition)).to be_truthy
73
- end
74
-
75
- it "matches the example when the line_number is the grandparent example group line number" do
76
- expect(example_metadata.filter_applies?(condition_key, parent_group_condition)).to be_truthy
77
- end
78
-
79
- it "matches the example when the line_number is the parent example group line number" do
80
- expect(example_metadata.filter_applies?(condition_key, group_condition)).to be_truthy
81
- end
82
-
83
- it "matches the example when the line_number is the example line number" do
84
- expect(example_metadata.filter_applies?(condition_key, example_condition)).to be_truthy
85
- end
86
-
87
- it "matches when the line number is between this example and the next" do
88
- expect(example_metadata.filter_applies?(condition_key, between_examples_condition)).to be_truthy
89
- end
90
-
91
- it "does not match when the line number matches the next example" do
92
- expect(example_metadata.filter_applies?(condition_key, next_example_condition)).to be_falsey
93
- end
94
- end
95
-
96
- context "with a single line number" do
97
- let(:condition_key){ :line_numbers }
98
- let(:parent_group_condition) { [parent_group_metadata[:example_group][:line_number]] }
99
- let(:group_condition) { [group_metadata[:example_group][:line_number]] }
100
- let(:example_condition) { [example_metadata[:line_number]] }
101
- let(:between_examples_condition) { [group_metadata[:example_group][:line_number] + 1] }
102
- let(:next_example_condition) { [example_metadata[:line_number] + 2] }
103
-
104
- it_has_behavior "matching by line number"
105
- end
106
-
107
- context "with multiple line numbers" do
108
- let(:condition_key){ :line_numbers }
109
- let(:parent_group_condition) { [-1, parent_group_metadata[:example_group][:line_number]] }
110
- let(:group_condition) { [-1, group_metadata[:example_group][:line_number]] }
111
- let(:example_condition) { [-1, example_metadata[:line_number]] }
112
- let(:between_examples_condition) { [-1, group_metadata[:example_group][:line_number] + 1] }
113
- let(:next_example_condition) { [-1, example_metadata[:line_number] + 2] }
114
-
115
- it_has_behavior "matching by line number"
116
- end
117
-
118
- context "with a :line_numbers filter" do
119
- before(:each) { Metadata.line_number_filter_deprecation_issued = false }
120
- after(:all) { Metadata.line_number_filter_deprecation_issued = false }
121
- let(:metadata) { Metadata.new.process("group") }
122
-
123
- context "when a line number filter is applied manually (e.g. not from the command line)" do
124
- it 'issues a deprecation warning' do
125
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /:line_numbers/)
126
- metadata.filter_applies?(:line_numbers, [2])
127
- end
128
- end
129
-
130
- context "when a line number filter is applied from the command line" do
131
- it "does not issue an additional deprecation" do
132
- allow_deprecation
133
- Parser.parse!(["--line-number", "3"])
134
-
135
- expect_no_deprecation
136
- metadata.filter_applies?(:line_numbers, [2])
137
- end
138
- end
139
- end
140
-
141
- context "with locations" do
142
- let(:condition_key){ :locations }
143
- let(:parent_group_condition) do
144
- {File.expand_path(parent_group_metadata[:example_group][:file_path]) => [parent_group_metadata[:example_group][:line_number]]}
145
- end
146
- let(:group_condition) do
147
- {File.expand_path(group_metadata[:example_group][:file_path]) => [group_metadata[:example_group][:line_number]]}
148
- end
149
- let(:example_condition) do
150
- {File.expand_path(example_metadata[:file_path]) => [example_metadata[:line_number]]}
151
- end
152
- let(:between_examples_condition) do
153
- {File.expand_path(group_metadata[:example_group][:file_path]) => [group_metadata[:example_group][:line_number] + 1]}
154
- end
155
- let(:next_example_condition) do
156
- {File.expand_path(example_metadata[:file_path]) => [example_metadata[:line_number] + 2]}
157
- end
158
-
159
- it_has_behavior "matching by line number"
160
-
161
- it "ignores location filters for other files" do
162
- expect(example_metadata.filter_applies?(:locations, {"/path/to/other_spec.rb" => [3,5,7]})).to be_truthy
163
- end
164
- end
165
-
166
- it "matches a proc with no arguments that evaluates to true" do
167
- expect(example_metadata.filter_applies?(:if, lambda { true })).to be_truthy
168
- end
169
-
170
- it "matches a proc that evaluates to true" do
171
- expect(example_metadata.filter_applies?(:if, lambda { |v| v })).to be_truthy
172
- end
173
-
174
- it "does not match a proc that evaluates to false" do
175
- expect(example_metadata.filter_applies?(:if, lambda { |v| !v })).to be_falsey
176
- end
177
-
178
- it "matches a proc with an arity of 2" do
179
- example_metadata[:foo] = nil
180
- expect(example_metadata.filter_applies?(:foo, lambda { |v, m| m == example_metadata })).to be_truthy
181
- end
182
-
183
- it "raises an error when the proc has an incorrect arity" do
184
- expect {
185
- example_metadata.filter_applies?(:if, lambda { |a,b,c| true })
186
- }.to raise_error(ArgumentError)
187
- end
188
-
189
- context "with an Array" do
190
- let(:metadata_with_array) {
191
- group_metadata.for_example('example_with_array', :tag => [:one, 2, 'three', /four/])
192
- }
193
-
194
- it "matches a symbol" do
195
- expect(metadata_with_array.filter_applies?(:tag, 'one')).to be_truthy
196
- expect(metadata_with_array.filter_applies?(:tag, :one)).to be_truthy
197
- expect(metadata_with_array.filter_applies?(:tag, 'two')).to be_falsey
198
- end
199
-
200
- it "matches a string" do
201
- expect(metadata_with_array.filter_applies?(:tag, 'three')).to be_truthy
202
- expect(metadata_with_array.filter_applies?(:tag, :three)).to be_truthy
203
- expect(metadata_with_array.filter_applies?(:tag, 'tree')).to be_falsey
204
- end
205
-
206
- it "matches an integer" do
207
- expect(metadata_with_array.filter_applies?(:tag, '2')).to be_truthy
208
- expect(metadata_with_array.filter_applies?(:tag, 2)).to be_truthy
209
- expect(metadata_with_array.filter_applies?(:tag, 3)).to be_falsey
210
- end
211
-
212
- it "matches a regexp" do
213
- expect(metadata_with_array.filter_applies?(:tag, 'four')).to be_truthy
214
- expect(metadata_with_array.filter_applies?(:tag, 'fourtune')).to be_truthy
215
- expect(metadata_with_array.filter_applies?(:tag, 'fortune')).to be_falsey
216
- end
217
-
218
- it "matches a proc that evaluates to true" do
219
- expect(metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'three' })).to be_truthy
220
- end
221
-
222
- it "does not match a proc that evaluates to false" do
223
- expect(metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'nothing' })).to be_falsey
224
- end
225
- end
226
- end
227
-
228
- describe "#for_example" do
229
- let(:metadata) { Metadata.new.process("group description") }
230
- let(:mfe) { metadata.for_example("example description", {:arbitrary => :options}) }
231
- let(:line_number) { __LINE__ - 1 }
232
-
233
- it "stores the description args" do
234
- expect(mfe.fetch(:description_args)).to eq ["example description"]
235
- expect(mfe[:description_args]).to eq ["example description"]
236
- end
237
-
238
- it "ignores nil description args" do
239
- expect(metadata.for_example(nil, {}).fetch(:description_args)).to eq []
240
- expect(metadata.for_example(nil, {})[:description_args]).to eq []
241
- end
242
-
243
- it "stores the full_description (group description + example description)" do
244
- expect(mfe.fetch(:full_description)).to eq("group description example description")
245
- expect(mfe[:full_description]).to eq("group description example description")
246
- end
247
-
248
- it "creates an empty execution result" do
249
- expect(mfe.fetch(:execution_result)).to eq({})
250
- expect(mfe[:execution_result]).to eq({})
251
- end
252
-
253
- it "extracts file path from caller" do
254
- expect(mfe.fetch(:file_path)).to eq(relative_path(__FILE__))
255
- expect(mfe[:file_path]).to eq(relative_path(__FILE__))
256
- end
257
-
258
- it "extracts line number from caller" do
259
- expect(mfe.fetch(:line_number)).to eq(line_number)
260
- expect(mfe[:line_number]).to eq(line_number)
261
- end
262
-
263
- it "extracts location from caller" do
264
- expect(mfe.fetch(:location)).to eq("#{relative_path(__FILE__)}:#{line_number}")
265
- expect(mfe[:location]).to eq("#{relative_path(__FILE__)}:#{line_number}")
266
- end
267
-
268
- it "uses :caller if passed as an option" do
269
- example_metadata = metadata.for_example('example description', {:caller => ['example_file:42']})
270
- expect(example_metadata[:location]).to eq("example_file:42")
271
- end
272
-
273
- it "merges arbitrary options" do
274
- expect(mfe.fetch(:arbitrary)).to eq(:options)
275
- expect(mfe[:arbitrary]).to eq(:options)
276
- end
277
-
278
- it "points :example_group to the same hash object" do
279
- a = metadata.for_example("foo", {})[:example_group]
280
- b = metadata.for_example("bar", {})[:example_group]
281
- a[:description] = "new description"
282
- expect(b[:description]).to eq("new description")
283
- end
284
- end
285
-
286
- [:described_class, :describes].each do |key|
287
- describe key.inspect do
288
- context "with a String" do
289
- it "returns nil" do
290
- m = Metadata.new
291
- m.process('group')
292
-
293
- expect(m[:example_group][key]).to be_nil
294
- end
295
- end
296
-
297
- context "with a Symbol" do
298
- it "returns nil" do
299
- m = Metadata.new
300
- m.process(:group)
301
-
302
- expect(m[:example_group][key]).to be_nil
303
- end
304
- end
305
-
306
- context "with a class" do
307
- it "returns the class" do
308
- m = Metadata.new
309
- m.process(String)
310
-
311
- expect(m[:example_group][key]).to be(String)
312
- end
313
- end
314
-
315
- context "in a nested group" do
316
- it "returns the parent group's described class" do
317
- sm = Metadata.new
318
- sm.process(String)
319
-
320
- m = Metadata.new(sm)
321
- m.process(Array)
322
-
323
- expect(m[:example_group][key]).to be(String)
324
- end
325
-
326
- it "returns own described class if parent doesn't have one" do
327
- sm = Metadata.new
328
- sm.process("foo")
329
-
330
- m = Metadata.new(sm)
331
- m.process(Array)
332
-
333
- expect(m[:example_group][key]).to be(Array)
334
- end
335
-
336
- it "can override a parent group's described class" do
337
- parent = Metadata.new
338
- parent.process(String)
339
-
340
- child = Metadata.new(parent)
341
- child.process(Fixnum)
342
- child[:example_group][key] = Hash
343
-
344
- grandchild = Metadata.new(child)
345
- grandchild.process(Array)
346
-
347
- expect(grandchild[:example_group][key]).to be(Hash)
348
- expect(child[:example_group][key]).to be(Hash)
349
- expect(parent[:example_group][key]).to be(String)
350
- end
351
- end
352
- end
353
- end
354
-
355
- describe ":description" do
356
- it "just has the example description" do
357
- m = Metadata.new
358
- m.process("group")
359
-
360
- m = m.for_example("example", {})
361
- expect(m[:description]).to eq("example")
362
- end
363
-
364
- context "with a string" do
365
- it "provides the submitted description" do
366
- m = Metadata.new
367
- m.process("group")
368
-
369
- expect(m[:example_group][:description]).to eq("group")
370
- end
371
- end
372
-
373
- context "with a non-string" do
374
- it "provides the submitted description" do
375
- m = Metadata.new
376
- m.process("group")
377
-
378
- expect(m[:example_group][:description]).to eq("group")
379
- end
380
- end
381
-
382
- context "with a non-string and a string" do
383
- it "concats the args" do
384
- m = Metadata.new
385
- m.process(Object, 'group')
386
-
387
- expect(m[:example_group][:description]).to eq("Object group")
388
- end
389
- end
390
-
391
- context "with empty args" do
392
- it "returns empty string for [:example_group][:description]" do
393
- m = Metadata.new
394
- m.process()
395
-
396
- expect(m[:example_group][:description]).to eq("")
397
- end
398
- end
399
- end
400
-
401
- describe ":full_description" do
402
- it "concats example group name and description" do
403
- group_metadata = Metadata.new
404
- group_metadata.process('group')
405
-
406
- example_metadata = group_metadata.for_example("example", {})
407
- expect(example_metadata[:full_description]).to eq("group example")
408
- end
409
-
410
- it "concats nested example group descriptions" do
411
- parent = Metadata.new
412
- parent.process('parent')
413
-
414
- child = Metadata.new(parent)
415
- child.process('child')
416
-
417
- expect(child[:example_group][:full_description]).to eq("parent child")
418
- expect(child.for_example('example', child)[:full_description]).to eq("parent child example")
419
- end
420
-
421
- it "concats nested example group descriptions three deep" do
422
- grandparent = Metadata.new
423
- grandparent.process('grandparent')
424
-
425
- parent = Metadata.new(grandparent)
426
- parent.process('parent')
427
-
428
- child = Metadata.new(parent)
429
- child.process('child')
430
-
431
- expect(grandparent[:example_group][:full_description]).to eq("grandparent")
432
- expect(parent[:example_group][:full_description]).to eq("grandparent parent")
433
- expect(child[:example_group][:full_description]).to eq("grandparent parent child")
434
- expect(child.for_example('example', child)[:full_description]).to eq("grandparent parent child example")
435
- end
436
-
437
- %w[# . ::].each do |char|
438
- context "with a 2nd arg starting with #{char}" do
439
- it "removes the space" do
440
- m = Metadata.new
441
- m.process(Array, "#{char}method")
442
- expect(m[:example_group][:full_description]).to eq("Array#{char}method")
443
- end
444
- end
445
-
446
- context "with a description starting with #{char} nested under a module" do
447
- it "removes the space" do
448
- parent = Metadata.new
449
- parent.process(Object)
450
- child = Metadata.new(parent)
451
- child.process("#{char}method")
452
- expect(child[:example_group][:full_description]).to eq("Object#{char}method")
453
- end
454
- end
455
-
456
- context "with a description starting with #{char} nested under a context string" do
457
- it "does not remove the space" do
458
- grandparent = Metadata.new
459
- grandparent.process(Array)
460
- parent = Metadata.new(grandparent)
461
- parent.process("with 2 items")
462
- child = Metadata.new(parent)
463
- child.process("#{char}method")
464
- expect(child[:example_group][:full_description]).to eq("Array with 2 items #{char}method")
465
- end
466
- end
467
- end
468
- end
469
-
470
- describe ":file_path" do
471
- it "finds the first non-rspec lib file in the caller array" do
472
- m = Metadata.new
473
- m.process(:caller => [
474
- "./lib/rspec/core/foo.rb",
475
- "#{__FILE__}:#{__LINE__}"
476
- ])
477
- expect(m[:example_group][:file_path]).to eq(relative_path(__FILE__))
478
- end
479
- end
480
-
481
- describe ":line_number" do
482
- it "finds the line number with the first non-rspec lib file in the backtrace" do
483
- m = Metadata.new
484
- m.process({})
485
- expect(m[:example_group][:line_number]).to eq(__LINE__ - 1)
486
- end
487
-
488
- it "finds the line number with the first spec file with drive letter" do
489
- m = Metadata.new
490
- m.process(:caller => [ "C:/path/to/file_spec.rb:#{__LINE__}" ])
491
- expect(m[:example_group][:line_number]).to eq(__LINE__ - 1)
492
- end
493
-
494
- it "uses the number after the first : for ruby 1.9" do
495
- m = Metadata.new
496
- m.process(:caller => [ "#{__FILE__}:#{__LINE__}:999" ])
497
- expect(m[:example_group][:line_number]).to eq(__LINE__ - 1)
498
- end
499
- end
500
-
501
- describe "child example group" do
502
- it "nests the parent's example group metadata" do
503
- parent = Metadata.new
504
- parent.process(Object, 'parent')
505
-
506
- child = Metadata.new(parent)
507
- child.process()
508
-
509
- expect(child[:example_group][:example_group]).to eq(parent[:example_group])
510
- end
511
- end
512
- end
513
- end
514
- end