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,96 +1,271 @@
1
+ RSpec::Support.require_rspec_support "with_keywords_when_needed"
2
+
1
3
  module RSpec
2
4
  module Core
5
+ # Represents some functionality that is shared with multiple example groups.
6
+ # The functionality is defined by the provided block, which is lazily
7
+ # eval'd when the `SharedExampleGroupModule` instance is included in an example
8
+ # group.
9
+ class SharedExampleGroupModule < Module
10
+ # @private
11
+ attr_reader :definition
12
+
13
+ def initialize(description, definition, metadata)
14
+ @description = description
15
+ @definition = definition
16
+ @metadata = metadata
17
+ end
18
+
19
+ # Provides a human-readable representation of this module.
20
+ def inspect
21
+ "#<#{self.class.name} #{@description.inspect}>"
22
+ end
23
+ alias to_s inspect
24
+
25
+ # Ruby callback for when a module is included in another module is class.
26
+ # Our definition evaluates the shared group block in the context of the
27
+ # including example group.
28
+ def included(klass)
29
+ inclusion_line = klass.metadata[:location]
30
+ include_in klass, inclusion_line, [], nil
31
+ end
32
+
33
+ # @private
34
+ def include_in(klass, inclusion_line, args, customization_block)
35
+ klass.update_inherited_metadata(@metadata) unless @metadata.empty?
36
+
37
+ SharedExampleGroupInclusionStackFrame.with_frame(@description, inclusion_line) do
38
+ RSpec::Support::WithKeywordsWhenNeeded.class_exec(klass, *args, &@definition)
39
+ klass.class_exec(&customization_block) if customization_block
40
+ end
41
+ end
42
+ end
43
+
44
+ # Shared example groups let you define common context and/or common
45
+ # examples that you wish to use in multiple example groups.
46
+ #
47
+ # When defined, the shared group block is stored for later evaluation.
48
+ # It can later be included in an example group either explicitly
49
+ # (using `include_examples`, `include_context` or `it_behaves_like`)
50
+ # or implicitly (via matching metadata).
51
+ #
52
+ # Named shared example groups are scoped based on where they are
53
+ # defined. Shared groups defined in an example group are available
54
+ # for inclusion in that example group or any child example groups,
55
+ # but not in any parent or sibling example groups. Shared example
56
+ # groups defined at the top level can be included from any example group.
3
57
  module SharedExampleGroup
4
58
  # @overload shared_examples(name, &block)
5
- # @overload shared_examples(name, tags, &block)
6
- #
7
- # Wraps the `block` in a module which can then be included in example
8
- # groups using `include_examples`, `include_context`, or
9
- # `it_behaves_like`.
59
+ # @param name [String, Symbol, Module] identifer to use when looking up
60
+ # this shared group
61
+ # @param block The block to be eval'd
62
+ # @overload shared_examples(name, metadata, &block)
63
+ # @param name [String, Symbol, Module] identifer to use when looking up
64
+ # this shared group
65
+ # @param metadata [Array<Symbol>, Hash] metadata to attach to this
66
+ # group; any example group or example with matching metadata will
67
+ # automatically include this shared example group.
68
+ # @param block The block to be eval'd
10
69
  #
11
- # @param [String] name to match when looking up this shared group
12
- # @param block to be eval'd in a nested example group generated by `it_behaves_like`
70
+ # Stores the block for later use. The block will be evaluated
71
+ # in the context of an example group via `include_examples`,
72
+ # `include_context`, or `it_behaves_like`.
13
73
  #
14
74
  # @example
15
- #
16
75
  # shared_examples "auditable" do
17
76
  # it "stores an audit record on save!" do
18
- # lambda { auditable.save! }.should change(Audit, :count).by(1)
77
+ # expect { auditable.save! }.to change(Audit, :count).by(1)
19
78
  # end
20
79
  # end
21
80
  #
22
- # class Account do
81
+ # RSpec.describe Account do
23
82
  # it_behaves_like "auditable" do
24
- # def auditable; Account.new; end
83
+ # let(:auditable) { Account.new }
25
84
  # end
26
85
  # end
27
86
  #
28
87
  # @see ExampleGroup.it_behaves_like
29
88
  # @see ExampleGroup.include_examples
30
89
  # @see ExampleGroup.include_context
31
- def shared_examples *args, &block
32
- if key? args.first
33
- key = args.shift
34
- raise_key_taken key if key_taken? key
35
- RSpec.world.shared_example_groups[key] = block
90
+ def shared_examples(name, *args, &block)
91
+ top_level = self == ExampleGroup
92
+ if top_level && RSpec::Support.thread_local_data[:in_example_group]
93
+ raise "Creating isolated shared examples from within a context is " \
94
+ "not allowed. Remove `RSpec.` prefix or move this to a " \
95
+ "top-level scope."
36
96
  end
37
97
 
38
- unless args.empty?
39
- mod = Module.new
40
- (class << mod; self; end).send :define_method, :extended do |host|
41
- host.class_eval(&block)
98
+ RSpec.world.shared_example_group_registry.add(self, name, *args, &block)
99
+ end
100
+ alias shared_context shared_examples
101
+ alias shared_examples_for shared_examples
102
+
103
+ # @api private
104
+ #
105
+ # Shared examples top level DSL.
106
+ module TopLevelDSL
107
+ # @private
108
+ def self.definitions
109
+ proc do
110
+ def shared_examples(name, *args, &block)
111
+ RSpec.world.shared_example_group_registry.add(:main, name, *args, &block)
112
+ end
113
+ alias shared_context shared_examples
114
+ alias shared_examples_for shared_examples
42
115
  end
43
- RSpec.configuration.extend mod, *args
44
116
  end
45
- end
46
117
 
47
- alias_method :shared_context, :shared_examples
48
- alias_method :share_examples_for, :shared_examples
49
- alias_method :shared_examples_for, :shared_examples
118
+ # @private
119
+ def self.exposed_globally?
120
+ @exposed_globally ||= false
121
+ end
122
+
123
+ # @api private
124
+ #
125
+ # Adds the top level DSL methods to Module and the top level binding.
126
+ def self.expose_globally!
127
+ return if exposed_globally?
128
+ Core::DSL.change_global_dsl(&definitions)
129
+ @exposed_globally = true
130
+ end
131
+
132
+ # @api private
133
+ #
134
+ # Removes the top level DSL methods to Module and the top level binding.
135
+ def self.remove_globally!
136
+ return unless exposed_globally?
137
+
138
+ Core::DSL.change_global_dsl do
139
+ undef shared_examples
140
+ undef shared_context
141
+ undef shared_examples_for
142
+ end
50
143
 
51
- def share_as(name, &block)
52
- if Object.const_defined?(name)
53
- mod = Object.const_get(name)
54
- raise_name_error unless mod.created_from_caller(caller)
144
+ @exposed_globally = false
55
145
  end
146
+ end
147
+
148
+ # @private
149
+ class Registry
150
+ def add(context, name, *metadata_args, &block)
151
+ unless block
152
+ RSpec.warning "Shared example group #{name} was defined without a "\
153
+ "block and will have no effect. Please define a "\
154
+ "block or remove the definition."
155
+ end
56
156
 
57
- mod = Module.new do
58
- @shared_block = block
59
- @caller_line = caller.last
157
+ if RSpec.configuration.shared_context_metadata_behavior == :trigger_inclusion
158
+ return legacy_add(context, name, *metadata_args, &block)
159
+ end
60
160
 
61
- def self.created_from_caller(other_caller)
62
- @caller_line == other_caller.last
161
+ unless valid_name?(name)
162
+ raise ArgumentError, "Shared example group names can only be a string, " \
163
+ "symbol or module but got: #{name.inspect}"
63
164
  end
64
165
 
65
- def self.included(kls)
66
- kls.describe(&@shared_block)
67
- kls.children.first.metadata[:shared_group_name] = name
166
+ ensure_block_has_source_location(block) { CallerFilter.first_non_rspec_line }
167
+ warn_if_key_taken context, name, block
168
+
169
+ metadata = Metadata.build_hash_from(metadata_args)
170
+ shared_module = SharedExampleGroupModule.new(name, block, metadata)
171
+ shared_example_groups[context][name] = shared_module
172
+ end
173
+
174
+ def find(lookup_contexts, name)
175
+ lookup_contexts.each do |context|
176
+ found = shared_example_groups[context][name]
177
+ return found if found
68
178
  end
179
+
180
+ shared_example_groups[:main][name]
69
181
  end
70
182
 
71
- shared_const = Object.const_set(name, mod)
72
- RSpec.world.shared_example_groups[shared_const] = block
73
- end
183
+ private
74
184
 
75
- private
185
+ # TODO: remove this in RSpec 4. This exists only to support
186
+ # `config.shared_context_metadata_behavior == :trigger_inclusion`,
187
+ # the legacy behavior of shared context metadata, which we do
188
+ # not want to support in RSpec 4.
189
+ def legacy_add(context, name, *metadata_args, &block)
190
+ ensure_block_has_source_location(block) { CallerFilter.first_non_rspec_line }
191
+ shared_module = SharedExampleGroupModule.new(name, block, {})
76
192
 
77
- def key? candidate
78
- [String, Symbol, Module].any? { |cls| cls === candidate }
79
- end
193
+ if valid_name?(name)
194
+ warn_if_key_taken context, name, block
195
+ shared_example_groups[context][name] = shared_module
196
+ else
197
+ metadata_args.unshift name
198
+ end
80
199
 
81
- def raise_name_error
82
- raise NameError, "The first argument (#{name}) to share_as must be a legal name for a constant not already in use."
83
- end
200
+ return if metadata_args.empty?
201
+ RSpec.configuration.include shared_module, *metadata_args
202
+ end
84
203
 
85
- def raise_key_taken key
86
- raise ArgumentError, "Shared example group '#{key}' already exists"
87
- end
204
+ def shared_example_groups
205
+ @shared_example_groups ||= Hash.new { |hash, context| hash[context] = {} }
206
+ end
207
+
208
+ def valid_name?(candidate)
209
+ case candidate
210
+ when String, Symbol, Module then true
211
+ else false
212
+ end
213
+ end
214
+
215
+ def warn_if_key_taken(context, key, new_block)
216
+ existing_module = shared_example_groups[context][key]
217
+ return unless existing_module
218
+
219
+ old_definition_location = formatted_location existing_module.definition
220
+ new_definition_location = formatted_location new_block
221
+ loaded_spec_files = RSpec.configuration.loaded_spec_files
222
+
223
+ if loaded_spec_files.include?(new_definition_location) && old_definition_location == new_definition_location
224
+ RSpec.warn_with <<-WARNING.gsub(/^ +\|/, ''), :call_site => nil
225
+ |WARNING: Your shared example group, '#{key}', defined at:
226
+ | #{old_definition_location}
227
+ |was automatically loaded by RSpec because the file name
228
+ |matches the configured autoloading pattern (#{RSpec.configuration.pattern}),
229
+ |and is also being required from somewhere else. To fix this
230
+ |warning, either rename the file to not match the pattern, or
231
+ |do not explicitly require the file.
232
+ WARNING
233
+ else
234
+ RSpec.warn_with <<-WARNING.gsub(/^ +\|/, ''), :call_site => nil
235
+ |WARNING: Shared example group '#{key}' has been previously defined at:
236
+ | #{old_definition_location}
237
+ |...and you are now defining it at:
238
+ | #{new_definition_location}
239
+ |The new definition will overwrite the original one.
240
+ WARNING
241
+ end
242
+ end
243
+
244
+ if RUBY_VERSION.to_f >= 1.9
245
+ def formatted_location(block)
246
+ block.source_location.join(":")
247
+ end
248
+ else # 1.8.7
249
+ # :nocov:
250
+ def formatted_location(block)
251
+ block.source_location.join(":").gsub(/:in.*$/, '')
252
+ end
253
+ # :nocov:
254
+ end
88
255
 
89
- def key_taken? key
90
- RSpec.world.shared_example_groups.has_key?(key)
256
+ if Proc.method_defined?(:source_location)
257
+ def ensure_block_has_source_location(_block); end
258
+ else # for 1.8.7
259
+ # :nocov:
260
+ def ensure_block_has_source_location(block)
261
+ source_location = yield.split(':')
262
+ block.extend(Module.new { define_method(:source_location) { source_location } })
263
+ end
264
+ # :nocov:
265
+ end
91
266
  end
92
267
  end
93
268
  end
94
- end
95
269
 
96
- include RSpec::Core::SharedExampleGroup
270
+ instance_exec(&Core::SharedExampleGroup::TopLevelDSL.definitions)
271
+ end
@@ -0,0 +1,49 @@
1
+ module RSpec
2
+ module Core
3
+ # @private
4
+ # Deals with the fact that `shellwords` only works on POSIX systems.
5
+ module ShellEscape
6
+ module_function
7
+
8
+ def quote(argument)
9
+ "'#{argument.to_s.gsub("'", "\\\\'")}'"
10
+ end
11
+
12
+ if RSpec::Support::OS.windows?
13
+ # :nocov:
14
+ alias escape quote
15
+ # :nocov:
16
+ else
17
+ require 'shellwords'
18
+
19
+ def escape(shell_command)
20
+ Shellwords.escape(shell_command.to_s)
21
+ end
22
+ end
23
+
24
+ # Known shells that require quoting: zsh, csh, tcsh.
25
+ #
26
+ # Feel free to add other shells to this list that are known to
27
+ # allow `rspec ./some_spec.rb[1:1]` syntax without quoting the id.
28
+ #
29
+ # @private
30
+ SHELLS_ALLOWING_UNQUOTED_IDS = %w[ bash ksh fish ]
31
+
32
+ def conditionally_quote(id)
33
+ return id if shell_allows_unquoted_ids?
34
+ quote(id)
35
+ end
36
+
37
+ def shell_allows_unquoted_ids?
38
+ # Note: ENV['SHELL'] isn't necessarily the shell the user is currently running.
39
+ # According to http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html:
40
+ # "This variable shall represent a pathname of the user's preferred command language interpreter."
41
+ #
42
+ # It's the best we can easily do, though. We err on the side of safety (quoting
43
+ # the id when not actually needed) so it's not a big deal if the user is actually
44
+ # using a different shell.
45
+ SHELLS_ALLOWING_UNQUOTED_IDS.include?(ENV['SHELL'].to_s.split('/').last)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ require 'test/unit/assertions'
2
+
3
+ module RSpec
4
+ module Core
5
+ # @private
6
+ module TestUnitAssertionsAdapter
7
+ include ::Test::Unit::Assertions
8
+
9
+ # If using test/unit from Ruby core with Ruby 1.9+, it includes
10
+ # MiniTest::Assertions by default. Note the upcasing of 'Test'.
11
+ #
12
+ # If the test/unit gem is being loaded, it will not include any minitest
13
+ # assertions.
14
+ #
15
+ # Only if Minitest 5.x is included / loaded do we need to worry about
16
+ # adding a shim for the new updates. Thus instead of checking on the
17
+ # RUBY_VERSION we need to check ancestors.
18
+ begin
19
+ # MiniTest is 4.x.
20
+ # Minitest is 5.x.
21
+ if ancestors.include?(::Minitest::Assertions)
22
+ require 'rspec/core/minitest_assertions_adapter'
23
+ include ::RSpec::Core::MinitestAssertionsAdapter
24
+ end
25
+ rescue NameError
26
+ # No-op. Minitest 5.x was not loaded.
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,7 +1,9 @@
1
1
  module RSpec
2
2
  module Core
3
+ # Version information for RSpec Core.
3
4
  module Version
4
- STRING = '2.11.1'
5
+ # Current version of RSpec Core, in semantic versioning format.
6
+ STRING = '3.11.0'
5
7
  end
6
8
  end
7
9
  end
@@ -0,0 +1,40 @@
1
+ require "rspec/support/warnings"
2
+
3
+ module RSpec
4
+ module Core
5
+ # @private
6
+ module Warnings
7
+ # @private
8
+ #
9
+ # Used internally to print deprecation warnings.
10
+ def deprecate(deprecated, data={})
11
+ RSpec.configuration.reporter.deprecation(
12
+ {
13
+ :deprecated => deprecated,
14
+ :call_site => CallerFilter.first_non_rspec_line
15
+ }.merge(data)
16
+ )
17
+ end
18
+
19
+ # @private
20
+ #
21
+ # Used internally to print deprecation warnings.
22
+ def warn_deprecation(message, opts={})
23
+ RSpec.configuration.reporter.deprecation opts.merge(:message => message)
24
+ end
25
+
26
+ # @private
27
+ def warn_with(message, options={})
28
+ if options[:use_spec_location_as_call_site]
29
+ message += "." unless message.end_with?(".")
30
+
31
+ if RSpec.current_example
32
+ message += " Warning generated from spec at `#{RSpec.current_example.location}`."
33
+ end
34
+ end
35
+
36
+ super(message, options)
37
+ end
38
+ end
39
+ end
40
+ end