rspec-core 3.0.0.beta2 → 3.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +1 -0
  5. data/Changelog.md +297 -57
  6. data/README.md +16 -13
  7. data/lib/rspec/core.rb +55 -84
  8. data/lib/rspec/core/backport_random.rb +35 -3
  9. data/lib/rspec/core/backtrace_formatter.rb +4 -13
  10. data/lib/rspec/core/configuration.rb +330 -114
  11. data/lib/rspec/core/configuration_options.rb +38 -22
  12. data/lib/rspec/core/drb.rb +111 -0
  13. data/lib/rspec/core/dsl.rb +8 -2
  14. data/lib/rspec/core/example.rb +203 -94
  15. data/lib/rspec/core/example_group.rb +344 -316
  16. data/lib/rspec/core/filter_manager.rb +135 -90
  17. data/lib/rspec/core/flat_map.rb +1 -0
  18. data/lib/rspec/core/formatters.rb +50 -14
  19. data/lib/rspec/core/formatters/base_formatter.rb +32 -138
  20. data/lib/rspec/core/formatters/base_text_formatter.rb +32 -253
  21. data/lib/rspec/core/formatters/console_codes.rb +65 -0
  22. data/lib/rspec/core/formatters/deprecation_formatter.rb +24 -15
  23. data/lib/rspec/core/formatters/documentation_formatter.rb +7 -10
  24. data/lib/rspec/core/formatters/helpers.rb +15 -9
  25. data/lib/rspec/core/formatters/html_formatter.rb +17 -16
  26. data/lib/rspec/core/formatters/html_printer.rb +1 -0
  27. data/lib/rspec/core/formatters/json_formatter.rb +18 -20
  28. data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
  29. data/lib/rspec/core/formatters/progress_formatter.rb +6 -7
  30. data/lib/rspec/core/formatters/snippet_extractor.rb +8 -6
  31. data/lib/rspec/core/hooks.rb +131 -125
  32. data/lib/rspec/core/memoized_helpers.rb +31 -26
  33. data/lib/rspec/core/metadata.rb +277 -184
  34. data/lib/rspec/core/metadata_filter.rb +86 -0
  35. data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
  36. data/lib/rspec/core/mocking_adapters/flexmock.rb +1 -1
  37. data/lib/rspec/core/mocking_adapters/mocha.rb +1 -1
  38. data/lib/rspec/core/mocking_adapters/null.rb +1 -1
  39. data/lib/rspec/core/mocking_adapters/rr.rb +2 -1
  40. data/lib/rspec/core/mocking_adapters/rspec.rb +1 -1
  41. data/lib/rspec/core/notifications.rb +435 -24
  42. data/lib/rspec/core/option_parser.rb +16 -25
  43. data/lib/rspec/core/ordering.rb +3 -1
  44. data/lib/rspec/core/pending.rb +57 -33
  45. data/lib/rspec/core/project_initializer.rb +2 -0
  46. data/lib/rspec/core/project_initializer/spec_helper.rb +5 -4
  47. data/lib/rspec/core/rake_task.rb +45 -20
  48. data/lib/rspec/core/reporter.rb +50 -22
  49. data/lib/rspec/core/ruby_project.rb +1 -0
  50. data/lib/rspec/core/runner.rb +93 -39
  51. data/lib/rspec/core/shared_context.rb +7 -5
  52. data/lib/rspec/core/shared_example_group.rb +85 -77
  53. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  54. data/lib/rspec/core/version.rb +3 -1
  55. data/lib/rspec/core/warnings.rb +35 -17
  56. data/lib/rspec/core/world.rb +57 -5
  57. metadata +56 -369
  58. metadata.gz.sig +3 -3
  59. data/features/README.md +0 -13
  60. data/features/Upgrade.md +0 -352
  61. data/features/command_line/README.md +0 -25
  62. data/features/command_line/dry_run.feature +0 -29
  63. data/features/command_line/example_name_option.feature +0 -97
  64. data/features/command_line/exit_status.feature +0 -82
  65. data/features/command_line/fail_fast.feature +0 -26
  66. data/features/command_line/format_option.feature +0 -75
  67. data/features/command_line/init.feature +0 -57
  68. data/features/command_line/line_number_appended_to_path.feature +0 -140
  69. data/features/command_line/line_number_option.feature +0 -58
  70. data/features/command_line/order.feature +0 -25
  71. data/features/command_line/pattern_option.feature +0 -49
  72. data/features/command_line/rake_task.feature +0 -122
  73. data/features/command_line/randomization.feature +0 -63
  74. data/features/command_line/require_option.feature +0 -43
  75. data/features/command_line/ruby.feature +0 -23
  76. data/features/command_line/tag.feature +0 -98
  77. data/features/command_line/warnings_option.feature +0 -29
  78. data/features/configuration/alias_example_to.feature +0 -39
  79. data/features/configuration/backtrace_exclusion_patterns.feature +0 -105
  80. data/features/configuration/custom_settings.feature +0 -84
  81. data/features/configuration/default_path.feature +0 -38
  82. data/features/configuration/deprecation_stream.feature +0 -58
  83. data/features/configuration/enable_global_dsl.feature +0 -54
  84. data/features/configuration/fail_fast.feature +0 -77
  85. data/features/configuration/failure_exit_code.feature +0 -36
  86. data/features/configuration/order_and_seed.feature +0 -3
  87. data/features/configuration/output_stream.feature +0 -24
  88. data/features/configuration/overriding_global_ordering.feature +0 -93
  89. data/features/configuration/pattern.feature +0 -38
  90. data/features/configuration/profile.feature +0 -220
  91. data/features/configuration/read_options_from_file.feature +0 -90
  92. data/features/configuration/run_all_when_everything_filtered.feature +0 -76
  93. data/features/example_groups/aliasing.feature +0 -48
  94. data/features/example_groups/basic_structure.feature +0 -55
  95. data/features/example_groups/shared_context.feature +0 -74
  96. data/features/example_groups/shared_examples.feature +0 -286
  97. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -102
  98. data/features/filtering/exclusion_filters.feature +0 -135
  99. data/features/filtering/if_and_unless.feature +0 -138
  100. data/features/filtering/inclusion_filters.feature +0 -101
  101. data/features/formatters/configurable_colors.feature +0 -31
  102. data/features/formatters/custom_formatter.feature +0 -68
  103. data/features/formatters/json_formatter.feature +0 -30
  104. data/features/formatters/regression_tests.feature +0 -95
  105. data/features/formatters/text_formatter.feature +0 -46
  106. data/features/helper_methods/arbitrary_methods.feature +0 -40
  107. data/features/helper_methods/let.feature +0 -50
  108. data/features/helper_methods/modules.feature +0 -146
  109. data/features/hooks/around_hooks.feature +0 -344
  110. data/features/hooks/before_and_after_hooks.feature +0 -427
  111. data/features/hooks/filtering.feature +0 -232
  112. data/features/metadata/current_example.feature +0 -56
  113. data/features/metadata/described_class.feature +0 -17
  114. data/features/metadata/user_defined.feature +0 -100
  115. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  116. data/features/mock_framework_integration/use_flexmock.feature +0 -94
  117. data/features/mock_framework_integration/use_mocha.feature +0 -95
  118. data/features/mock_framework_integration/use_rr.feature +0 -96
  119. data/features/mock_framework_integration/use_rspec.feature +0 -95
  120. data/features/pending_and_skipped_examples/README.md +0 -3
  121. data/features/pending_and_skipped_examples/pending_examples.feature +0 -118
  122. data/features/pending_and_skipped_examples/skipped_examples.feature +0 -106
  123. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  124. data/features/step_definitions/additional_cli_steps.rb +0 -83
  125. data/features/subject/explicit_subject.feature +0 -101
  126. data/features/subject/implicit_subject.feature +0 -63
  127. data/features/subject/one_liner_syntax.feature +0 -71
  128. data/features/support/env.rb +0 -21
  129. data/features/support/require_expect_syntax_in_aruba_specs.rb +0 -16
  130. data/features/support/rubinius.rb +0 -6
  131. data/lib/rspec/core/command_line.rb +0 -35
  132. data/lib/rspec/core/drb_command_line.rb +0 -26
  133. data/lib/rspec/core/drb_options.rb +0 -87
  134. data/lib/rspec/core/formatters/legacy_formatter.rb +0 -227
  135. data/lib/rspec/core/shared_example_group/collection.rb +0 -27
  136. data/spec/command_line/order_spec.rb +0 -211
  137. data/spec/rspec/core/backtrace_formatter_spec.rb +0 -230
  138. data/spec/rspec/core/command_line_spec.rb +0 -112
  139. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  140. data/spec/rspec/core/configuration_options_spec.rb +0 -409
  141. data/spec/rspec/core/configuration_spec.rb +0 -1479
  142. data/spec/rspec/core/drb_command_line_spec.rb +0 -102
  143. data/spec/rspec/core/drb_options_spec.rb +0 -193
  144. data/spec/rspec/core/dsl_spec.rb +0 -88
  145. data/spec/rspec/core/example_group_spec.rb +0 -1533
  146. data/spec/rspec/core/example_spec.rb +0 -642
  147. data/spec/rspec/core/filter_manager_spec.rb +0 -229
  148. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -64
  149. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -303
  150. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -208
  151. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -75
  152. data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
  153. data/spec/rspec/core/formatters/html_formatted-2.1.0.html +0 -392
  154. data/spec/rspec/core/formatters/html_formatted.html +0 -397
  155. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -122
  156. data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -206
  157. data/spec/rspec/core/formatters/legacy_formatter_spec.rb +0 -137
  158. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -43
  159. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
  160. data/spec/rspec/core/formatters_spec.rb +0 -120
  161. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  162. data/spec/rspec/core/hooks_spec.rb +0 -294
  163. data/spec/rspec/core/memoized_helpers_spec.rb +0 -495
  164. data/spec/rspec/core/metadata_spec.rb +0 -491
  165. data/spec/rspec/core/option_parser_spec.rb +0 -262
  166. data/spec/rspec/core/ordering_spec.rb +0 -102
  167. data/spec/rspec/core/pending_example_spec.rb +0 -117
  168. data/spec/rspec/core/pending_spec.rb +0 -8
  169. data/spec/rspec/core/project_initializer_spec.rb +0 -73
  170. data/spec/rspec/core/rake_task_spec.rb +0 -146
  171. data/spec/rspec/core/random_spec.rb +0 -47
  172. data/spec/rspec/core/reporter_spec.rb +0 -155
  173. data/spec/rspec/core/resources/a_bar.rb +0 -0
  174. data/spec/rspec/core/resources/a_foo.rb +0 -0
  175. data/spec/rspec/core/resources/a_spec.rb +0 -1
  176. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  177. data/spec/rspec/core/resources/formatter_specs.rb +0 -58
  178. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  179. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  180. data/spec/rspec/core/ruby_project_spec.rb +0 -26
  181. data/spec/rspec/core/runner_spec.rb +0 -151
  182. data/spec/rspec/core/shared_context_spec.rb +0 -102
  183. data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -57
  184. data/spec/rspec/core/shared_example_group_spec.rb +0 -114
  185. data/spec/rspec/core/warnings_spec.rb +0 -29
  186. data/spec/rspec/core/world_spec.rb +0 -142
  187. data/spec/rspec/core_spec.rb +0 -91
  188. data/spec/spec_helper.rb +0 -160
  189. data/spec/support/config_options_helper.rb +0 -13
  190. data/spec/support/formatter_support.rb +0 -83
  191. data/spec/support/helper_methods.rb +0 -26
  192. data/spec/support/isolate_load_path_mutation.rb +0 -5
  193. data/spec/support/isolated_directory.rb +0 -10
  194. data/spec/support/isolated_home_directory.rb +0 -16
  195. data/spec/support/legacy_formatter_using_sub_classing_example.rb +0 -87
  196. data/spec/support/matchers.rb +0 -85
  197. data/spec/support/mathn_integration_support.rb +0 -12
  198. data/spec/support/old_style_formatter_example.rb +0 -69
  199. data/spec/support/shared_example_groups.rb +0 -13
  200. data/spec/support/spec_files.rb +0 -44
  201. data/spec/support/stderr_splitter.rb +0 -36
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # rspec-core [![Build Status](https://secure.travis-ci.org/rspec/rspec-core.png?branch=master)](http://travis-ci.org/rspec/rspec-core) [![Code Climate](https://codeclimate.com/github/rspec/rspec-core.png)](https://codeclimate.com/github/rspec/rspec-core)
1
+ # rspec-core [![Build Status](https://secure.travis-ci.org/rspec/rspec-core.png?branch=master)](http://travis-ci.org/rspec/rspec-core) [![Code Climate](https://codeclimate.com/github/rspec/rspec-core.png)](https://codeclimate.com/github/rspec/rspec-core) [![Inline docs](http://inch-pages.github.io/github/rspec/rspec-core.png)](http://inch-pages.github.io/github/rspec/rspec-core)
2
2
 
3
3
  rspec-core provides the structure for writing executable examples of how your
4
4
  code should behave, and an `rspec` command with tools to constrain which
@@ -18,7 +18,7 @@ RSpec uses the words "describe" and "it" so we can express concepts like a conve
18
18
  "It sums the prices of its line items."
19
19
 
20
20
  ```ruby
21
- describe Order do
21
+ RSpec.describe Order do
22
22
  it "sums the prices of its line items" do
23
23
  order = Order.new
24
24
  order.add_entry(LineItem.new(:item => Item.new(
@@ -46,7 +46,7 @@ You can also declare nested nested groups using the `describe` or `context`
46
46
  methods:
47
47
 
48
48
  ```ruby
49
- describe Order do
49
+ RSpec.describe Order do
50
50
  context "with no items" do
51
51
  it "behaves one way" do
52
52
  # ...
@@ -63,8 +63,11 @@ end
63
63
 
64
64
  ## aliases
65
65
 
66
- You can declare example groups using either `describe` or `context`, though
67
- only `describe` is available at the top level.
66
+ You can declare example groups using either `describe` or `context`.
67
+ For a top level example group, `describe` and `context` are available
68
+ off of `RSpec`. For backwards compatibility, they are also available
69
+ off of the `main` object and `Module` unless you disable monkey
70
+ patching.
68
71
 
69
72
  You can declare examples within a group using any of `it`, `specify`, or
70
73
  `example`.
@@ -75,17 +78,17 @@ Declare a shared example group using `shared_examples`, and then include it
75
78
  in any group using `include_examples`.
76
79
 
77
80
  ```ruby
78
- shared_examples "collections" do |collection_class|
81
+ RSpec.shared_examples "collections" do |collection_class|
79
82
  it "is empty when first created" do
80
83
  expect(collection_class.new).to be_empty
81
84
  end
82
85
  end
83
86
 
84
- describe Array do
87
+ RSpec.describe Array do
85
88
  include_examples "collections", Array
86
89
  end
87
90
 
88
- describe Hash do
91
+ RSpec.describe Hash do
89
92
  include_examples "collections", Hash
90
93
  end
91
94
  ```
@@ -123,7 +126,7 @@ using the `described_class` method, which is a wrapper for
123
126
  `example.metadata[:described_class]`.
124
127
 
125
128
  ```ruby
126
- describe Widget do
129
+ RSpec.describe Widget do
127
130
  example do
128
131
  expect(described_class).to equal(Widget)
129
132
  end
@@ -135,17 +138,17 @@ class is unknown. Taking the collections shared example group from above, we can
135
138
  clean it up a bit using `described_class`:
136
139
 
137
140
  ```ruby
138
- shared_examples "collections" do
141
+ RSpec.shared_examples "collections" do
139
142
  it "is empty when first created" do
140
143
  expect(described_class.new).to be_empty
141
144
  end
142
145
  end
143
146
 
144
- describe Array do
147
+ RSpec.describe Array do
145
148
  include_examples "collections"
146
149
  end
147
150
 
148
- describe Hash do
151
+ RSpec.describe Hash do
149
152
  include_examples "collections"
150
153
  end
151
154
  ```
@@ -176,7 +179,7 @@ this before you write any implementation code:
176
179
 
177
180
  ```ruby
178
181
  # in spec/calculator_spec.rb
179
- describe Calculator do
182
+ RSpec.describe Calculator do
180
183
  describe '#add' do
181
184
  it 'returns the sum of its arguments' do
182
185
  expect(Calculator.new.add(1, 2)).to eq(3)
@@ -1,77 +1,49 @@
1
- require_rspec = if defined?(require_relative)
2
- lambda do |path|
3
- require_relative path
4
- end
5
- else # for 1.8.7
6
- lambda do |path|
7
- require "rspec/#{path}"
8
- end
9
- end
10
-
11
- require 'set'
12
- require 'time'
1
+ $_rspec_core_load_started_at = Time.now
13
2
  require 'rbconfig'
14
3
 
15
- require_rspec['core/version']
16
-
17
- require 'rspec/support/caller_filter'
18
- require 'rspec/core/warnings'
19
- require 'rspec/support/warnings'
20
-
21
- require_rspec['core/flat_map']
22
- require_rspec['core/filter_manager']
23
- require_rspec['core/dsl']
24
- require_rspec['core/notifications']
25
- require_rspec['core/reporter']
26
-
27
- require_rspec['core/hooks']
28
- require_rspec['core/memoized_helpers']
29
- require_rspec['core/metadata']
30
- require_rspec['core/pending']
31
- require_rspec['core/formatters']
32
- require_rspec['core/ordering']
33
-
34
- require_rspec['core/world']
35
- require_rspec['core/configuration']
36
- require_rspec['core/option_parser']
37
- require_rspec['core/configuration_options']
38
- require_rspec['core/command_line']
39
- require_rspec['core/runner']
40
- require_rspec['core/example']
41
- require_rspec['core/shared_example_group/collection']
42
- require_rspec['core/shared_example_group']
43
- require_rspec['core/example_group']
4
+ require "rspec/support"
5
+ RSpec::Support.require_rspec_support "caller_filter"
6
+
7
+ RSpec::Support.define_optimized_require_for_rspec(:core) { |f| require_relative f }
8
+
9
+ %w[
10
+ version
11
+ warnings
12
+
13
+ flat_map
14
+ filter_manager
15
+ dsl
16
+ notifications
17
+ reporter
18
+
19
+ hooks
20
+ memoized_helpers
21
+ metadata
22
+ metadata_filter
23
+ pending
24
+ formatters
25
+ ordering
26
+
27
+ world
28
+ configuration
29
+ option_parser
30
+ configuration_options
31
+ runner
32
+ example
33
+ shared_example_group
34
+ example_group
35
+ ].each { |name| RSpec::Support.require_rspec_core name }
44
36
 
45
37
  module RSpec
46
38
  autoload :SharedContext, 'rspec/core/shared_context'
47
39
 
48
- # @private
49
- def self.wants_to_quit
50
- # Used internally to determine what to do when a SIGINT is received
51
- world.wants_to_quit
52
- end
53
-
54
- # @private
55
- # Used internally to determine what to do when a SIGINT is received
56
- def self.wants_to_quit=(maybe)
57
- world.wants_to_quit=(maybe)
58
- end
59
-
60
- # @private
61
- # Internal container for global non-configuration data
62
- def self.world
63
- @world ||= RSpec::Core::World.new
64
- end
65
-
66
- # @private
67
- # Used internally to set the global object
68
- def self.world=(new_world)
69
- @world = new_world
70
- end
40
+ extend RSpec::Core::Warnings
71
41
 
72
- # @private
73
- # Used internally to ensure examples get reloaded between multiple runs in
42
+ # Used to ensure examples get reloaded between multiple runs in
74
43
  # the same process.
44
+ #
45
+ # Users must invoke this if they want to have the configuration reset when
46
+ # they use runner multiple times within the same process.
75
47
  def self.reset
76
48
  @world = nil
77
49
  @configuration = nil
@@ -94,12 +66,6 @@ module RSpec
94
66
 
95
67
  end
96
68
 
97
- # @private
98
- # Used internally to set the global object
99
- def self.configuration=(new_configuration)
100
- @configuration = new_configuration
101
- end
102
-
103
69
  # Yields the global configuration to a block.
104
70
  # @yield [Configuration] global configuration
105
71
  #
@@ -112,12 +78,6 @@ module RSpec
112
78
  yield configuration if block_given?
113
79
  end
114
80
 
115
- # @private
116
- # Used internally to clear remaining groups when fail_fast is set
117
- def self.clear_remaining_example_groups
118
- world.example_groups.clear
119
- end
120
-
121
81
  # The example being executed.
122
82
  #
123
83
  # The primary audience for this method is library authors who need access
@@ -132,7 +92,7 @@ module RSpec
132
92
  # fetch_current_example = RSpec.respond_to?(:current_example) ?
133
93
  # proc { RSpec.current_example } : proc { |context| context.example }
134
94
  #
135
- # c.before(:each) do
95
+ # c.before(:example) do
136
96
  # example = fetch_current_example.call(self)
137
97
  #
138
98
  # # ...
@@ -140,20 +100,29 @@ module RSpec
140
100
  # end
141
101
  #
142
102
  def self.current_example
143
- Thread.current[:_rspec_current_example]
103
+ thread_local_metadata[:current_example]
144
104
  end
145
105
 
146
106
  # Set the current example being executed.
147
107
  # @api private
148
108
  def self.current_example=(example)
149
- Thread.current[:_rspec_current_example] = example
109
+ thread_local_metadata[:current_example] = example
150
110
  end
151
111
 
152
112
  # @private
153
- def self.windows_os?
154
- RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/
113
+ # A single thread local variable so we don't excessively pollute that
114
+ # namespace.
115
+ def self.thread_local_metadata
116
+ Thread.current[:_rspec] ||= {}
155
117
  end
156
118
 
119
+ # @private
120
+ # Internal container for global non-configuration data
121
+ def self.world
122
+ @world ||= RSpec::Core::World.new
123
+ end
124
+
125
+ # Namespace for the rspec-core code.
157
126
  module Core
158
127
  # @private
159
128
  # This avoids issues with reporting time caused by examples that
@@ -171,12 +140,14 @@ module RSpec
171
140
  end
172
141
  end
173
142
 
143
+ # @private
174
144
  MODULES_TO_AUTOLOAD = {
175
145
  :Matchers => "rspec/expectations",
176
146
  :Expectations => "rspec/expectations",
177
147
  :Mocks => "rspec/mocks"
178
148
  }
179
149
 
150
+ # @private
180
151
  def self.const_missing(name)
181
152
  # Load rspec-expectations when RSpec::Matchers is referenced. This allows
182
153
  # people to define custom matchers (using `RSpec::Matchers.define`) before
@@ -188,7 +159,7 @@ module RSpec
188
159
  #
189
160
  # As of rspec 2.14.1, we no longer require `rspec/mocks` and
190
161
  # `rspec/expectations` when `rspec` is required, so we want
191
- # to make them available as an autoload. For more info, see:
162
+ # to make them available as an autoload.
192
163
  require MODULES_TO_AUTOLOAD.fetch(name) { return super }
193
164
  ::RSpec.const_get(name)
194
165
  end
@@ -1,12 +1,40 @@
1
- # This code was (mostly) ported from the backports gem (https://github.com/marcandre/backports).
2
- # The goal is to provide a random number generator in Ruby versions that do not have one.
3
- # This was added to support localization of random spec ordering.
1
+ # This code was (mostly) ported from the backports gem found at
2
+ # https://github.com/marcandre/backports which is subject to this license:
3
+ #
4
+ # =============================================================================
5
+ #
6
+ # Copyright (c) 2009 Marc-Andre Lafortune
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to
13
+ # permit persons to whom the Software is furnished to do so, subject to
14
+ # the following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be
17
+ # included in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ #
27
+ # =============================================================================
28
+ #
29
+ # The goal is to provide a random number generator in Ruby versions that do
30
+ # not have one. This was added to support localization of random spec ordering.
4
31
  #
5
32
  # These were in multiple files in backports, but merged into one here.
6
33
 
7
34
  module RSpec
8
35
  module Core
9
36
  # Methods used internally by the backports.
37
+ # @private
10
38
  module Backports
11
39
  # Helper method to coerce a value into a specific class.
12
40
  # Raises a TypeError if the coercion fails or the returned value
@@ -25,6 +53,7 @@ module RSpec
25
53
  ret
26
54
  end
27
55
 
56
+ # @private
28
57
  def self.coerce_to_int(obj)
29
58
  coerce_to(obj, Integer, :to_int)
30
59
  end
@@ -33,7 +62,9 @@ module RSpec
33
62
  # (from Rubinius)
34
63
  Undefined = Object.new
35
64
 
65
+ # @private
36
66
  class Random
67
+ # @private
37
68
  # An implementation of Mersenne Twister MT19937 in Ruby
38
69
  class MT19937
39
70
  STATE_SIZE = 624
@@ -198,6 +229,7 @@ module RSpec
198
229
  end
199
230
  end
200
231
 
232
+ # @private
201
233
  # Implementation corresponding to the actual Random class of Ruby
202
234
  # The actual random generator (mersenne twister) is in MT19937.
203
235
  # Ruby specific conversions are handled in bits_and_bytes.
@@ -1,13 +1,8 @@
1
1
  module RSpec
2
2
  module Core
3
+ # @private
3
4
  class BacktraceFormatter
4
- # This is only used externally by rspec-expectations. Can be removed once
5
- # rspec-expectations uses
6
- # RSpec.configuration.backtrace_formatter.format_backtrace instead.
7
- def self.format_backtrace(backtrace, options = {})
8
- RSpec.configuration.backtrace_formatter.format_backtrace(backtrace, options)
9
- end
10
-
5
+ # @private
11
6
  attr_accessor :exclusion_patterns, :inclusion_patterns
12
7
 
13
8
  def initialize
@@ -33,10 +28,8 @@ module RSpec
33
28
 
34
29
  def format_backtrace(backtrace, options = {})
35
30
  return backtrace if options[:full_backtrace]
36
- backtrace.
37
- take_while {|l| l != RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE}.
38
- map {|l| backtrace_line(l)}.
39
- compact.
31
+
32
+ backtrace.map { |l| backtrace_line(l) }.compact.
40
33
  tap do |filtered|
41
34
  if filtered.empty?
42
35
  filtered.concat backtrace
@@ -48,14 +41,12 @@ module RSpec
48
41
  end
49
42
  end
50
43
 
51
- # @api private
52
44
  def backtrace_line(line)
53
45
  RSpec::Core::Metadata::relative_path(line) unless exclude?(line)
54
46
  rescue SecurityError
55
47
  nil
56
48
  end
57
49
 
58
- # @api private
59
50
  def exclude?(line)
60
51
  return false if @full_backtrace
61
52
  matches_an_exclusion_pattern?(line) &&
@@ -1,7 +1,8 @@
1
1
  require 'fileutils'
2
- require 'rspec/core/backtrace_formatter'
3
- require 'rspec/core/ruby_project'
4
- require 'rspec/core/formatters/deprecation_formatter'
2
+
3
+ RSpec::Support.require_rspec_core "backtrace_formatter"
4
+ RSpec::Support.require_rspec_core "ruby_project"
5
+ RSpec::Support.require_rspec_core "formatters/deprecation_formatter"
5
6
 
6
7
  module RSpec
7
8
  module Core
@@ -21,9 +22,9 @@ module RSpec
21
22
  #
22
23
  # @example Hooks
23
24
  # RSpec.configure do |c|
24
- # c.before(:suite) { establish_connection }
25
- # c.before(:each) { log_in_as :authorized }
26
- # c.around(:each) { |ex| Database.transaction(&ex) }
25
+ # c.before(:suite) { establish_connection }
26
+ # c.before(:example) { log_in_as :authorized }
27
+ # c.around(:example) { |ex| Database.transaction(&ex) }
27
28
  # end
28
29
  #
29
30
  # @see RSpec.configure
@@ -31,6 +32,7 @@ module RSpec
31
32
  class Configuration
32
33
  include RSpec::Core::Hooks
33
34
 
35
+ # @private
34
36
  class MustBeConfiguredBeforeExampleGroupsError < StandardError; end
35
37
 
36
38
  # @private
@@ -77,10 +79,11 @@ module RSpec
77
79
  end
78
80
 
79
81
  # @macro [attach] add_setting
80
- # @attribute $1
82
+ # @!attribute [rw] $1
83
+ # @!method $1=(value)
81
84
  #
82
85
  # @macro [attach] define_reader
83
- # @attribute $1
86
+ # @!attribute [r] $1
84
87
 
85
88
  # @macro add_setting
86
89
  # Path to use if no path is provided to the `rspec` command (default:
@@ -121,9 +124,24 @@ module RSpec
121
124
  end
122
125
  end
123
126
 
124
- # @macro add_setting
125
- # Default: `$stderr`.
126
- add_setting :deprecation_stream
127
+ # Determines where deprecation warnings are printed.
128
+ # Defaults to `$stderr`.
129
+ # @return [IO, String] IO to write to or filename to write to
130
+ define_reader :deprecation_stream
131
+
132
+ # Determines where deprecation warnings are printed.
133
+ # @param value [IO, String] IO to write to or filename to write to
134
+ def deprecation_stream=(value)
135
+ if @reporter && !value.equal?(@deprecation_stream)
136
+ warn "RSpec's reporter has already been initialized with " +
137
+ "#{deprecation_stream.inspect} as the deprecation stream, so your change to "+
138
+ "`deprecation_stream` will be ignored. You should configure it earlier for " +
139
+ "it to take effect, or use the `--deprecation-out` CLI option. " +
140
+ "(Called from #{CallerFilter.first_non_rspec_line})"
141
+ else
142
+ @deprecation_stream = value
143
+ end
144
+ end
127
145
 
128
146
  # @macro add_setting
129
147
  # Clean up and exit after the first failure (default: `false`).
@@ -143,13 +161,16 @@ module RSpec
143
161
  define_reader :requires
144
162
 
145
163
  # @macro define_reader
146
- # Returns dirs that have been prepended to the load path by #lib=
164
+ # Returns dirs that have been prepended to the load path by the `-I` command line option
147
165
  define_reader :libs
148
166
 
149
167
  # @macro add_setting
168
+ # Determines where RSpec will send its output.
150
169
  # Default: `$stdout`.
151
- # Also known as `output` and `out`
152
170
  define_reader :output_stream
171
+
172
+ # Set the output stream for reporter
173
+ # @attr value [IO] value for output, defaults to $stdout
153
174
  def output_stream=(value)
154
175
  if @reporter && !value.equal?(@output_stream)
155
176
  warn "RSpec's reporter has already been initialized with " +
@@ -163,15 +184,16 @@ module RSpec
163
184
 
164
185
  # @macro add_setting
165
186
  # Load files matching this pattern (default: `'**/*_spec.rb'`)
166
- add_setting :pattern, :alias_with => :filename_pattern
187
+ add_setting :pattern
167
188
 
168
- def pattern= value
189
+ # Set pattern to match files to load
190
+ # @attr value [String] the filename pattern to filter spec files by
191
+ def pattern=(value)
169
192
  if @spec_files_loaded
170
193
  RSpec.warning "Configuring `pattern` to #{value} has no effect since RSpec has already loaded the spec files."
171
194
  end
172
195
  @pattern = value
173
196
  end
174
- alias :filename_pattern= :pattern=
175
197
 
176
198
  # @macro add_setting
177
199
  # Report the times for the slowest examples (default: `false`).
@@ -184,32 +206,44 @@ module RSpec
184
206
 
185
207
  # @macro add_setting
186
208
  # Color to use to indicate success.
187
- # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
209
+ # @param color [Symbol] defaults to `:green` but can be set to one of the
210
+ # following: `[:black, :white, :red, :green, :yellow,
211
+ # :blue, :magenta, :cyan]`
188
212
  add_setting :success_color
189
213
 
190
214
  # @macro add_setting
191
215
  # Color to use to print pending examples.
192
- # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
216
+ # @param color [Symbol] defaults to `:yellow` but can be set to one of the
217
+ # following: `[:black, :white, :red, :green, :yellow,
218
+ # :blue, :magenta, :cyan]`
193
219
  add_setting :pending_color
194
220
 
195
221
  # @macro add_setting
196
222
  # Color to use to indicate failure.
197
- # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
223
+ # @param color [Symbol] defaults to `:red` but can be set to one of the
224
+ # following: `[:black, :white, :red, :green, :yellow,
225
+ # :blue, :magenta, :cyan]`
198
226
  add_setting :failure_color
199
227
 
200
228
  # @macro add_setting
201
229
  # The default output color.
202
- # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
230
+ # @param color [Symbol] defaults to `:white` but can be set to one of the
231
+ # following:`[:black, :white, :red, :green, :yellow,
232
+ # :blue, :magenta, :cyan]`
203
233
  add_setting :default_color
204
234
 
205
235
  # @macro add_setting
206
236
  # Color used when a pending example is fixed.
207
- # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
237
+ # @param color [Symbol] defaults to `:blue` but can be set to one of the
238
+ # following: `[:black, :white, :red, :green, :yellow,
239
+ # :blue, :magenta, :cyan]`
208
240
  add_setting :fixed_color
209
241
 
210
242
  # @macro add_setting
211
243
  # Color used to print details.
212
- # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
244
+ # @param color [Symbol] defaults to `:cyan` but can be set to one of the
245
+ # following: `[:black, :white, :red, :green, :yellow,
246
+ # :blue, :magenta, :cyan]`
213
247
  add_setting :detail_color
214
248
 
215
249
  # Deprecated. This config option was added in RSpec 2 to pave the way
@@ -217,10 +251,13 @@ module RSpec
217
251
  # a no-op.
218
252
  def treat_symbols_as_metadata_keys_with_true_values=(value)
219
253
  RSpec.deprecate("RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values=",
220
- :message => "RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values=" +
254
+ :message => "RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values= " +
221
255
  "is deprecated, it is now set to true as default and setting it to false has no effect.")
222
256
  end
223
257
 
258
+ # Record the start time of the spec suite to measure load time
259
+ add_setting :start_time
260
+
224
261
  # @private
225
262
  add_setting :tty
226
263
  # @private
@@ -234,12 +271,8 @@ module RSpec
234
271
  # @private
235
272
  attr_reader :backtrace_formatter, :ordering_manager
236
273
 
237
- # Alias for rspec-2.x's backtrace_cleaner (now backtrace_formatter)
238
- #
239
- # TODO: consider deprecating and removing this rather than aliasing in rspec-3?
240
- alias backtrace_cleaner backtrace_formatter
241
-
242
274
  def initialize
275
+ @start_time = $_rspec_core_load_started_at || ::RSpec::Core::Time.now
243
276
  @expectation_frameworks = []
244
277
  @include_or_extend_modules = []
245
278
  @mock_framework = nil
@@ -255,6 +288,7 @@ module RSpec
255
288
  @deprecation_stream = $stderr
256
289
  @output_stream = $stdout
257
290
  @reporter = nil
291
+ @reporter_buffer = nil
258
292
  @filter_manager = FilterManager.new
259
293
  @ordering_manager = Ordering::ConfigurationManager.new
260
294
  @preferred_options = {}
@@ -267,6 +301,7 @@ module RSpec
267
301
  @profile_examples = false
268
302
  @requires = []
269
303
  @libs = []
304
+ @derived_metadata_blocks = []
270
305
  end
271
306
 
272
307
  # @private
@@ -275,7 +310,6 @@ module RSpec
275
310
  def force(hash)
276
311
  ordering_manager.force(hash)
277
312
  @preferred_options.merge!(hash)
278
- self.warnings = value_for :warnings, nil
279
313
  end
280
314
 
281
315
  # @private
@@ -322,7 +356,7 @@ module RSpec
322
356
  # RSpec.configuration.foo? # returns true if foo returns anything but nil or false
323
357
  def add_setting(name, opts={})
324
358
  default = opts.delete(:default)
325
- (class << self; self; end).class_eval do
359
+ (class << self; self; end).class_exec do
326
360
  add_setting(name, opts)
327
361
  end
328
362
  __send__("#{name}=", default) if default
@@ -354,6 +388,8 @@ module RSpec
354
388
  @backtrace_formatter.exclusion_patterns
355
389
  end
356
390
 
391
+ # Set regular expressions used to exclude lines in backtrace
392
+ # @param patterns [Regexp] set the backtrace exlusion pattern
357
393
  def backtrace_exclusion_patterns=(patterns)
358
394
  @backtrace_formatter.exclusion_patterns = patterns
359
395
  end
@@ -370,11 +406,13 @@ module RSpec
370
406
  @backtrace_formatter.inclusion_patterns
371
407
  end
372
408
 
409
+ # Set regular expressions used to include lines in backtrace
410
+ # @attr patterns [Regexp] set backtrace_formatter inclusion_patterns
373
411
  def backtrace_inclusion_patterns=(patterns)
374
412
  @backtrace_formatter.inclusion_patterns = patterns
375
413
  end
376
414
 
377
- # @api private
415
+ # @private
378
416
  MOCKING_ADAPTERS = {
379
417
  :rspec => :RSpec,
380
418
  :flexmock => :Flexmock,
@@ -400,8 +438,8 @@ module RSpec
400
438
  # - called before each example
401
439
  #
402
440
  # verify_mocks_for_rspec
403
- # - called after each example. Framework should raise an exception
404
- # when expectations fail
441
+ # - called after each example if the example hasn't yet failed.
442
+ # Framework should raise an exception when expectations fail
405
443
  #
406
444
  # teardown_mocks_for_rspec
407
445
  # - called after verify_mocks_for_rspec (even if there are errors)
@@ -422,7 +460,7 @@ module RSpec
422
460
  "Pass a module or one of #{MOCKING_ADAPTERS.keys.inspect}"
423
461
  end
424
462
 
425
- require "rspec/core/mocking_adapters/#{const_name.to_s.downcase}"
463
+ RSpec::Support.require_rspec_core "mocking_adapters/#{const_name.to_s.downcase}"
426
464
  RSpec::Core::MockingAdapters.const_get(const_name)
427
465
  end
428
466
 
@@ -456,16 +494,17 @@ module RSpec
456
494
  # Sets the expectation framework module(s) to be included in each example
457
495
  # group.
458
496
  #
459
- # `frameworks` can be `:rspec`, `:stdlib`, a custom module, or any
460
- # combination thereof:
497
+ # `frameworks` can be `:rspec`, `:test_unit`, `:minitest`, a custom
498
+ # module, or any combination thereof:
461
499
  #
462
500
  # config.expect_with :rspec
463
- # config.expect_with :stdlib
464
- # config.expect_with :rspec, :stdlib
501
+ # config.expect_with :test_unit
502
+ # config.expect_with :minitest
503
+ # config.expect_with :rspec, :minitest
465
504
  # config.expect_with OtherExpectationFramework
466
505
  #
467
- # RSpec will translate `:rspec` and `:stdlib` into the appropriate
468
- # modules.
506
+ # RSpec will translate `:rspec`, `:minitest`, and `:test_unit` into the
507
+ # appropriate modules.
469
508
  #
470
509
  # ## Configuration
471
510
  #
@@ -484,9 +523,12 @@ module RSpec
484
523
  require 'rspec/expectations'
485
524
  self.expecting_with_rspec = true
486
525
  ::RSpec::Matchers
487
- when :stdlib
488
- require 'test/unit/assertions'
489
- ::Test::Unit::Assertions
526
+ when :test_unit
527
+ require 'rspec/core/test_unit_assertions_adapter'
528
+ ::RSpec::Core::TestUnitAssertionsAdapter
529
+ when :minitest
530
+ require 'rspec/core/minitest_assertions_adapter'
531
+ ::RSpec::Core::MinitestAssertionsAdapter
490
532
  else
491
533
  raise ArgumentError, "#{framework.inspect} is not supported"
492
534
  end
@@ -505,25 +547,40 @@ module RSpec
505
547
  @expectation_frameworks.push(*modules)
506
548
  end
507
549
 
550
+ # Check if full backtrace is enabled
551
+ # @return [Boolean] is full backtrace enabled
508
552
  def full_backtrace?
509
553
  @backtrace_formatter.full_backtrace?
510
554
  end
511
555
 
556
+ # Toggle full backtrace
557
+ # @attr true_or_false [Boolean] toggle full backtrace display
512
558
  def full_backtrace=(true_or_false)
513
559
  @backtrace_formatter.full_backtrace = true_or_false
514
560
  end
515
561
 
516
- def color(output=output_stream)
517
- # rspec's built-in formatters all call this with the output argument,
518
- # but defaulting to output_stream for backward compatibility with
519
- # formatters in extension libs
520
- return false unless output_to_tty?(output)
562
+ # Returns the configuration option for color, but should not
563
+ # be used to check if color is supported.
564
+ #
565
+ # @see color_enabled?
566
+ # @return [Boolean]
567
+ def color
521
568
  value_for(:color, @color)
522
569
  end
523
570
 
524
- def color=(bool)
525
- if bool
526
- if RSpec.windows_os? and not ENV['ANSICON']
571
+ # Check if color is enabled for a particular output
572
+ # @param output [IO] an output stream to use, defaults to the current
573
+ # `output_stream`
574
+ # @return [Boolean]
575
+ def color_enabled?(output = output_stream)
576
+ output_to_tty?(output) && color
577
+ end
578
+
579
+ # Toggle output color
580
+ # @attr true_or_false [Boolean] toggle color enabled
581
+ def color=(true_or_false)
582
+ if true_or_false
583
+ if RSpec.world.windows_os? and not ENV['ANSICON']
527
584
  RSpec.warning "You must use ANSICON 1.31 or later (http://adoxa.3eeweb.com/ansicon/) to use colour on Windows"
528
585
  @color = false
529
586
  else
@@ -532,12 +589,7 @@ module RSpec
532
589
  end
533
590
  end
534
591
 
535
- # TODO - deprecate color_enabled - probably not until the last 2.x
536
- # release before 3.0
537
- alias_method :color_enabled, :color
538
- alias_method :color_enabled=, :color=
539
- define_predicate_for :color_enabled, :color
540
-
592
+ # @private
541
593
  def libs=(libs)
542
594
  libs.map do |lib|
543
595
  @libs.unshift lib
@@ -545,19 +597,13 @@ module RSpec
545
597
  end
546
598
  end
547
599
 
548
- # Run examples defined on `line_numbers` in all files to run.
549
- def line_numbers=(line_numbers)
550
- filter_run :line_numbers => line_numbers.map{|l| l.to_i}
551
- end
552
-
553
- def line_numbers
554
- filter.fetch(:line_numbers,[])
555
- end
556
-
600
+ # Run examples matching on `description` in all files to run.
601
+ # @param description [String, Regexp] the pattern to filter on
557
602
  def full_description=(description)
558
603
  filter_run :full_description => Regexp.union(*Array(description).map {|d| Regexp.new(d) })
559
604
  end
560
605
 
606
+ # @return [Array] full description filter
561
607
  def full_description
562
608
  filter.fetch :full_description, nil
563
609
  end
@@ -579,21 +625,70 @@ module RSpec
579
625
  end
580
626
  alias_method :formatter=, :add_formatter
581
627
 
582
- # @api private
628
+ # The formatter that will be used if no formatter has been set.
629
+ # Defaults to 'progress'.
630
+ def default_formatter
631
+ formatter_loader.default_formatter
632
+ end
633
+
634
+ # Sets a fallback formatter to use if none other has been set.
635
+ #
636
+ # @example
637
+ #
638
+ # RSpec.configure do |rspec|
639
+ # rspec.default_formatter = 'doc'
640
+ # end
641
+ def default_formatter=(value)
642
+ formatter_loader.default_formatter = value
643
+ end
644
+
645
+ # Returns a duplicate of the formatters currently loaded in
646
+ # the `FormatterLoader` for introspection.
647
+ #
648
+ # Note as this is a duplicate, any mutations will be disregarded.
649
+ #
650
+ # @return [Array] the formatters currently loaded
583
651
  def formatters
584
- formatter_loader.formatters
652
+ formatter_loader.formatters.dup
585
653
  end
586
654
 
587
- # @api private
655
+ # @private
588
656
  def formatter_loader
589
657
  @formatter_loader ||= Formatters::Loader.new(Reporter.new(self))
590
658
  end
591
659
 
592
- # @api private
660
+ # @private
661
+ #
662
+ # This buffer is used to capture all messages sent to the reporter during
663
+ # reporter initialization. It can then replay those messages after the
664
+ # formatter is correctly initialized. Otherwise, deprecation warnings
665
+ # during formatter initialization can cause an infinite loop.
666
+ class DeprecationReporterBuffer
667
+ def initialize
668
+ @calls = []
669
+ end
670
+
671
+ def deprecation(*args)
672
+ @calls << args
673
+ end
674
+
675
+ def play_onto(reporter)
676
+ @calls.each do |args|
677
+ reporter.deprecation(*args)
678
+ end
679
+ end
680
+ end
681
+
682
+ # @private
593
683
  def reporter
594
- @reporter ||=
684
+ # @reporter_buffer should only ever be set in this method to cover
685
+ # initialization of @reporter.
686
+ @reporter_buffer || @reporter ||=
595
687
  begin
688
+ @reporter_buffer = DeprecationReporterBuffer.new
596
689
  formatter_loader.setup_default output_stream, deprecation_stream
690
+ @reporter_buffer.play_onto(formatter_loader.reporter)
691
+ @reporter_buffer = nil
597
692
  formatter_loader.reporter
598
693
  end
599
694
  end
@@ -619,54 +714,70 @@ module RSpec
619
714
  @files_to_run = nil
620
715
  end
621
716
 
717
+ # The spec files RSpec will run
718
+ # @return [Array] specified files about to run
622
719
  def files_to_run
623
720
  @files_to_run ||= get_files_to_run(@files_or_directories_to_run)
624
721
  end
625
722
 
626
723
  # Creates a method that delegates to `example` including the submitted
627
724
  # `args`. Used internally to add variants of `example` like `pending`:
725
+ # @param name [String] example name alias
726
+ # @param args [Array<Symbol>, Hash] metadata for the generated example
727
+ #
728
+ # @note The specific example alias below (`pending`) is already
729
+ # defined for you.
730
+ # @note Use with caution. This extends the language used in your
731
+ # specs, but does not add any additional documentation. We use this
732
+ # in rspec to define methods like `focus` and `xit`, but we also add
733
+ # docs for those methods.
628
734
  #
629
735
  # @example
630
- # alias_example_to :pending, :pending => true
736
+ # RSpec.configure do |config|
737
+ # config.alias_example_to :pending, :pending => true
738
+ # end
631
739
  #
632
- # # This lets you do this:
740
+ # # This lets you do this:
633
741
  #
634
- # describe Thing do
635
- # pending "does something" do
636
- # thing = Thing.new
637
- # end
742
+ # describe Thing do
743
+ # pending "does something" do
744
+ # thing = Thing.new
638
745
  # end
746
+ # end
639
747
  #
640
- # # ... which is the equivalent of
748
+ # # ... which is the equivalent of
641
749
  #
642
- # describe Thing do
643
- # it "does something", :pending => true do
644
- # thing = Thing.new
645
- # end
750
+ # describe Thing do
751
+ # it "does something", :pending => true do
752
+ # thing = Thing.new
646
753
  # end
647
- def alias_example_to(new_name, *args)
754
+ # end
755
+ def alias_example_to(name, *args)
648
756
  extra_options = Metadata.build_hash_from(args)
649
- RSpec::Core::ExampleGroup.alias_example_to(new_name, extra_options)
757
+ RSpec::Core::ExampleGroup.define_example_method(name, extra_options)
650
758
  end
651
759
 
652
760
  # Creates a method that defines an example group with the provided
653
761
  # metadata. Can be used to define example group/metadata shortcuts.
654
762
  #
655
763
  # @example
656
- # alias_example_group_to :describe_model, :type => :model
657
- # shared_context_for "model tests", :type => :model do
658
- # # define common model test helper methods, `let` declarations, etc
659
- # end
764
+ # RSpec.configure do |config|
765
+ # config.alias_example_group_to :describe_model, :type => :model
766
+ # end
660
767
  #
661
- # # This lets you do this:
768
+ # shared_context_for "model tests", :type => :model do
769
+ # # define common model test helper methods, `let` declarations, etc
770
+ # end
662
771
  #
663
- # RSpec.describe_model User do
664
- # end
772
+ # # This lets you do this:
665
773
  #
666
- # # ... which is the equivalent of
774
+ # RSpec.describe_model User do
775
+ # end
667
776
  #
668
- # RSpec.describe User, :type => :model do
669
- # end
777
+ # # ... which is the equivalent of
778
+ #
779
+ # RSpec.describe User, :type => :model do
780
+ # end
670
781
  #
671
782
  # @note The defined aliased will also be added to the top level
672
783
  # (e.g. `main` and from within modules) if
@@ -675,34 +786,38 @@ module RSpec
675
786
  # @see #expose_dsl_globally=
676
787
  def alias_example_group_to(new_name, *args)
677
788
  extra_options = Metadata.build_hash_from(args)
678
- RSpec::Core::ExampleGroup.alias_example_group_to(new_name, extra_options)
789
+ RSpec::Core::ExampleGroup.define_example_group_method(new_name, extra_options)
679
790
  end
680
791
 
681
792
  # Define an alias for it_should_behave_like that allows different
682
793
  # language (like "it_has_behavior" or "it_behaves_like") to be
683
794
  # employed when including shared examples.
684
795
  #
685
- # Example:
686
- #
687
- # alias_it_behaves_like_to(:it_has_behavior, 'has behavior:')
796
+ # @example
797
+ # RSpec.configure do |config|
798
+ # config.alias_it_behaves_like_to(:it_has_behavior, 'has behavior:')
799
+ # end
688
800
  #
689
- # allows the user to include a shared example group like:
801
+ # # allows the user to include a shared example group like:
690
802
  #
691
- # describe Entity do
692
- # it_has_behavior 'sortability' do
693
- # let(:sortable) { Entity.new }
694
- # end
803
+ # describe Entity do
804
+ # it_has_behavior 'sortability' do
805
+ # let(:sortable) { Entity.new }
695
806
  # end
807
+ # end
696
808
  #
697
- # which is reported in the output as:
809
+ # # which is reported in the output as:
810
+ # # Entity
811
+ # # has behavior: sortability
812
+ # # ...sortability examples here
698
813
  #
699
- # Entity
700
- # has behavior: sortability
701
- # # sortability examples here
814
+ # @note Use with caution. This extends the language used in your
815
+ # specs, but does not add any additional documentation. We use this
816
+ # in rspec to define `it_should_behave_like` (for backward
817
+ # compatibility), but we also add docs for that method.
702
818
  def alias_it_behaves_like_to(new_name, report_label = '')
703
- RSpec::Core::ExampleGroup.alias_it_behaves_like_to(new_name, report_label)
819
+ RSpec::Core::ExampleGroup.define_nested_shared_group_method(new_name, report_label)
704
820
  end
705
-
706
821
  alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
707
822
 
708
823
  # Adds key/value pairs to the `inclusion_filter`. If `args`
@@ -748,7 +863,7 @@ module RSpec
748
863
  # This overrides any inclusion filters/tags set on the command line or in
749
864
  # configuration files.
750
865
  def inclusion_filter=(filter)
751
- filter_manager.include! Metadata.build_hash_from([filter])
866
+ filter_manager.include_only Metadata.build_hash_from([filter])
752
867
  end
753
868
 
754
869
  alias_method :filter=, :inclusion_filter=
@@ -802,7 +917,7 @@ module RSpec
802
917
  # This overrides any exclusion filters/tags set on the command line or in
803
918
  # configuration files.
804
919
  def exclusion_filter=(filter)
805
- filter_manager.exclude! Metadata.build_hash_from([filter])
920
+ filter_manager.exclude_only Metadata.build_hash_from([filter])
806
921
  end
807
922
 
808
923
  # Returns the `exclusion_filter`. If none has been set, returns an empty
@@ -906,10 +1021,12 @@ module RSpec
906
1021
 
907
1022
  # @private
908
1023
  if RUBY_VERSION.to_f >= 1.9
1024
+ # @private
909
1025
  def safe_extend(mod, host)
910
1026
  host.extend(mod) unless host.singleton_class < mod
911
1027
  end
912
1028
  else
1029
+ # @private
913
1030
  def safe_extend(mod, host)
914
1031
  host.extend(mod) unless (class << host; self; end).included_modules.include?(mod)
915
1032
  end
@@ -918,6 +1035,7 @@ module RSpec
918
1035
  # @private
919
1036
  def configure_mock_framework
920
1037
  RSpec::Core::ExampleGroup.__send__(:include, mock_framework)
1038
+ conditionally_disable_mocks_monkey_patching
921
1039
  end
922
1040
 
923
1041
  # @private
@@ -925,6 +1043,7 @@ module RSpec
925
1043
  expectation_frameworks.each do |framework|
926
1044
  RSpec::Core::ExampleGroup.__send__(:include, framework)
927
1045
  end
1046
+ conditionally_disable_expectations_monkey_patching
928
1047
  end
929
1048
 
930
1049
  # @private
@@ -1015,11 +1134,12 @@ module RSpec
1015
1134
  delegate_to_ordering_manager :seed_used?, :ordering_registry
1016
1135
 
1017
1136
  # Set Ruby warnings on or off
1018
- def warnings= value
1137
+ def warnings=(value)
1019
1138
  $VERBOSE = !!value
1020
1139
  end
1021
1140
 
1022
- def warnings
1141
+ # @return [Boolean] Whether or not ruby warnings are enabled.
1142
+ def warnings?
1023
1143
  $VERBOSE
1024
1144
  end
1025
1145
 
@@ -1046,7 +1166,7 @@ module RSpec
1046
1166
  # end
1047
1167
  # end
1048
1168
  def expose_current_running_example_as(method_name)
1049
- ExposeCurrentExample.module_eval do
1169
+ ExposeCurrentExample.module_exec do
1050
1170
  extend RSpec::SharedContext
1051
1171
  let(method_name) { |ex| ex }
1052
1172
  end
@@ -1054,6 +1174,7 @@ module RSpec
1054
1174
  include ExposeCurrentExample
1055
1175
  end
1056
1176
 
1177
+ # @private
1057
1178
  module ExposeCurrentExample; end
1058
1179
 
1059
1180
  # Turns deprecation warnings into errors, in order to surface
@@ -1070,6 +1191,78 @@ module RSpec
1070
1191
  self.deprecation_stream = Formatters::DeprecationFormatter::RaiseErrorStream.new
1071
1192
  end
1072
1193
 
1194
+ # Enables zero monkey patching mode for RSpec. It removes monkey
1195
+ # patching of the top-level DSL methods (`describe`,
1196
+ # `shared_examples_for`, etc) onto `main` and `Module`, instead
1197
+ # requiring you to prefix these methods with `RSpec.`. It enables
1198
+ # expect-only syntax for rspec-mocks and rspec-expectations. It
1199
+ # simply disables monkey patching on whatever pieces of rspec
1200
+ # the user is using.
1201
+ #
1202
+ # @note It configures rspec-mocks and rspec-expectations only
1203
+ # if the user is using those (either explicitly or implicitly
1204
+ # by not setting `mock_with` or `expect_with` to anything else).
1205
+ #
1206
+ # @note If the user uses this options with `mock_with :mocha`
1207
+ # (or similiar) they will still have monkey patching active
1208
+ # in their test environment from mocha.
1209
+ #
1210
+ # @example
1211
+ #
1212
+ # # It disables all monkey patching
1213
+ # RSpec.configure do |config|
1214
+ # config.disable_monkey_patching!
1215
+ # end
1216
+ #
1217
+ # # Is an equivalent to
1218
+ # RSpec.configure do |config|
1219
+ # config.expose_dsl_globally = false
1220
+ #
1221
+ # config.mock_with :rspec do |mocks|
1222
+ # mocks.syntax = :expect
1223
+ # mocks.patch_marshal_to_support_partial_doubles = false
1224
+ # end
1225
+ #
1226
+ # config.mock_with :rspec do |expectations|
1227
+ # expectations.syntax = :expect
1228
+ # end
1229
+ # end
1230
+ def disable_monkey_patching!
1231
+ self.expose_dsl_globally = false
1232
+ self.disable_monkey_patching = true
1233
+ conditionally_disable_mocks_monkey_patching
1234
+ conditionally_disable_expectations_monkey_patching
1235
+ end
1236
+
1237
+ # @private
1238
+ attr_accessor :disable_monkey_patching
1239
+
1240
+ # Defines a callback that can assign derived metadata values.
1241
+ #
1242
+ # @param filters [Array<Symbol>, Hash] metadata filters that determine which example
1243
+ # or group metadata hashes the callback will be triggered for. If none are given,
1244
+ # the callback will be run against the metadata hashes of all groups and examples.
1245
+ # @yieldparam metadata [Hash] original metadata hash from an example or group. Mutate this in
1246
+ # your block as needed.
1247
+ #
1248
+ # @example
1249
+ # RSpec.configure do |config|
1250
+ # # Tag all groups and examples in the spec/unit directory with :type => :unit
1251
+ # config.define_derived_metadata(:file_path => %r{/spec/unit/}) do |metadata|
1252
+ # metadata[:type] = :unit
1253
+ # end
1254
+ # end
1255
+ def define_derived_metadata(*filters, &block)
1256
+ @derived_metadata_blocks << [Metadata.build_hash_from(filters), block]
1257
+ end
1258
+
1259
+ # @private
1260
+ def apply_derived_metadata_to(metadata)
1261
+ @derived_metadata_blocks.each do |filter, block|
1262
+ block.call(metadata) if filter.empty? || MetadataFilter.any_apply?(filter, metadata)
1263
+ end
1264
+ end
1265
+
1073
1266
  private
1074
1267
 
1075
1268
  def get_files_to_run(paths)
@@ -1113,6 +1306,29 @@ module RSpec
1113
1306
  def output_to_tty?(output=output_stream)
1114
1307
  tty? || (output.respond_to?(:tty?) && output.tty?)
1115
1308
  end
1309
+
1310
+ def conditionally_disable_mocks_monkey_patching
1311
+ return unless disable_monkey_patching && rspec_mocks_loaded?
1312
+
1313
+ RSpec::Mocks.configuration.tap do |config|
1314
+ config.syntax = :expect
1315
+ config.patch_marshal_to_support_partial_doubles = false
1316
+ end
1317
+ end
1318
+
1319
+ def conditionally_disable_expectations_monkey_patching
1320
+ return unless disable_monkey_patching && rspec_expectations_loaded?
1321
+
1322
+ RSpec::Expectations.configuration.syntax = :expect
1323
+ end
1324
+
1325
+ def rspec_mocks_loaded?
1326
+ defined?(RSpec::Mocks.configuration)
1327
+ end
1328
+
1329
+ def rspec_expectations_loaded?
1330
+ defined?(RSpec::Expectations.configuration)
1331
+ end
1116
1332
  end
1117
1333
  end
1118
1334
  end