rspec-core 2.99.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +1 -0
  4. data/Changelog.md +339 -1
  5. data/License.txt +1 -0
  6. data/README.md +19 -37
  7. data/exe/rspec +2 -23
  8. data/lib/rspec/core/backport_random.rb +336 -0
  9. data/lib/rspec/core/backtrace_formatter.rb +70 -0
  10. data/lib/rspec/core/configuration.rb +479 -577
  11. data/lib/rspec/core/configuration_options.rb +71 -54
  12. data/lib/rspec/core/drb.rb +111 -0
  13. data/lib/rspec/core/dsl.rb +86 -18
  14. data/lib/rspec/core/example.rb +267 -119
  15. data/lib/rspec/core/example_group.rb +381 -393
  16. data/lib/rspec/core/filter_manager.rb +133 -114
  17. data/lib/rspec/core/flat_map.rb +18 -0
  18. data/lib/rspec/core/formatters/base_formatter.rb +51 -125
  19. data/lib/rspec/core/formatters/base_text_formatter.rb +34 -286
  20. data/lib/rspec/core/formatters/console_codes.rb +24 -1
  21. data/lib/rspec/core/formatters/deprecation_formatter.rb +25 -26
  22. data/lib/rspec/core/formatters/documentation_formatter.rb +27 -25
  23. data/lib/rspec/core/formatters/helpers.rb +14 -36
  24. data/lib/rspec/core/formatters/html_formatter.rb +58 -65
  25. data/lib/rspec/core/formatters/html_printer.rb +12 -18
  26. data/lib/rspec/core/formatters/json_formatter.rb +54 -31
  27. data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
  28. data/lib/rspec/core/formatters/progress_formatter.rb +11 -15
  29. data/lib/rspec/core/formatters/snippet_extractor.rb +22 -11
  30. data/lib/rspec/core/formatters.rb +90 -43
  31. data/lib/rspec/core/hooks.rb +325 -270
  32. data/lib/rspec/core/memoized_helpers.rb +45 -156
  33. data/lib/rspec/core/metadata.rb +284 -236
  34. data/lib/rspec/core/metadata_filter.rb +86 -0
  35. data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
  36. data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
  37. data/lib/rspec/core/mocking_adapters/null.rb +12 -0
  38. data/lib/rspec/core/mocking_adapters/rr.rb +29 -0
  39. data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
  40. data/lib/rspec/core/notifications.rb +511 -0
  41. data/lib/rspec/core/option_parser.rb +49 -74
  42. data/lib/rspec/core/ordering.rb +156 -0
  43. data/lib/rspec/core/pending.rb +94 -96
  44. data/lib/rspec/core/project_initializer/.rspec +3 -0
  45. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +78 -0
  46. data/lib/rspec/core/project_initializer.rb +24 -64
  47. data/lib/rspec/core/rake_task.rb +44 -130
  48. data/lib/rspec/core/reporter.rb +76 -59
  49. data/lib/rspec/core/ruby_project.rb +2 -1
  50. data/lib/rspec/core/runner.rb +117 -52
  51. data/lib/rspec/core/shared_context.rb +10 -10
  52. data/lib/rspec/core/shared_example_group.rb +108 -121
  53. data/lib/rspec/core/version.rb +3 -1
  54. data/lib/rspec/core/warnings.rb +40 -0
  55. data/lib/rspec/core/world.rb +66 -10
  56. data/lib/rspec/core.rb +64 -104
  57. data.tar.gz.sig +3 -0
  58. metadata +75 -322
  59. metadata.gz.sig +1 -0
  60. data/exe/autospec +0 -13
  61. data/features/Autotest.md +0 -38
  62. data/features/README.md +0 -17
  63. data/features/Upgrade.md +0 -364
  64. data/features/command_line/README.md +0 -28
  65. data/features/command_line/example_name_option.feature +0 -97
  66. data/features/command_line/exit_status.feature +0 -82
  67. data/features/command_line/format_option.feature +0 -75
  68. data/features/command_line/init.feature +0 -18
  69. data/features/command_line/line_number_appended_to_path.feature +0 -140
  70. data/features/command_line/line_number_option.feature +0 -53
  71. data/features/command_line/order.feature +0 -26
  72. data/features/command_line/pattern_option.feature +0 -49
  73. data/features/command_line/rake_task.feature +0 -122
  74. data/features/command_line/require_option.feature +0 -43
  75. data/features/command_line/ruby.feature +0 -22
  76. data/features/command_line/tag.feature +0 -98
  77. data/features/command_line/warnings_option.feature +0 -29
  78. data/features/configuration/alias_example_to.feature +0 -48
  79. data/features/configuration/backtrace_clean_patterns.feature +0 -102
  80. data/features/configuration/custom_settings.feature +0 -84
  81. data/features/configuration/default_path.feature +0 -38
  82. data/features/configuration/deprecation_stream.feature +0 -58
  83. data/features/configuration/fail_fast.feature +0 -77
  84. data/features/configuration/failure_exit_code.feature +0 -36
  85. data/features/configuration/order_and_seed.feature +0 -3
  86. data/features/configuration/output_stream.feature +0 -24
  87. data/features/configuration/pattern.feature +0 -38
  88. data/features/configuration/profile.feature +0 -220
  89. data/features/configuration/read_options_from_file.feature +0 -90
  90. data/features/configuration/run_all_when_everything_filtered.feature +0 -76
  91. data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
  92. data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
  93. data/features/example_groups/basic_structure.feature +0 -55
  94. data/features/example_groups/shared_context.feature +0 -74
  95. data/features/example_groups/shared_examples.feature +0 -294
  96. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -197
  97. data/features/filtering/exclusion_filters.feature +0 -138
  98. data/features/filtering/if_and_unless.feature +0 -168
  99. data/features/filtering/inclusion_filters.feature +0 -105
  100. data/features/formatters/configurable_colors.feature +0 -31
  101. data/features/formatters/custom_formatter.feature +0 -36
  102. data/features/formatters/json_formatter.feature +0 -30
  103. data/features/formatters/text_formatter.feature +0 -46
  104. data/features/helper_methods/arbitrary_methods.feature +0 -40
  105. data/features/helper_methods/let.feature +0 -50
  106. data/features/helper_methods/modules.feature +0 -149
  107. data/features/hooks/around_hooks.feature +0 -343
  108. data/features/hooks/before_and_after_hooks.feature +0 -427
  109. data/features/hooks/filtering.feature +0 -234
  110. data/features/metadata/current_example.feature +0 -56
  111. data/features/metadata/described_class.feature +0 -17
  112. data/features/metadata/user_defined.feature +0 -113
  113. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  114. data/features/mock_framework_integration/use_flexmock.feature +0 -96
  115. data/features/mock_framework_integration/use_mocha.feature +0 -97
  116. data/features/mock_framework_integration/use_rr.feature +0 -98
  117. data/features/mock_framework_integration/use_rspec.feature +0 -97
  118. data/features/pending/pending_examples.feature +0 -229
  119. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  120. data/features/step_definitions/additional_cli_steps.rb +0 -49
  121. data/features/subject/attribute_of_subject.feature +0 -124
  122. data/features/subject/explicit_subject.feature +0 -101
  123. data/features/subject/implicit_subject.feature +0 -63
  124. data/features/subject/one_liner_syntax.feature +0 -71
  125. data/features/support/env.rb +0 -14
  126. data/features/support/rubinius.rb +0 -6
  127. data/lib/autotest/discover.rb +0 -10
  128. data/lib/autotest/rspec2.rb +0 -77
  129. data/lib/rspec/core/backtrace_cleaner.rb +0 -46
  130. data/lib/rspec/core/backward_compatibility.rb +0 -55
  131. data/lib/rspec/core/caller_filter.rb +0 -60
  132. data/lib/rspec/core/command_line.rb +0 -47
  133. data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
  134. data/lib/rspec/core/deprecation.rb +0 -26
  135. data/lib/rspec/core/drb_command_line.rb +0 -26
  136. data/lib/rspec/core/drb_options.rb +0 -87
  137. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  138. data/lib/rspec/core/extensions/kernel.rb +0 -9
  139. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  140. data/lib/rspec/core/extensions/ordered.rb +0 -27
  141. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  142. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  143. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  144. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  145. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  146. data/lib/rspec/core/mocking/with_rspec.rb +0 -27
  147. data/lib/rspec/core/shared_example_group/collection.rb +0 -45
  148. data/spec/autotest/discover_spec.rb +0 -49
  149. data/spec/autotest/failed_results_re_spec.rb +0 -45
  150. data/spec/autotest/rspec_spec.rb +0 -133
  151. data/spec/command_line/order_spec.rb +0 -204
  152. data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
  153. data/spec/rspec/core/caller_filter_spec.rb +0 -58
  154. data/spec/rspec/core/command_line_spec.rb +0 -127
  155. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  156. data/spec/rspec/core/configuration_options_spec.rb +0 -417
  157. data/spec/rspec/core/configuration_spec.rb +0 -2072
  158. data/spec/rspec/core/deprecation_spec.rb +0 -27
  159. data/spec/rspec/core/deprecations_spec.rb +0 -59
  160. data/spec/rspec/core/drb_command_line_spec.rb +0 -102
  161. data/spec/rspec/core/drb_options_spec.rb +0 -193
  162. data/spec/rspec/core/dsl_spec.rb +0 -25
  163. data/spec/rspec/core/example_group_spec.rb +0 -1337
  164. data/spec/rspec/core/example_spec.rb +0 -502
  165. data/spec/rspec/core/filter_manager_spec.rb +0 -246
  166. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -108
  167. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -524
  168. data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
  169. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -263
  170. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -89
  171. data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
  172. data/spec/rspec/core/formatters/html_formatted.html +0 -397
  173. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -131
  174. data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -115
  175. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
  176. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
  177. data/spec/rspec/core/formatters/text_mate_formatted.html +0 -397
  178. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
  179. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  180. data/spec/rspec/core/hooks_spec.rb +0 -269
  181. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  182. data/spec/rspec/core/memoized_helpers_spec.rb +0 -776
  183. data/spec/rspec/core/metadata_spec.rb +0 -514
  184. data/spec/rspec/core/option_parser_spec.rb +0 -297
  185. data/spec/rspec/core/pending_example_spec.rb +0 -260
  186. data/spec/rspec/core/pending_spec.rb +0 -27
  187. data/spec/rspec/core/project_initializer_spec.rb +0 -130
  188. data/spec/rspec/core/rake_task_spec.rb +0 -202
  189. data/spec/rspec/core/reporter_spec.rb +0 -167
  190. data/spec/rspec/core/resources/a_bar.rb +0 -0
  191. data/spec/rspec/core/resources/a_foo.rb +0 -0
  192. data/spec/rspec/core/resources/a_spec.rb +0 -1
  193. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  194. data/spec/rspec/core/resources/formatter_specs.rb +0 -60
  195. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  196. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  197. data/spec/rspec/core/ruby_project_spec.rb +0 -26
  198. data/spec/rspec/core/runner_spec.rb +0 -82
  199. data/spec/rspec/core/shared_context_spec.rb +0 -114
  200. data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -70
  201. data/spec/rspec/core/shared_example_group_spec.rb +0 -138
  202. data/spec/rspec/core/world_spec.rb +0 -142
  203. data/spec/rspec/core_spec.rb +0 -108
  204. data/spec/spec_helper.rb +0 -135
  205. data/spec/support/config_options_helper.rb +0 -15
  206. data/spec/support/helper_methods.rb +0 -55
  207. data/spec/support/in_sub_process.rb +0 -37
  208. data/spec/support/isolate_load_path_mutation.rb +0 -6
  209. data/spec/support/isolated_directory.rb +0 -10
  210. data/spec/support/isolated_home_directory.rb +0 -16
  211. data/spec/support/matchers.rb +0 -65
  212. data/spec/support/mathn_integration_support.rb +0 -12
  213. data/spec/support/sandboxed_mock_space.rb +0 -116
  214. data/spec/support/shared_example_groups.rb +0 -42
  215. data/spec/support/silence_dsl_deprecations.rb +0 -32
  216. data/spec/support/spec_files.rb +0 -44
@@ -1,76 +1,104 @@
1
1
  require 'erb'
2
2
  require 'shellwords'
3
+ require 'set'
3
4
 
4
5
  module RSpec
5
6
  module Core
6
- # @private
7
+ # Responsible for utilizing externally provided configuration options,
8
+ # whether via the command line, `.rspec`, `~/.rspec`, `.rspec-local`
9
+ # or a custom options file.
7
10
  class ConfigurationOptions
8
- attr_reader :options
9
-
11
+ # @param args [Array<String>] command line arguments
10
12
  def initialize(args)
11
13
  @args = args.dup
12
- if @args.include?("--default_path")
13
- @args[@args.index("--default_path")] = "--default-path"
14
- end
15
-
16
- if @args.include?("--line_number")
17
- @args[@args.index("--line_number")] = "--line-number"
18
- end
14
+ organize_options
19
15
  end
20
16
 
17
+ # Updates the provided {Configuration} instance based on the provided
18
+ # external configuration options.
19
+ #
20
+ # @param config [Configuration] the configuration instance to update
21
21
  def configure(config)
22
- config.filter_manager = filter_manager
23
-
24
- config.libs = options[:libs] || []
25
- config.setup_load_path_and_require(options[:requires] || [])
26
-
27
22
  process_options_into config
23
+ configure_filter_manager config.filter_manager
28
24
  load_formatters_into config
29
25
  end
30
26
 
31
- def parse_options
32
- @options ||= extract_filters_from(*all_configs).inject do |merged, pending|
33
- merged.merge(pending) { |key, oldval, newval|
34
- MERGED_OPTIONS.include?(key) ? oldval + newval : newval
35
- }
36
- end
37
- end
38
-
39
- def drb_argv
40
- DrbOptions.new(options, filter_manager).options
27
+ # @api private
28
+ # Updates the provided {FilterManager} based on the filter options.
29
+ # @param filter_manager [FilterManager] instance to update
30
+ def configure_filter_manager(filter_manager)
31
+ @filter_manager_inclusions.each { |val| filter_manager.include(val) }
32
+ @filter_manager_exclusions.each { |val| filter_manager.exclude(val) }
41
33
  end
42
34
 
43
- def filter_manager
44
- @filter_manager ||= RSpec::configuration.filter_manager
45
- end
35
+ # @return [Hash] the final merged options, drawn from all external sources
36
+ attr_reader :options
46
37
 
47
38
  private
48
39
 
49
- NON_FORCED_OPTIONS = [
50
- :debug, :requires, :profile, :drb, :libs, :files_or_directories_to_run,
51
- :line_numbers, :full_description, :full_backtrace, :tty
52
- ].to_set
40
+ def organize_options
41
+ @filter_manager_inclusions = []
42
+ @filter_manager_exclusions = []
53
43
 
54
- MERGED_OPTIONS = [:requires, :libs].to_set
44
+ @options = (file_options << command_line_options << env_options).each { |opts|
45
+ @filter_manager_inclusions << opts.delete(:inclusion_filter) if opts.key?(:inclusion_filter)
46
+ @filter_manager_exclusions << opts.delete(:exclusion_filter) if opts.key?(:exclusion_filter)
47
+ }.inject(:libs => [], :requires => []) { |hash, opts|
48
+ hash.merge(opts) { |key, oldval, newval|
49
+ [:libs, :requires].include?(key) ? oldval + newval : newval
50
+ }
51
+ }
52
+ end
53
+
54
+ UNFORCED_OPTIONS = [
55
+ :requires, :profile, :drb, :libs, :files_or_directories_to_run,
56
+ :full_description, :full_backtrace, :tty
57
+ ].to_set
55
58
 
56
- UNPROCESSABLE_OPTIONS = [:libs, :formatters, :requires].to_set
59
+ UNPROCESSABLE_OPTIONS = [:formatters].to_set
57
60
 
58
61
  def force?(key)
59
- !NON_FORCED_OPTIONS.include?(key)
62
+ !UNFORCED_OPTIONS.include?(key)
60
63
  end
61
64
 
62
- def order(keys, *ordered)
63
- ordered.reverse.each do |key|
65
+ def order(keys)
66
+ OPTIONS_ORDER.reverse.each do |key|
64
67
  keys.unshift(key) if keys.delete(key)
65
68
  end
66
69
  keys
67
70
  end
68
71
 
72
+ OPTIONS_ORDER = [
73
+ # It's important to set this before anything that might issue a
74
+ # deprecation (or otherwise access the reporter).
75
+ :deprecation_stream,
76
+
77
+ # load paths depend on nothing, but must be set before `requires`
78
+ # to support load-path-relative requires.
79
+ :libs,
80
+
81
+ # `files_or_directories_to_run` uses `default_path` so it must be
82
+ # set before it.
83
+ :default_path,
84
+
85
+ # must be set before `requires` to support checking `config.files_to_run`
86
+ # from within `spec_helper.rb` when a `-rspec_helper` option is used.
87
+ :files_or_directories_to_run,
88
+
89
+ # In general, we want to require the specified files as early as possible.
90
+ # The `--require` option is specifically intended to allow early requires.
91
+ # For later requires, they can just put the require in their spec files, but
92
+ # `--require` provides a unique opportunity for users to instruct RSpec to
93
+ # load an extension file early for maximum flexibility.
94
+ :requires
95
+ ]
96
+
69
97
  def process_options_into(config)
70
98
  opts = options.reject { |k, _| UNPROCESSABLE_OPTIONS.include? k }
71
99
 
72
- order(opts.keys, :default_path, :pattern).each do |key|
73
- force?(key) ? config.force(key => opts[key]) : config.send("#{key}=", opts[key])
100
+ order(opts.keys).each do |key|
101
+ force?(key) ? config.force(key => opts[key]) : config.__send__("#{key}=", opts[key])
74
102
  end
75
103
  end
76
104
 
@@ -78,27 +106,16 @@ module RSpec
78
106
  options[:formatters].each { |pair| config.add_formatter(*pair) } if options[:formatters]
79
107
  end
80
108
 
81
- def extract_filters_from(*configs)
82
- configs.compact.each do |config|
83
- filter_manager.include config.delete(:inclusion_filter) if config.has_key?(:inclusion_filter)
84
- filter_manager.exclude config.delete(:exclusion_filter) if config.has_key?(:exclusion_filter)
85
- end
86
- end
87
-
88
- def all_configs
89
- @all_configs ||= file_options << command_line_options << env_options
90
- end
91
-
92
109
  def file_options
93
110
  custom_options_file ? [custom_options] : [global_options, project_options, local_options]
94
111
  end
95
112
 
96
113
  def env_options
97
- ENV["SPEC_OPTS"] ? Parser.parse!(Shellwords.split(ENV["SPEC_OPTS"])) : {}
114
+ ENV["SPEC_OPTS"] ? Parser.parse(Shellwords.split(ENV["SPEC_OPTS"])) : {}
98
115
  end
99
116
 
100
117
  def command_line_options
101
- @command_line_options ||= Parser.parse!(@args).merge :files_or_directories_to_run => @args
118
+ @command_line_options ||= Parser.parse(@args).merge :files_or_directories_to_run => @args
102
119
  end
103
120
 
104
121
  def custom_options
@@ -124,7 +141,7 @@ module RSpec
124
141
  def args_from_options_file(path)
125
142
  return [] unless path && File.exist?(path)
126
143
  config_string = options_file_as_erb_string(path)
127
- config_string.split(/\n+/).map {|l| Shellwords.shellwords(l) }.flatten
144
+ FlatMap.flat_map(config_string.split(/\n+/), &:shellsplit)
128
145
  end
129
146
 
130
147
  def options_file_as_erb_string(path)
@@ -147,7 +164,7 @@ module RSpec
147
164
  begin
148
165
  File.join(File.expand_path("~"), ".rspec")
149
166
  rescue ArgumentError
150
- warn "Unable to find ~/.rspec because the HOME environment variable is not set"
167
+ RSpec.warning "Unable to find ~/.rspec because the HOME environment variable is not set"
151
168
  nil
152
169
  end
153
170
  end
@@ -0,0 +1,111 @@
1
+ require 'drb/drb'
2
+
3
+ module RSpec
4
+ module Core
5
+ # @private
6
+ class DRbRunner
7
+ def initialize(options, configuration=RSpec.configuration)
8
+ @options = options
9
+ @configuration = configuration
10
+ end
11
+
12
+ def drb_port
13
+ @options.options[:drb_port] || ENV['RSPEC_DRB'] || 8989
14
+ end
15
+
16
+ def run(err, out)
17
+ begin
18
+ DRb.start_service("druby://localhost:0")
19
+ rescue SocketError, Errno::EADDRNOTAVAIL
20
+ DRb.start_service("druby://:0")
21
+ end
22
+ spec_server = DRbObject.new_with_uri("druby://127.0.0.1:#{drb_port}")
23
+ spec_server.run(drb_argv, err, out)
24
+ end
25
+
26
+ def drb_argv
27
+ @drb_argv ||= begin
28
+ @options.configure_filter_manager(@configuration.filter_manager)
29
+ DRbOptions.new(@options.options, @configuration.filter_manager).options
30
+ end
31
+ end
32
+ end
33
+
34
+ # @private
35
+ class DRbOptions
36
+ def initialize(submitted_options, filter_manager)
37
+ @submitted_options = submitted_options
38
+ @filter_manager = filter_manager
39
+ end
40
+
41
+ def options
42
+ argv = []
43
+ argv << "--color" if @submitted_options[:color]
44
+ argv << "--profile" if @submitted_options[:profile_examples]
45
+ argv << "--backtrace" if @submitted_options[:full_backtrace]
46
+ argv << "--tty" if @submitted_options[:tty]
47
+ argv << "--fail-fast" if @submitted_options[:fail_fast]
48
+ argv << "--options" << @submitted_options[:custom_options_file] if @submitted_options[:custom_options_file]
49
+ argv << "--order" << @submitted_options[:order] if @submitted_options[:order]
50
+
51
+ add_failure_exit_code(argv)
52
+ add_full_description(argv)
53
+ add_filter(argv, :inclusion, @filter_manager.inclusions)
54
+ add_filter(argv, :exclusion, @filter_manager.exclusions)
55
+ add_formatters(argv)
56
+ add_libs(argv)
57
+ add_requires(argv)
58
+
59
+ argv + @submitted_options[:files_or_directories_to_run]
60
+ end
61
+
62
+ def add_failure_exit_code(argv)
63
+ if @submitted_options[:failure_exit_code]
64
+ argv << "--failure-exit-code" << @submitted_options[:failure_exit_code].to_s
65
+ end
66
+ end
67
+
68
+ def add_full_description(argv)
69
+ if @submitted_options[:full_description]
70
+ # The argument to --example is regexp-escaped before being stuffed
71
+ # into a regexp when received for the first time (see OptionParser).
72
+ # Hence, merely grabbing the source of this regexp will retain the
73
+ # backslashes, so we must remove them.
74
+ @submitted_options[:full_description].each do |description|
75
+ argv << "--example" << description.source.delete('\\')
76
+ end
77
+ end
78
+ end
79
+
80
+ CONDITIONAL_FILTERS = [:if, :unless]
81
+
82
+ def add_filter(argv, name, hash)
83
+ hash.each_pair do |k, v|
84
+ next if CONDITIONAL_FILTERS.include?(k)
85
+ tag = name == :inclusion ? k.to_s : "~#{k}"
86
+ tag << ":#{v}" if v.is_a?(String)
87
+ argv << "--tag" << tag
88
+ end unless hash.empty?
89
+ end
90
+
91
+ def add_formatters(argv)
92
+ @submitted_options[:formatters].each do |pair|
93
+ argv << "--format" << pair[0]
94
+ argv << "--out" << pair[1] if pair[1]
95
+ end if @submitted_options[:formatters]
96
+ end
97
+
98
+ def add_libs(argv)
99
+ @submitted_options[:libs].each do |path|
100
+ argv << "-I" << path
101
+ end if @submitted_options[:libs]
102
+ end
103
+
104
+ def add_requires(argv)
105
+ @submitted_options[:requires].each do |path|
106
+ argv << "--require" << path
107
+ end if @submitted_options[:requires]
108
+ end
109
+ end
110
+ end
111
+ end
@@ -1,26 +1,94 @@
1
1
  module RSpec
2
2
  module Core
3
- # Adds the `describe` method to the top-level namespace.
3
+ # DSL defines methods to group examples, most notably `describe`,
4
+ # and exposes them as class methods of {RSpec}. They can also be
5
+ # exposed globally (on `main` and instances of `Module`) through
6
+ # the {Configuration} option `expose_dsl_globally`.
7
+ #
8
+ # By default the methods `describe`, `context` and `example_group`
9
+ # are exposed. These methods define a named context for one or
10
+ # more examples. The given block is evaluated in the context of
11
+ # a generated subclass of {RSpec::Core::ExampleGroup}
12
+ #
13
+ # ## Examples:
14
+ #
15
+ # RSpec.describe "something" do
16
+ # context "when something is a certain way" do
17
+ # it "does something" do
18
+ # # example code goes here
19
+ # end
20
+ # end
21
+ # end
22
+ #
23
+ # @see ExampleGroup
24
+ # @see ExampleGroup.example_group
4
25
  module DSL
5
- # Generates a subclass of {ExampleGroup}
6
- #
7
- # ## Examples:
8
- #
9
- # describe "something" do
10
- # it "does something" do
11
- # # example code goes here
12
- # end
13
- # end
14
- #
15
- # @see ExampleGroup
16
- # @see ExampleGroup.describe
17
- def describe(*args, &example_group_block)
18
- RSpec::Core::ExampleGroup.describe(*args, &example_group_block).register
26
+ # @private
27
+ def self.example_group_aliases
28
+ @example_group_aliases ||= []
19
29
  end
30
+
31
+ # @private
32
+ def self.exposed_globally?
33
+ @exposed_globally ||= false
34
+ end
35
+
36
+ # @private
37
+ def self.expose_example_group_alias(name)
38
+ example_group_aliases << name
39
+
40
+ (class << RSpec; self; end).__send__(:define_method, name) do |*args, &example_group_block|
41
+ RSpec.world.register RSpec::Core::ExampleGroup.__send__(name, *args, &example_group_block)
42
+ end
43
+
44
+ expose_example_group_alias_globally(name) if exposed_globally?
45
+ end
46
+
47
+ class << self
48
+ # @private
49
+ attr_accessor :top_level
50
+ end
51
+
52
+ # Adds the describe method to Module and the top level binding
53
+ # @api private
54
+ def self.expose_globally!
55
+ return if exposed_globally?
56
+
57
+ example_group_aliases.each do |method_name|
58
+ expose_example_group_alias_globally(method_name)
59
+ end
60
+
61
+ @exposed_globally = true
62
+ end
63
+
64
+ # Removes the describe method from Module and the top level binding
65
+ # @api private
66
+ def self.remove_globally!
67
+ return unless exposed_globally?
68
+
69
+ example_group_aliases.each do |method_name|
70
+ change_global_dsl { undef_method method_name }
71
+ end
72
+
73
+ @exposed_globally = false
74
+ end
75
+
76
+ # @private
77
+ def self.expose_example_group_alias_globally(method_name)
78
+ change_global_dsl do
79
+ define_method(method_name) { |*a, &b| ::RSpec.__send__(method_name, *a, &b) }
80
+ end
81
+ end
82
+
83
+ # @private
84
+ def self.change_global_dsl(&changes)
85
+ (class << top_level; self; end).class_exec(&changes)
86
+ Module.class_exec(&changes)
87
+ end
88
+
20
89
  end
21
90
  end
22
91
  end
23
92
 
24
- extend RSpec::Core::DSL
25
- Module.send(:include, RSpec::Core::DSL)
26
-
93
+ # capture main without an eval
94
+ ::RSpec::Core::DSL.top_level = self