rspec-core 2.11.1 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +3 -1
  5. data/Changelog.md +1814 -29
  6. data/{License.txt → LICENSE.md} +6 -4
  7. data/README.md +197 -48
  8. data/exe/rspec +2 -23
  9. data/lib/rspec/autorun.rb +1 -0
  10. data/lib/rspec/core/backtrace_formatter.rb +65 -0
  11. data/lib/rspec/core/bisect/coordinator.rb +62 -0
  12. data/lib/rspec/core/bisect/example_minimizer.rb +173 -0
  13. data/lib/rspec/core/bisect/fork_runner.rb +138 -0
  14. data/lib/rspec/core/bisect/server.rb +61 -0
  15. data/lib/rspec/core/bisect/shell_command.rb +126 -0
  16. data/lib/rspec/core/bisect/shell_runner.rb +73 -0
  17. data/lib/rspec/core/bisect/utilities.rb +69 -0
  18. data/lib/rspec/core/configuration.rb +1846 -407
  19. data/lib/rspec/core/configuration_options.rb +154 -50
  20. data/lib/rspec/core/did_you_mean.rb +46 -0
  21. data/lib/rspec/core/drb.rb +120 -0
  22. data/lib/rspec/core/dsl.rb +90 -18
  23. data/lib/rspec/core/example.rb +488 -152
  24. data/lib/rspec/core/example_group.rb +733 -294
  25. data/lib/rspec/core/example_status_persister.rb +235 -0
  26. data/lib/rspec/core/filter_manager.rb +175 -147
  27. data/lib/rspec/core/flat_map.rb +20 -0
  28. data/lib/rspec/core/formatters/base_bisect_formatter.rb +45 -0
  29. data/lib/rspec/core/formatters/base_formatter.rb +32 -130
  30. data/lib/rspec/core/formatters/base_text_formatter.rb +62 -190
  31. data/lib/rspec/core/formatters/bisect_drb_formatter.rb +29 -0
  32. data/lib/rspec/core/formatters/bisect_progress_formatter.rb +157 -0
  33. data/lib/rspec/core/formatters/console_codes.rb +76 -0
  34. data/lib/rspec/core/formatters/deprecation_formatter.rb +223 -0
  35. data/lib/rspec/core/formatters/documentation_formatter.rb +62 -27
  36. data/lib/rspec/core/formatters/exception_presenter.rb +521 -0
  37. data/lib/rspec/core/formatters/failure_list_formatter.rb +23 -0
  38. data/lib/rspec/core/formatters/fallback_message_formatter.rb +28 -0
  39. data/lib/rspec/core/formatters/helpers.rb +93 -14
  40. data/lib/rspec/core/formatters/html_formatter.rb +104 -415
  41. data/lib/rspec/core/formatters/html_printer.rb +414 -0
  42. data/lib/rspec/core/formatters/html_snippet_extractor.rb +120 -0
  43. data/lib/rspec/core/formatters/json_formatter.rb +102 -0
  44. data/lib/rspec/core/formatters/profile_formatter.rb +68 -0
  45. data/lib/rspec/core/formatters/progress_formatter.rb +12 -15
  46. data/lib/rspec/core/formatters/protocol.rb +182 -0
  47. data/lib/rspec/core/formatters/snippet_extractor.rb +115 -39
  48. data/lib/rspec/core/formatters/syntax_highlighter.rb +91 -0
  49. data/lib/rspec/core/formatters.rb +279 -0
  50. data/lib/rspec/core/hooks.rb +451 -300
  51. data/lib/rspec/core/invocations.rb +87 -0
  52. data/lib/rspec/core/memoized_helpers.rb +580 -0
  53. data/lib/rspec/core/metadata.rb +395 -173
  54. data/lib/rspec/core/metadata_filter.rb +255 -0
  55. data/lib/rspec/core/minitest_assertions_adapter.rb +31 -0
  56. data/lib/rspec/core/mocking_adapters/flexmock.rb +31 -0
  57. data/lib/rspec/core/mocking_adapters/mocha.rb +57 -0
  58. data/lib/rspec/core/mocking_adapters/null.rb +14 -0
  59. data/lib/rspec/core/mocking_adapters/rr.rb +31 -0
  60. data/lib/rspec/core/mocking_adapters/rspec.rb +32 -0
  61. data/lib/rspec/core/notifications.rb +521 -0
  62. data/lib/rspec/core/option_parser.rb +208 -64
  63. data/lib/rspec/core/ordering.rb +169 -0
  64. data/lib/rspec/core/output_wrapper.rb +29 -0
  65. data/lib/rspec/core/pending.rb +115 -59
  66. data/lib/rspec/core/profiler.rb +34 -0
  67. data/lib/rspec/core/project_initializer/.rspec +1 -0
  68. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +98 -0
  69. data/lib/rspec/core/project_initializer.rb +26 -65
  70. data/lib/rspec/core/rake_task.rb +140 -131
  71. data/lib/rspec/core/reporter.rb +207 -44
  72. data/lib/rspec/core/ruby_project.rb +15 -6
  73. data/lib/rspec/core/runner.rb +180 -44
  74. data/lib/rspec/core/sandbox.rb +37 -0
  75. data/lib/rspec/core/set.rb +54 -0
  76. data/lib/rspec/core/shared_context.rb +25 -19
  77. data/lib/rspec/core/shared_example_group.rb +229 -54
  78. data/lib/rspec/core/shell_escape.rb +49 -0
  79. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  80. data/lib/rspec/core/version.rb +3 -1
  81. data/lib/rspec/core/warnings.rb +40 -0
  82. data/lib/rspec/core/world.rb +208 -49
  83. data/lib/rspec/core.rb +166 -80
  84. data.tar.gz.sig +0 -0
  85. metadata +230 -445
  86. metadata.gz.sig +0 -0
  87. data/exe/autospec +0 -13
  88. data/features/Autotest.md +0 -38
  89. data/features/README.md +0 -17
  90. data/features/Upgrade.md +0 -364
  91. data/features/command_line/README.md +0 -28
  92. data/features/command_line/example_name_option.feature +0 -101
  93. data/features/command_line/exit_status.feature +0 -83
  94. data/features/command_line/format_option.feature +0 -81
  95. data/features/command_line/init.feature +0 -18
  96. data/features/command_line/line_number_appended_to_path.feature +0 -140
  97. data/features/command_line/line_number_option.feature +0 -58
  98. data/features/command_line/order.feature +0 -29
  99. data/features/command_line/pattern_option.feature +0 -31
  100. data/features/command_line/rake_task.feature +0 -68
  101. data/features/command_line/ruby.feature +0 -22
  102. data/features/command_line/tag.feature +0 -91
  103. data/features/configuration/alias_example_to.feature +0 -48
  104. data/features/configuration/custom_settings.feature +0 -84
  105. data/features/configuration/default_path.feature +0 -38
  106. data/features/configuration/fail_fast.feature +0 -77
  107. data/features/configuration/read_options_from_file.feature +0 -87
  108. data/features/example_groups/basic_structure.feature +0 -55
  109. data/features/example_groups/shared_context.feature +0 -74
  110. data/features/example_groups/shared_examples.feature +0 -204
  111. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
  112. data/features/filtering/exclusion_filters.feature +0 -139
  113. data/features/filtering/if_and_unless.feature +0 -168
  114. data/features/filtering/inclusion_filters.feature +0 -105
  115. data/features/filtering/run_all_when_everything_filtered.feature +0 -46
  116. data/features/formatters/custom_formatter.feature +0 -36
  117. data/features/formatters/text_formatter.feature +0 -46
  118. data/features/helper_methods/arbitrary_methods.feature +0 -40
  119. data/features/helper_methods/let.feature +0 -50
  120. data/features/helper_methods/modules.feature +0 -149
  121. data/features/hooks/around_hooks.feature +0 -343
  122. data/features/hooks/before_and_after_hooks.feature +0 -423
  123. data/features/hooks/filtering.feature +0 -234
  124. data/features/metadata/current_example.feature +0 -17
  125. data/features/metadata/described_class.feature +0 -17
  126. data/features/metadata/user_defined.feature +0 -113
  127. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  128. data/features/mock_framework_integration/use_flexmock.feature +0 -96
  129. data/features/mock_framework_integration/use_mocha.feature +0 -97
  130. data/features/mock_framework_integration/use_rr.feature +0 -98
  131. data/features/mock_framework_integration/use_rspec.feature +0 -97
  132. data/features/pending/pending_examples.feature +0 -229
  133. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  134. data/features/step_definitions/additional_cli_steps.rb +0 -30
  135. data/features/subject/attribute_of_subject.feature +0 -124
  136. data/features/subject/explicit_subject.feature +0 -82
  137. data/features/subject/implicit_receiver.feature +0 -29
  138. data/features/subject/implicit_subject.feature +0 -63
  139. data/features/support/env.rb +0 -12
  140. data/lib/autotest/discover.rb +0 -1
  141. data/lib/autotest/rspec2.rb +0 -73
  142. data/lib/rspec/core/backward_compatibility.rb +0 -65
  143. data/lib/rspec/core/command_line.rb +0 -36
  144. data/lib/rspec/core/deprecation.rb +0 -36
  145. data/lib/rspec/core/drb_command_line.rb +0 -26
  146. data/lib/rspec/core/drb_options.rb +0 -87
  147. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  148. data/lib/rspec/core/extensions/kernel.rb +0 -9
  149. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  150. data/lib/rspec/core/extensions/ordered.rb +0 -21
  151. data/lib/rspec/core/extensions.rb +0 -4
  152. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  153. data/lib/rspec/core/let.rb +0 -110
  154. data/lib/rspec/core/load_path.rb +0 -3
  155. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  156. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  157. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  158. data/lib/rspec/core/mocking/with_mocha.rb +0 -29
  159. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  160. data/lib/rspec/core/mocking/with_rspec.rb +0 -23
  161. data/lib/rspec/core/subject.rb +0 -219
  162. data/spec/autotest/discover_spec.rb +0 -19
  163. data/spec/autotest/failed_results_re_spec.rb +0 -45
  164. data/spec/autotest/rspec_spec.rb +0 -123
  165. data/spec/command_line/order_spec.rb +0 -137
  166. data/spec/rspec/core/command_line_spec.rb +0 -108
  167. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  168. data/spec/rspec/core/configuration_options_spec.rb +0 -377
  169. data/spec/rspec/core/configuration_spec.rb +0 -1196
  170. data/spec/rspec/core/deprecations_spec.rb +0 -66
  171. data/spec/rspec/core/drb_command_line_spec.rb +0 -108
  172. data/spec/rspec/core/drb_options_spec.rb +0 -180
  173. data/spec/rspec/core/dsl_spec.rb +0 -17
  174. data/spec/rspec/core/example_group_spec.rb +0 -1098
  175. data/spec/rspec/core/example_spec.rb +0 -370
  176. data/spec/rspec/core/filter_manager_spec.rb +0 -256
  177. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -80
  178. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -363
  179. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -88
  180. data/spec/rspec/core/formatters/helpers_spec.rb +0 -66
  181. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +0 -410
  182. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +0 -409
  183. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -416
  184. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -416
  185. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -82
  186. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
  187. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -18
  188. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +0 -410
  189. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +0 -409
  190. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +0 -416
  191. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +0 -416
  192. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -83
  193. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  194. data/spec/rspec/core/hooks_spec.rb +0 -250
  195. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  196. data/spec/rspec/core/let_spec.rb +0 -55
  197. data/spec/rspec/core/metadata_spec.rb +0 -447
  198. data/spec/rspec/core/option_parser_spec.rb +0 -166
  199. data/spec/rspec/core/pending_example_spec.rb +0 -220
  200. data/spec/rspec/core/project_initializer_spec.rb +0 -130
  201. data/spec/rspec/core/rake_task_spec.rb +0 -138
  202. data/spec/rspec/core/reporter_spec.rb +0 -103
  203. data/spec/rspec/core/resources/a_bar.rb +0 -0
  204. data/spec/rspec/core/resources/a_foo.rb +0 -0
  205. data/spec/rspec/core/resources/a_spec.rb +0 -1
  206. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  207. data/spec/rspec/core/resources/formatter_specs.rb +0 -60
  208. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  209. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  210. data/spec/rspec/core/ruby_project_spec.rb +0 -24
  211. data/spec/rspec/core/runner_spec.rb +0 -81
  212. data/spec/rspec/core/shared_context_spec.rb +0 -67
  213. data/spec/rspec/core/shared_example_group_spec.rb +0 -84
  214. data/spec/rspec/core/subject_spec.rb +0 -244
  215. data/spec/rspec/core/world_spec.rb +0 -144
  216. data/spec/rspec/core_spec.rb +0 -35
  217. data/spec/spec_helper.rb +0 -98
  218. data/spec/support/config_options_helper.rb +0 -24
  219. data/spec/support/helper_methods.rb +0 -5
  220. data/spec/support/matchers.rb +0 -65
  221. data/spec/support/shared_example_groups.rb +0 -41
  222. data/spec/support/spec_files.rb +0 -44
@@ -1,447 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module RSpec
4
- module Core
5
- describe Metadata do
6
-
7
- describe "#process" do
8
- Metadata::RESERVED_KEYS.each do |key|
9
- it "prohibits :#{key} as a hash key" do
10
- m = Metadata.new
11
- expect do
12
- m.process('group', key => {})
13
- end.to raise_error(/:#{key} is not allowed/)
14
- end
15
- end
16
-
17
- it "uses :caller if passed as part of the user metadata" do
18
- m = Metadata.new
19
- m.process('group', :caller => ['example_file:42'])
20
- m[:example_group][:location].should eq("example_file:42")
21
- end
22
- end
23
-
24
- describe "#filter_applies?" do
25
- let(:parent_group_metadata) { Metadata.new.process('parent group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
26
- let(:group_metadata) { Metadata.new(parent_group_metadata).process('group', :caller => ["foo_spec.rb:#{__LINE__}"]) }
27
- let(:example_metadata) { group_metadata.for_example('example', :caller => ["foo_spec.rb:#{__LINE__}"], :if => true) }
28
- let(:next_example_metadata) { group_metadata.for_example('next_example', :caller => ["foo_spec.rb:#{example_line_number + 2}"]) }
29
- let(:world) { World.new }
30
-
31
- before { RSpec.stub(:world) { world } }
32
-
33
- shared_examples_for "matching by line number" do
34
- let(:preceeding_declaration_lines) {{
35
- parent_group_metadata[:example_group][:line_number] => parent_group_metadata[:example_group][:line_number],
36
- group_metadata[:example_group][:line_number] => group_metadata[:example_group][:line_number],
37
- example_metadata[:line_number] => example_metadata[:line_number],
38
- (example_metadata[:line_number] + 1) => example_metadata[:line_number],
39
- (example_metadata[:line_number] + 2) => example_metadata[:line_number] + 2,
40
- }}
41
- before do
42
- world.should_receive(:preceding_declaration_line).at_least(:once).and_return do |v|
43
- preceeding_declaration_lines[v]
44
- end
45
- end
46
-
47
- it "matches the group when the line_number is the example group line number" do
48
- # this call doesn't really make sense since filter_applies? is only called
49
- # for example metadata not group metadata
50
- group_metadata.filter_applies?(condition_key, group_condition).should be_true
51
- end
52
-
53
- it "matches the example when the line_number is the grandparent example group line number" do
54
- example_metadata.filter_applies?(condition_key, parent_group_condition).should be_true
55
- end
56
-
57
- it "matches the example when the line_number is the parent example group line number" do
58
- example_metadata.filter_applies?(condition_key, group_condition).should be_true
59
- end
60
-
61
- it "matches the example when the line_number is the example line number" do
62
- example_metadata.filter_applies?(condition_key, example_condition).should be_true
63
- end
64
-
65
- it "matches when the line number is between this example and the next" do
66
- example_metadata.filter_applies?(condition_key, between_examples_condition).should be_true
67
- end
68
-
69
- it "does not match when the line number matches the next example" do
70
- example_metadata.filter_applies?(condition_key, next_example_condition).should be_false
71
- end
72
- end
73
-
74
- context "with a single line number" do
75
- let(:condition_key){ :line_numbers }
76
- let(:parent_group_condition) { [parent_group_metadata[:example_group][:line_number]] }
77
- let(:group_condition) { [group_metadata[:example_group][:line_number]] }
78
- let(:example_condition) { [example_metadata[:line_number]] }
79
- let(:between_examples_condition) { [group_metadata[:example_group][:line_number] + 1] }
80
- let(:next_example_condition) { [example_metadata[:line_number] + 2] }
81
-
82
- it_has_behavior "matching by line number"
83
- end
84
-
85
- context "with multiple line numbers" do
86
- let(:condition_key){ :line_numbers }
87
- let(:parent_group_condition) { [-1, parent_group_metadata[:example_group][:line_number]] }
88
- let(:group_condition) { [-1, group_metadata[:example_group][:line_number]] }
89
- let(:example_condition) { [-1, example_metadata[:line_number]] }
90
- let(:between_examples_condition) { [-1, group_metadata[:example_group][:line_number] + 1] }
91
- let(:next_example_condition) { [-1, example_metadata[:line_number] + 2] }
92
-
93
- it_has_behavior "matching by line number"
94
- end
95
-
96
- context "with locations" do
97
- let(:condition_key){ :locations }
98
- let(:parent_group_condition) do
99
- {File.expand_path(parent_group_metadata[:example_group][:file_path]) => [parent_group_metadata[:example_group][:line_number]]}
100
- end
101
- let(:group_condition) do
102
- {File.expand_path(group_metadata[:example_group][:file_path]) => [group_metadata[:example_group][:line_number]]}
103
- end
104
- let(:example_condition) do
105
- {File.expand_path(example_metadata[:file_path]) => [example_metadata[:line_number]]}
106
- end
107
- let(:between_examples_condition) do
108
- {File.expand_path(group_metadata[:example_group][:file_path]) => [group_metadata[:example_group][:line_number] + 1]}
109
- end
110
- let(:next_example_condition) do
111
- {File.expand_path(example_metadata[:file_path]) => [example_metadata[:line_number] + 2]}
112
- end
113
-
114
- it_has_behavior "matching by line number"
115
-
116
- it "ignores location filters for other files" do
117
- example_metadata.filter_applies?(:locations, {"/path/to/other_spec.rb" => [3,5,7]}).should be_true
118
- end
119
- end
120
-
121
- it "matches a proc with no arguments that evaluates to true" do
122
- example_metadata.filter_applies?(:if, lambda { true }).should be_true
123
- end
124
-
125
- it "matches a proc that evaluates to true" do
126
- example_metadata.filter_applies?(:if, lambda { |v| v }).should be_true
127
- end
128
-
129
- it "does not match a proc that evaluates to false" do
130
- example_metadata.filter_applies?(:if, lambda { |v| !v }).should be_false
131
- end
132
-
133
- it "matches a proc with an arity of 2" do
134
- example_metadata[:foo] = nil
135
- example_metadata.filter_applies?(:foo, lambda { |v, m| m == example_metadata }).should be_true
136
- end
137
-
138
- it "raises an error when the proc has an incorrect arity" do
139
- expect {
140
- example_metadata.filter_applies?(:if, lambda { |a,b,c| true })
141
- }.to raise_error(ArgumentError)
142
- end
143
-
144
- context "with an Array" do
145
- let(:metadata_with_array) {
146
- group_metadata.for_example('example_with_array', :tag => [:one, 2, 'three', /four/])
147
- }
148
-
149
- it "matches a symbol" do
150
- metadata_with_array.filter_applies?(:tag, 'one').should be_true
151
- metadata_with_array.filter_applies?(:tag, :one).should be_true
152
- metadata_with_array.filter_applies?(:tag, 'two').should be_false
153
- end
154
-
155
- it "matches a string" do
156
- metadata_with_array.filter_applies?(:tag, 'three').should be_true
157
- metadata_with_array.filter_applies?(:tag, :three).should be_true
158
- metadata_with_array.filter_applies?(:tag, 'tree').should be_false
159
- end
160
-
161
- it "matches an integer" do
162
- metadata_with_array.filter_applies?(:tag, '2').should be_true
163
- metadata_with_array.filter_applies?(:tag, 2).should be_true
164
- metadata_with_array.filter_applies?(:tag, 3).should be_false
165
- end
166
-
167
- it "matches a regexp" do
168
- metadata_with_array.filter_applies?(:tag, 'four').should be_true
169
- metadata_with_array.filter_applies?(:tag, 'fourtune').should be_true
170
- metadata_with_array.filter_applies?(:tag, 'fortune').should be_false
171
- end
172
-
173
- it "matches a proc that evaluates to true" do
174
- metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'three' }).should be_true
175
- end
176
-
177
- it "does not match a proc that evaluates to false" do
178
- metadata_with_array.filter_applies?(:tag, lambda { |values| values.include? 'nothing' }).should be_false
179
- end
180
- end
181
- end
182
-
183
- describe "#for_example" do
184
- let(:metadata) { Metadata.new.process("group description") }
185
- let(:mfe) { metadata.for_example("example description", {:arbitrary => :options}) }
186
- let(:line_number) { __LINE__ - 1 }
187
-
188
- it "stores the description" do
189
- mfe[:description].should eq("example description")
190
- end
191
-
192
- it "stores the full_description (group description + example description)" do
193
- mfe[:full_description].should eq("group description example description")
194
- end
195
-
196
- it "creates an empty execution result" do
197
- mfe[:execution_result].should eq({})
198
- end
199
-
200
- it "extracts file path from caller" do
201
- mfe[:file_path].should eq(relative_path(__FILE__))
202
- end
203
-
204
- it "extracts line number from caller" do
205
- mfe[:line_number].should eq(line_number)
206
- end
207
-
208
- it "extracts location from caller" do
209
- mfe[:location].should eq("#{relative_path(__FILE__)}:#{line_number}")
210
- end
211
-
212
- it "uses :caller if passed as an option" do
213
- example_metadata = metadata.for_example('example description', {:caller => ['example_file:42']})
214
- example_metadata[:location].should eq("example_file:42")
215
- end
216
-
217
- it "merges arbitrary options" do
218
- mfe[:arbitrary].should eq(:options)
219
- end
220
-
221
- it "points :example_group to the same hash object" do
222
- a = metadata.for_example("foo", {})[:example_group]
223
- b = metadata.for_example("bar", {})[:example_group]
224
- a[:description] = "new description"
225
- b[:description].should eq("new description")
226
- end
227
- end
228
-
229
- [:described_class, :describes].each do |key|
230
- describe key do
231
- context "with a String" do
232
- it "returns nil" do
233
- m = Metadata.new
234
- m.process('group')
235
-
236
- m[:example_group][key].should be_nil
237
- end
238
- end
239
-
240
- context "with a Symbol" do
241
- it "returns nil" do
242
- m = Metadata.new
243
- m.process(:group)
244
-
245
- m[:example_group][key].should be_nil
246
- end
247
- end
248
-
249
- context "with a class" do
250
- it "returns the class" do
251
- m = Metadata.new
252
- m.process(String)
253
-
254
- m[:example_group][key].should be(String)
255
- end
256
- end
257
-
258
- context "in a nested group" do
259
- it "returns the parent group's described class" do
260
- sm = Metadata.new
261
- sm.process(String)
262
-
263
- m = Metadata.new(sm)
264
- m.process(Array)
265
-
266
- m[:example_group][key].should be(String)
267
- end
268
-
269
- it "returns own described class if parent doesn't have one" do
270
- sm = Metadata.new
271
- sm.process("foo")
272
-
273
- m = Metadata.new(sm)
274
- m.process(Array)
275
-
276
- m[:example_group][key].should be(Array)
277
- end
278
-
279
- it "can override a parent group's described class" do
280
- parent = Metadata.new
281
- parent.process(String)
282
-
283
- child = Metadata.new(parent)
284
- child.process(Fixnum)
285
- child[:example_group][key] = Hash
286
-
287
- grandchild = Metadata.new(child)
288
- grandchild.process(Array)
289
-
290
- grandchild[:example_group][key].should be(Hash)
291
- child[:example_group][key].should be(Hash)
292
- parent[:example_group][key].should be(String)
293
- end
294
- end
295
- end
296
- end
297
-
298
- describe ":description" do
299
- it "just has the example description" do
300
- m = Metadata.new
301
- m.process("group")
302
-
303
- m = m.for_example("example", {})
304
- m[:description].should eq("example")
305
- end
306
-
307
- context "with a string" do
308
- it "provides the submitted description" do
309
- m = Metadata.new
310
- m.process("group")
311
-
312
- m[:example_group][:description].should eq("group")
313
- end
314
- end
315
-
316
- context "with a non-string" do
317
- it "provides the submitted description" do
318
- m = Metadata.new
319
- m.process("group")
320
-
321
- m[:example_group][:description].should eq("group")
322
- end
323
- end
324
-
325
- context "with a non-string and a string" do
326
- it "concats the args" do
327
- m = Metadata.new
328
- m.process(Object, 'group')
329
-
330
- m[:example_group][:description].should eq("Object group")
331
- end
332
- end
333
-
334
- context "with empty args" do
335
- it "returns empty string for [:example_group][:description]" do
336
- m = Metadata.new
337
- m.process()
338
-
339
- m[:example_group][:description].should eq("")
340
- end
341
- end
342
- end
343
-
344
- describe ":full_description" do
345
- it "concats example group name and description" do
346
- group_metadata = Metadata.new
347
- group_metadata.process('group')
348
-
349
- example_metadata = group_metadata.for_example("example", {})
350
- example_metadata[:full_description].should eq("group example")
351
- end
352
-
353
- it "concats nested example group descriptions" do
354
- parent = Metadata.new
355
- parent.process('parent')
356
-
357
- child = Metadata.new(parent)
358
- child.process('child')
359
-
360
- child[:example_group][:full_description].should eq("parent child")
361
- child.for_example('example', child)[:full_description].should eq("parent child example")
362
- end
363
-
364
- it "concats nested example group descriptions three deep" do
365
- grandparent = Metadata.new
366
- grandparent.process('grandparent')
367
-
368
- parent = Metadata.new(grandparent)
369
- parent.process('parent')
370
-
371
- child = Metadata.new(parent)
372
- child.process('child')
373
-
374
- grandparent[:example_group][:full_description].should eq("grandparent")
375
- parent[:example_group][:full_description].should eq("grandparent parent")
376
- child[:example_group][:full_description].should eq("grandparent parent child")
377
- child.for_example('example', child)[:full_description].should eq("grandparent parent child example")
378
- end
379
-
380
- %w[# . ::].each do |char|
381
- context "with a 2nd arg starting with #{char}" do
382
- it "removes the space" do
383
- m = Metadata.new
384
- m.process(Array, "#{char}method")
385
- m[:example_group][:full_description].should eq("Array#{char}method")
386
- end
387
- end
388
- end
389
-
390
- %w[# . ::].each do |char|
391
- context "with a nested description starting with #{char}" do
392
- it "removes the space" do
393
- parent = Metadata.new
394
- parent.process("Object")
395
- child = Metadata.new(parent)
396
- child.process("#{char}method")
397
- child[:example_group][:full_description].should eq("Object#{char}method")
398
- end
399
- end
400
- end
401
- end
402
-
403
- describe ":file_path" do
404
- it "finds the first non-rspec lib file in the caller array" do
405
- m = Metadata.new
406
- m.process(:caller => [
407
- "./lib/rspec/core/foo.rb",
408
- "#{__FILE__}:#{__LINE__}"
409
- ])
410
- m[:example_group][:file_path].should eq(relative_path(__FILE__))
411
- end
412
- end
413
-
414
- describe ":line_number" do
415
- it "finds the line number with the first non-rspec lib file in the backtrace" do
416
- m = Metadata.new
417
- m.process({})
418
- m[:example_group][:line_number].should eq(__LINE__ - 1)
419
- end
420
-
421
- it "finds the line number with the first spec file with drive letter" do
422
- m = Metadata.new
423
- m.process(:caller => [ "C:/path/to/file_spec.rb:#{__LINE__}" ])
424
- m[:example_group][:line_number].should eq(__LINE__ - 1)
425
- end
426
-
427
- it "uses the number after the first : for ruby 1.9" do
428
- m = Metadata.new
429
- m.process(:caller => [ "#{__FILE__}:#{__LINE__}:999" ])
430
- m[:example_group][:line_number].should eq(__LINE__ - 1)
431
- end
432
- end
433
-
434
- describe "child example group" do
435
- it "nests the parent's example group metadata" do
436
- parent = Metadata.new
437
- parent.process(Object, 'parent')
438
-
439
- child = Metadata.new(parent)
440
- child.process()
441
-
442
- child[:example_group][:example_group].should eq(parent[:example_group])
443
- end
444
- end
445
- end
446
- end
447
- end
@@ -1,166 +0,0 @@
1
- require "spec_helper"
2
-
3
- module RSpec::Core
4
- describe OptionParser do
5
- let(:output_file){ mock File }
6
-
7
- before do
8
- RSpec.stub(:deprecate)
9
- File.stub(:open).with("foo.txt",'w') { (output_file) }
10
- end
11
-
12
- it "does not parse empty args" do
13
- parser = Parser.new
14
- OptionParser.should_not_receive(:new)
15
- parser.parse!([])
16
- end
17
-
18
- describe "--formatter" do
19
- it "is deprecated" do
20
- RSpec.should_receive(:deprecate)
21
- Parser.parse!(%w[--formatter doc])
22
- end
23
-
24
- it "gets converted to --format" do
25
- options = Parser.parse!(%w[--formatter doc])
26
- options[:formatters].first.should eq(["doc"])
27
- end
28
- end
29
-
30
- %w[--format -f].each do |option|
31
- describe option do
32
- it "defines the formatter" do
33
- options = Parser.parse!([option, 'doc'])
34
- options[:formatters].first.should eq(["doc"])
35
- end
36
- end
37
- end
38
-
39
- %w[--out -o].each do |option|
40
- describe option do
41
- let(:options) { Parser.parse!([option, 'out.txt']) }
42
-
43
- it "sets the output stream for the formatter" do
44
- options[:formatters].last.should eq(['progress', 'out.txt'])
45
- end
46
-
47
- context "with multiple formatters" do
48
- context "after last formatter" do
49
- it "sets the output stream for the last formatter" do
50
- options = Parser.parse!(['-f', 'progress', '-f', 'doc', option, 'out.txt'])
51
- options[:formatters][0].should eq(['progress'])
52
- options[:formatters][1].should eq(['doc', 'out.txt'])
53
- end
54
- end
55
-
56
- context "after first formatter" do
57
- it "sets the output stream for the first formatter" do
58
- options = Parser.parse!(['-f', 'progress', option, 'out.txt', '-f', 'doc'])
59
- options[:formatters][0].should eq(['progress', 'out.txt'])
60
- options[:formatters][1].should eq(['doc'])
61
- end
62
- end
63
- end
64
- end
65
- end
66
-
67
- %w[--example -e].each do |option|
68
- describe option do
69
- it "escapes the arg" do
70
- options = Parser.parse!([option, "this (and that)"])
71
- options[:full_description].length.should eq(1)
72
- "this (and that)".should match(options[:full_description].first)
73
- end
74
- end
75
- end
76
-
77
- %w[--pattern -P].each do |option|
78
- describe option do
79
- it "sets the filename pattern" do
80
- options = Parser.parse!([option, 'spec/**/*.spec'])
81
- options[:pattern].should eq('spec/**/*.spec')
82
- end
83
- end
84
- end
85
-
86
- %w[--tag -t].each do |option|
87
- describe option do
88
- context "without ~" do
89
- it "treats no value as true" do
90
- options = Parser.parse!([option, 'foo'])
91
- options[:inclusion_filter].should eq(:foo => true)
92
- end
93
-
94
- it "treats 'true' as true" do
95
- options = Parser.parse!([option, 'foo:true'])
96
- options[:inclusion_filter].should eq(:foo => true)
97
- end
98
-
99
- it "treats 'nil' as nil" do
100
- options = Parser.parse!([option, 'foo:nil'])
101
- options[:inclusion_filter].should eq(:foo => nil)
102
- end
103
-
104
- it "treats 'false' as false" do
105
- options = Parser.parse!([option, 'foo:false'])
106
- options[:inclusion_filter].should eq(:foo => false)
107
- end
108
-
109
- it "merges muliple invocations" do
110
- options = Parser.parse!([option, 'foo:false', option, 'bar:true', option, 'foo:true'])
111
- options[:inclusion_filter].should eq(:foo => true, :bar => true)
112
- end
113
-
114
- it "treats 'any_string' as 'any_string'" do
115
- options = Parser.parse!([option, 'foo:any_string'])
116
- options[:inclusion_filter].should eq(:foo => 'any_string')
117
- end
118
- end
119
-
120
- context "with ~" do
121
- it "treats no value as true" do
122
- options = Parser.parse!([option, '~foo'])
123
- options[:exclusion_filter].should eq(:foo => true)
124
- end
125
-
126
- it "treats 'true' as true" do
127
- options = Parser.parse!([option, '~foo:true'])
128
- options[:exclusion_filter].should eq(:foo => true)
129
- end
130
-
131
- it "treats 'nil' as nil" do
132
- options = Parser.parse!([option, '~foo:nil'])
133
- options[:exclusion_filter].should eq(:foo => nil)
134
- end
135
-
136
- it "treats 'false' as false" do
137
- options = Parser.parse!([option, '~foo:false'])
138
- options[:exclusion_filter].should eq(:foo => false)
139
- end
140
- end
141
- end
142
- end
143
-
144
- describe "--order" do
145
- it "is nil by default" do
146
- Parser.parse!([])[:order].should be_nil
147
- end
148
-
149
- %w[rand random].each do |option|
150
- context "with #{option}" do
151
- it "defines the order as random" do
152
- options = Parser.parse!(['--order', option])
153
- options[:order].should eq(option)
154
- end
155
- end
156
- end
157
- end
158
-
159
- describe "--seed" do
160
- it "sets the order to rand:SEED" do
161
- options = Parser.parse!(%w[--seed 123])
162
- options[:order].should eq("rand:123")
163
- end
164
- end
165
- end
166
- end