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,68 +0,0 @@
1
- require "spec_helper"
2
-
3
- module RSpec::Core
4
- describe BacktraceCleaner do
5
- context "with no patterns" do
6
- it "keeps all lines" do
7
- lines = ["/tmp/a_file", "some_random_text", "hello\330\271!"]
8
- cleaner = BacktraceCleaner.new([], [])
9
- expect(lines.all? {|line| cleaner.exclude? line}).to be_falsey
10
- end
11
-
12
- it 'is considered a full backtrace' do
13
- expect(BacktraceCleaner.new([], []).full_backtrace?).to be_truthy
14
- end
15
- end
16
-
17
- context "with an exclusion pattern but no inclusion patterns" do
18
- it "excludes lines that match the exclusion pattern" do
19
- cleaner = BacktraceCleaner.new([], [/remove/])
20
- expect(cleaner.exclude? "remove me").to be_truthy
21
- end
22
-
23
- it "keeps lines that do not match the exclusion pattern" do
24
- cleaner = BacktraceCleaner.new([], [/remove/])
25
- expect(cleaner.exclude? "apple").to be_falsey
26
- end
27
-
28
- it 'is considered a partial backtrace' do
29
- expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_falsey
30
- end
31
- end
32
-
33
- context "with an exclusion pattern and an inclusion pattern" do
34
- it "excludes lines that match the exclusion pattern but not the inclusion pattern" do
35
- cleaner = BacktraceCleaner.new([/keep/], [/discard/])
36
- expect(cleaner.exclude? "discard").to be_truthy
37
- end
38
-
39
- it "keeps lines that match the inclusion pattern and the exclusion pattern" do
40
- cleaner = BacktraceCleaner.new([/hi/], [/.*/])
41
- expect(cleaner.exclude? "hi").to be_falsey
42
- end
43
-
44
- it "keeps lines that match neither pattern" do
45
- cleaner = BacktraceCleaner.new([/hi/], [/delete/])
46
- expect(cleaner.exclude? "fish").to be_falsey
47
- end
48
-
49
- it 'is considered a partial backtrace' do
50
- expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_falsey
51
- end
52
- end
53
-
54
- context "with an exclusion pattern that matches the current working directory" do
55
- it "defaults to having one inclusion pattern, the current working directory" do
56
- cleaner = BacktraceCleaner.new(nil, [/.*/])
57
- expect(Dir.getwd =~ cleaner.inclusion_patterns.first).to be_truthy
58
- end
59
- end
60
-
61
- context "with an exclusion pattern that does not match the current working directory" do
62
- it "defaults to having no exclusion patterns" do
63
- cleaner = BacktraceCleaner.new(nil, [/i_wont_match_a_directory/])
64
- expect(cleaner.inclusion_patterns.length).to be_zero
65
- end
66
- end
67
- end
68
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
- require 'rspec/core/caller_filter'
3
-
4
- module RSpec
5
- describe CallerFilter do
6
- def ruby_files_in_lib(lib)
7
- # http://rubular.com/r/HYpUMftlG2
8
- path = $LOAD_PATH.find { |p| p.match(/\/rspec-#{lib}(-[a-f0-9]+)?\/lib/) }
9
-
10
- unless path
11
- pending "Cannot locate rspec-#{lib} files."
12
- end
13
-
14
- Dir["#{path}/**/*.rb"].sort.tap do |files|
15
- # Just a sanity check...
16
- expect(files.count).to be > 10
17
- end
18
- end
19
-
20
- describe "the filtering regex" do
21
- def unmatched_from(files)
22
- files.reject { |file| file.match(CallerFilter::LIB_REGEX) }
23
- end
24
-
25
- %w[ core mocks expectations ].each do |lib|
26
- it "matches all ruby files in rspec-#{lib}" do
27
- files = ruby_files_in_lib(lib)
28
-
29
- files.reject! do |file|
30
- # We don't care about this file -- it only has a single require statement
31
- # and won't show up in any backtraces.
32
- file.end_with?('lib/rspec-expectations.rb') ||
33
-
34
- # This has a single require and a single deprecation, and won't be
35
- # in backtraces.
36
- file.end_with?('lib/spec/mocks.rb') ||
37
-
38
- # Autotest files are only loaded by the autotest executable
39
- # and not by the rspec command and thus won't be in backtraces.
40
- file.include?('autotest')
41
- end
42
-
43
- expect(unmatched_from files).to eq([])
44
- end
45
- end
46
-
47
- it "does not match other ruby files" do
48
- files = %w[
49
- /path/to/lib/rspec/some-extension/foo.rb
50
- /path/to/spec/rspec/core/some_spec.rb
51
- ]
52
-
53
- expect(unmatched_from files).to eq(files)
54
- end
55
- end
56
- end
57
- end
58
-
@@ -1,127 +0,0 @@
1
- require "spec_helper"
2
- require "stringio"
3
- require 'tmpdir'
4
-
5
- module RSpec::Core
6
- describe Runner do
7
-
8
- let(:out) { StringIO.new }
9
- let(:err) { StringIO.new }
10
- let(:config) { RSpec::configuration }
11
- let(:world) { RSpec::world }
12
-
13
- before { config.stub :run_hook }
14
-
15
- it "configures streams before command line options" do
16
- config.stub(:reporter => double.as_null_object)
17
- config.stub :load_spec_files
18
-
19
- # this is necessary to ensure that color works correctly on windows
20
- config.should_receive(:error_stream=).ordered
21
- config.should_receive(:output_stream=).ordered
22
- config.should_receive(:force).at_least(:once).ordered
23
-
24
- runner = build_runner
25
- runner.run err, out
26
- end
27
-
28
- it "assigns submitted ConfigurationOptions to @options" do
29
- config_options = ConfigurationOptions.new(%w[--color])
30
- runner = Runner.new(config_options)
31
- expect(runner.instance_eval { @options }).to be(config_options)
32
- end
33
-
34
- describe "#run" do
35
- context "running files" do
36
- include_context "spec files"
37
-
38
- it "returns 0 if spec passes" do
39
- runner = build_runner passing_spec_filename
40
- expect(runner.run(err, out)).to eq 0
41
- end
42
-
43
- it "returns 1 if spec fails" do
44
- runner = build_runner failing_spec_filename
45
- expect(runner.run(err, out)).to eq 1
46
- end
47
-
48
- it "returns 2 if spec fails and --failure-exit-code is 2" do
49
- runner = build_runner failing_spec_filename, "--failure-exit-code", "2"
50
- expect(runner.run(err, out)).to eq 2
51
- end
52
- end
53
-
54
- context "running hooks" do
55
- before { config.stub :load_spec_files }
56
-
57
- it "runs before suite hooks" do
58
- config.should_receive(:run_hook).with(:before, :suite)
59
- runner = build_runner
60
- runner.run err, out
61
- end
62
-
63
- it "runs after suite hooks" do
64
- config.should_receive(:run_hook).with(:after, :suite)
65
- runner = build_runner
66
- runner.run err, out
67
- end
68
-
69
- it "runs after suite hooks even after an error" do
70
- config.should_receive(:run_hook).with(:before, :suite).and_raise "this error"
71
- config.should_receive(:run_hook).with(:after , :suite)
72
- expect do
73
- runner = build_runner
74
- runner.run err, out
75
- end.to raise_error
76
- end
77
- end
78
- end
79
-
80
- describe "#run with custom output" do
81
- before { config.stub :files_to_run => [] }
82
-
83
- let(:output_file) { File.new("#{Dir.tmpdir}/runner_spec_output.txt", 'w') }
84
-
85
- it "doesn't override output_stream" do
86
- config.output_stream = output_file
87
- runner = build_runner
88
- runner.run err, out
89
- expect(runner.instance_eval { @configuration.output_stream }).to eq output_file
90
- end
91
- end
92
-
93
- def build_runner *args
94
- Runner.new build_config_options(*args)
95
- end
96
-
97
- def build_config_options *args
98
- options = ConfigurationOptions.new args
99
- options.parse_options
100
- options
101
- end
102
- end
103
-
104
- describe CommandLine do
105
- it 'is a subclass of `Runner` so that it inherits the same behavior' do
106
- expect(CommandLine.superclass).to be(Runner)
107
- end
108
-
109
- it 'prints a deprecation when instantiated' do
110
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /RSpec::Core::CommandLine/)
111
- CommandLine.new(ConfigurationOptions.new([]))
112
- end
113
-
114
- context "when given an array as the first arg" do
115
- it 'parses it into configuration options' do
116
- cl = CommandLine.new(%w[ --require foo ])
117
- options = cl.instance_eval { @options }
118
- expect(options.options).to include(:requires => ['foo'])
119
- end
120
-
121
- it 'issues a deprecation about the array arg' do
122
- expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /array/)
123
- CommandLine.new(%w[ --require foo ])
124
- end
125
- end
126
- end
127
- end
File without changes
@@ -1,417 +0,0 @@
1
- require 'spec_helper'
2
- require 'ostruct'
3
- require 'rspec/core/drb_options'
4
-
5
- describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolated_home => true do
6
- include ConfigOptionsHelper
7
-
8
- it "warns when HOME env var is not set", :unless => (RUBY_PLATFORM == 'java') do
9
- without_env_vars 'HOME' do
10
- coo = RSpec::Core::ConfigurationOptions.new([])
11
- coo.should_receive(:warn)
12
- coo.parse_options
13
- end
14
- end
15
-
16
- it "duplicates the arguments array" do
17
- args = ['-e', 'some spec']
18
- coo = RSpec::Core::ConfigurationOptions.new(args)
19
- coo.parse_options
20
- expect(args).to eq(['-e', 'some spec'])
21
- end
22
-
23
- describe "#configure" do
24
- it "sends libs before requires" do
25
- opts = config_options_object(*%w[--require a/path -I a/lib])
26
- config = double("config").as_null_object
27
- config.should_receive(:libs=).ordered
28
- config.should_receive(:setup_load_path_and_require).ordered
29
- opts.configure(config)
30
- end
31
-
32
- it "sends loads requires before loading specs" do
33
- opts = config_options_object(*%w[-rspec_helper])
34
- config = double("config").as_null_object
35
- expect(config).to receive(:setup_load_path_and_require).ordered
36
- expect(config).to receive(:files_or_directories_to_run=).ordered
37
- opts.configure(config)
38
- end
39
-
40
- it "sets up load path and requires before formatter" do
41
- opts = config_options_object(*%w[--require a/path -f a/formatter])
42
- config = double("config").as_null_object
43
- config.should_receive(:setup_load_path_and_require).ordered
44
- config.should_receive(:add_formatter).ordered
45
- opts.configure(config)
46
- end
47
-
48
- it "sends default_path before files_or_directories_to_run" do
49
- opts = config_options_object(*%w[--default_path spec])
50
- config = double("config").as_null_object
51
- config.should_receive(:force).with(:default_path => 'spec').ordered
52
- config.should_receive(:files_or_directories_to_run=).ordered
53
- opts.configure(config)
54
- end
55
-
56
- it "sends pattern before files_or_directories_to_run" do
57
- opts = config_options_object(*%w[--pattern **/*.spec])
58
- config = double("config").as_null_object
59
- config.should_receive(:force).with(:pattern => '**/*.spec').ordered
60
- config.should_receive(:files_or_directories_to_run=).ordered
61
- opts.configure(config)
62
- end
63
-
64
- it "assigns inclusion_filter" do
65
- opts = config_options_object(*%w[--tag awesome])
66
- config = RSpec::Core::Configuration.new
67
- opts.configure(config)
68
- expect(config.inclusion_filter).to have_key(:awesome)
69
- end
70
-
71
- it "merges the :exclusion_filter option with the default exclusion_filter" do
72
- opts = config_options_object(*%w[--tag ~slow])
73
- config = RSpec::Core::Configuration.new
74
- opts.configure(config)
75
- expect(config.exclusion_filter).to have_key(:slow)
76
- end
77
-
78
- it "forces color" do
79
- opts = config_options_object(*%w[--color])
80
- config = RSpec::Core::Configuration.new
81
- config.should_receive(:force).with(:color => true)
82
- opts.configure(config)
83
- end
84
-
85
- [
86
- ["--failure-exit-code", "3", :failure_exit_code, 3 ],
87
- ["--pattern", "foo/bar", :pattern, "foo/bar"],
88
- ["--failure-exit-code", "37", :failure_exit_code, 37],
89
- ["--default_path", "behavior", :default_path, "behavior"],
90
- ["--order", "rand", :order, "rand"],
91
- ["--seed", "37", :order, "rand:37"],
92
- ["--drb-port", "37", :drb_port, 37]
93
- ].each do |cli_option, cli_value, config_key, config_value|
94
- it "forces #{config_key}" do
95
- opts = config_options_object(*[cli_option, cli_value].compact)
96
- config = RSpec::Core::Configuration.new
97
- config.should_receive(:force) do |pair|
98
- expect(pair.keys.first).to eq(config_key)
99
- expect(pair.values.first).to eq(config_value)
100
- end
101
- opts.configure(config)
102
- end
103
- end
104
-
105
- it "sets debug directly" do
106
- opts = config_options_object("--debug")
107
- config = RSpec::Core::Configuration.new
108
- config.should_receive(:debug=).with(:cli)
109
- opts.configure(config)
110
- end
111
-
112
- it "merges --require specified by multiple configuration sources" do
113
- with_env_vars 'SPEC_OPTS' => "--require file_from_env" do
114
- opts = config_options_object(*%w[--require file_from_opts])
115
- config = RSpec::Core::Configuration.new
116
- config.should_receive(:require).with("file_from_opts")
117
- config.should_receive(:require).with("file_from_env")
118
- opts.configure(config)
119
- end
120
- end
121
-
122
- it "merges --I specified by multiple configuration sources" do
123
- with_env_vars 'SPEC_OPTS' => "-I dir_from_env" do
124
- opts = config_options_object(*%w[-I dir_from_opts])
125
- config = RSpec::Core::Configuration.new
126
- config.should_receive(:libs=).with(["dir_from_opts", "dir_from_env"])
127
- opts.configure(config)
128
- end
129
- end
130
- end
131
-
132
- describe "-c, --color, and --colour" do
133
- it "sets :color => true" do
134
- expect(parse_options('-c')).to include(:color => true)
135
- expect(parse_options('--color')).to include(:color => true)
136
- expect(parse_options('--colour')).to include(:color => true)
137
- end
138
- end
139
-
140
- describe "--no-color" do
141
- it "sets :color => false" do
142
- expect(parse_options('--no-color')).to include(:color => false)
143
- end
144
-
145
- it "overrides previous :color => true" do
146
- expect(parse_options('--color', '--no-color')).to include(:color => false)
147
- end
148
-
149
- it "gets overriden by a subsequent :color => true" do
150
- expect(parse_options('--no-color', '--color')).to include(:color => true)
151
- end
152
- end
153
-
154
- describe "-I" do
155
- example "adds to :libs" do
156
- expect(parse_options('-I', 'a_dir')).to include(:libs => ['a_dir'])
157
- end
158
- example "can be used more than once" do
159
- expect(parse_options('-I', 'dir_1', '-I', 'dir_2')).to include(:libs => ['dir_1','dir_2'])
160
- end
161
- end
162
-
163
- describe '--require' do
164
- example "requires files" do
165
- expect(parse_options('--require', 'a/path')).to include(:requires => ['a/path'])
166
- end
167
- example "can be used more than once" do
168
- expect(parse_options('--require', 'path/1', '--require', 'path/2')).to include(:requires => ['path/1','path/2'])
169
- end
170
- end
171
-
172
- describe "--format, -f" do
173
- it "sets :formatter" do
174
- [['--format', 'd'], ['-f', 'd'], '-fd'].each do |args|
175
- expect(parse_options(*args)).to include(:formatters => [['d']])
176
- end
177
- end
178
-
179
- example "can accept a class name" do
180
- expect(parse_options('-fSome::Formatter::Class')).to include(:formatters => [['Some::Formatter::Class']])
181
- end
182
- end
183
-
184
- describe "--profile, -p" do
185
- it "sets :profile_examples" do
186
- expect(parse_options('-p')).to include(:profile_examples => true)
187
- expect(parse_options('--profile')).to include(:profile_examples => true)
188
- expect(parse_options('-p', '4')).to include(:profile_examples => 4)
189
- expect(parse_options('--profile', '3')).to include(:profile_examples => 3)
190
- end
191
- end
192
-
193
- describe "--no-profile" do
194
- it "sets :profile_examples to false" do
195
- expect(parse_options('--no-profile')).to include(:profile_examples => false)
196
- end
197
- end
198
-
199
- describe '--line_number' do
200
- it "sets :line_number" do
201
- expect(parse_options('-l','3')).to include(:line_numbers => ['3'])
202
- expect(parse_options('--line_number','3')).to include(:line_numbers => ['3'])
203
- end
204
-
205
- it "can be specified multiple times" do
206
- expect(parse_options('-l','3', '-l', '6')).to include(:line_numbers => ['3', '6'])
207
- expect(parse_options('--line_number','3', '--line_number', '6')).to include(:line_numbers => ['3', '6'])
208
- end
209
- end
210
-
211
- describe "--example" do
212
- it "sets :full_description" do
213
- expect(parse_options('--example','foo')).to include(:full_description => [/foo/])
214
- expect(parse_options('-e','bar')).to include(:full_description => [/bar/])
215
- end
216
- end
217
-
218
- describe "--backtrace, -b" do
219
- it "sets full_backtrace on config" do
220
- expect(parse_options("--backtrace")).to include(:full_backtrace => true)
221
- expect(parse_options("-b")).to include(:full_backtrace => true)
222
- end
223
- end
224
-
225
- describe "--debug, -d" do
226
- it "sets :debug => true" do
227
- expect(parse_options("--debug")).to include(:debug => :cli)
228
- expect(parse_options("-d")).to include(:debug => :cli)
229
- end
230
- end
231
-
232
- describe "--fail-fast" do
233
- it "defaults to false" do
234
- expect(parse_options[:fail_fast]).to be_falsey
235
- end
236
-
237
- it "sets fail_fast on config" do
238
- expect(parse_options("--fail-fast")[:fail_fast]).to be_truthy
239
- end
240
- end
241
-
242
- describe "--failure-exit-code" do
243
- it "sets :failure_exit_code" do
244
- expect(parse_options('--failure-exit-code', '0')).to include(:failure_exit_code => 0)
245
- expect(parse_options('--failure-exit-code', '1')).to include(:failure_exit_code => 1)
246
- expect(parse_options('--failure-exit-code', '2')).to include(:failure_exit_code => 2)
247
- end
248
-
249
- it "overrides previous :failure_exit_code" do
250
- expect(parse_options('--failure-exit-code', '2', '--failure-exit-code', '3')).to include(:failure_exit_code => 3)
251
- end
252
- end
253
-
254
- describe "--options" do
255
- it "sets :custom_options_file" do
256
- expect(parse_options(*%w[-O my.opts])).to include(:custom_options_file => "my.opts")
257
- expect(parse_options(*%w[--options my.opts])).to include(:custom_options_file => "my.opts")
258
- end
259
- end
260
-
261
- describe "--drb, -X" do
262
- context "combined with --debug" do
263
- it "turns off the debugger if --drb is specified first" do
264
- expect(config_options_object("--drb", "--debug").drb_argv).not_to include("--debug")
265
- expect(config_options_object("--drb", "-d" ).drb_argv).not_to include("--debug")
266
- expect(config_options_object("-X", "--debug").drb_argv).not_to include("--debug")
267
- expect(config_options_object("-X", "-d" ).drb_argv).not_to include("--debug")
268
- end
269
-
270
- it "turns off the debugger option if --drb is specified later" do
271
- expect(config_options_object("--debug", "--drb").drb_argv).not_to include("--debug")
272
- expect(config_options_object("-d", "--drb").drb_argv).not_to include("--debug")
273
- expect(config_options_object("--debug", "-X" ).drb_argv).not_to include("--debug")
274
- expect(config_options_object("-d", "-X" ).drb_argv).not_to include("--debug")
275
- end
276
-
277
- it "turns off the debugger option if --drb is specified in the options file" do
278
- File.open("./.rspec", "w") {|f| f << "--drb"}
279
- expect(config_options_object("--debug").drb_argv).not_to include("--debug")
280
- expect(config_options_object("-d" ).drb_argv).not_to include("--debug")
281
- end
282
-
283
- it "turns off the debugger option if --debug is specified in the options file" do
284
- File.open("./.rspec", "w") {|f| f << "--debug"}
285
- expect(config_options_object("--drb").drb_argv).not_to include("--debug")
286
- expect(config_options_object("-X" ).drb_argv).not_to include("--debug")
287
- end
288
- end
289
-
290
- it "does not send --drb back to the parser after parsing options" do
291
- expect(config_options_object("--drb", "--color").drb_argv).not_to include("--drb")
292
- end
293
-
294
- end
295
-
296
- describe "--no-drb" do
297
- it "disables drb" do
298
- expect(parse_options("--no-drb")).to include(:drb => false)
299
- end
300
-
301
- it "overrides a previous drb => true" do
302
- expect(parse_options("--drb", "--no-drb")).to include(:drb => false)
303
- end
304
-
305
- it "gets overriden by a subsquent drb => true" do
306
- expect(parse_options("--no-drb", "--drb")).to include(:drb => true)
307
- end
308
- end
309
-
310
-
311
- describe "files_or_directories_to_run" do
312
- it "parses files from '-c file.rb dir/file.rb'" do
313
- expect(parse_options("-c", "file.rb", "dir/file.rb")).to include(
314
- :files_or_directories_to_run => ["file.rb", "dir/file.rb"]
315
- )
316
- end
317
-
318
- it "parses dir from 'dir'" do
319
- expect(parse_options("dir")).to include(:files_or_directories_to_run => ["dir"])
320
- end
321
-
322
- it "parses dir and files from 'spec/file1_spec.rb, spec/file2_spec.rb'" do
323
- expect(parse_options("dir", "spec/file1_spec.rb", "spec/file2_spec.rb")).to include(
324
- :files_or_directories_to_run => ["dir", "spec/file1_spec.rb", "spec/file2_spec.rb"]
325
- )
326
- end
327
-
328
- it "provides no files or directories if spec directory does not exist" do
329
- FileTest.stub(:directory?).with("spec").and_return false
330
- expect(parse_options()).to include(:files_or_directories_to_run => [])
331
- end
332
- end
333
-
334
- describe "default_path" do
335
- it "gets set before files_or_directories_to_run" do
336
- config = double("config").as_null_object
337
- config.should_receive(:force).with(:default_path => 'foo').ordered
338
- config.should_receive(:files_or_directories_to_run=).ordered
339
- opts = config_options_object("--default_path", "foo")
340
- opts.configure(config)
341
- end
342
- end
343
-
344
- describe "#filter_manager" do
345
- it "returns the same object as RSpec::configuration.filter_manager" do
346
- expect(config_options_object.filter_manager).to be(RSpec::configuration.filter_manager)
347
- end
348
- end
349
-
350
- describe "sources: ~/.rspec, ./.rspec, ./.rspec-local, custom, CLI, and SPEC_OPTS" do
351
- it "merges global, local, SPEC_OPTS, and CLI" do
352
- File.open("./.rspec", "w") {|f| f << "--line 37"}
353
- File.open("./.rspec-local", "w") {|f| f << "--format global"}
354
- File.open(File.expand_path("~/.rspec"), "w") {|f| f << "--color"}
355
- with_env_vars 'SPEC_OPTS' => "--debug --example 'foo bar'" do
356
- options = parse_options("--drb")
357
- expect(options[:color]).to be_truthy
358
- expect(options[:line_numbers]).to eq(["37"])
359
- expect(options[:debug]).to be_truthy
360
- expect(options[:full_description]).to eq([/foo\ bar/])
361
- expect(options[:drb]).to be_truthy
362
- expect(options[:formatters]).to eq([['global']])
363
- end
364
- end
365
-
366
- it "prefers SPEC_OPTS over CLI" do
367
- with_env_vars 'SPEC_OPTS' => "--format spec_opts" do
368
- expect(parse_options("--format", "cli")[:formatters]).to eq([['spec_opts']])
369
- end
370
- end
371
-
372
- it "prefers CLI over file options" do
373
- File.open("./.rspec", "w") {|f| f << "--format project"}
374
- File.open(File.expand_path("~/.rspec"), "w") {|f| f << "--format global"}
375
- expect(parse_options("--format", "cli")[:formatters]).to eq([['cli']])
376
- end
377
-
378
- it "prefers project file options over global file options" do
379
- File.open("./.rspec", "w") {|f| f << "--format project"}
380
- File.open(File.expand_path("~/.rspec"), "w") {|f| f << "--format global"}
381
- expect(parse_options[:formatters]).to eq([['project']])
382
- end
383
-
384
- it "prefers local file options over project file options" do
385
- File.open("./.rspec-local", "w") {|f| f << "--format local"}
386
- File.open("./.rspec", "w") {|f| f << "--format global"}
387
- expect(parse_options[:formatters]).to eq([['local']])
388
- end
389
-
390
- it "parses options file correctly if erb code has trimming options" do
391
- File.open("./.rspec", "w") do |f|
392
- f << "<% if true -%>\n"
393
- f << "--format local\n"
394
- f << "<%- end %>\n"
395
- end
396
-
397
- expect(parse_options[:formatters]).to eq([['local']])
398
- end
399
-
400
- context "with custom options file" do
401
- it "ignores project and global options files" do
402
- File.open("./.rspec", "w") {|f| f << "--format project"}
403
- File.open(File.expand_path("~/.rspec"), "w") {|f| f << "--format global"}
404
- File.open("./custom.opts", "w") {|f| f << "--color"}
405
- options = parse_options("-O", "./custom.opts")
406
- expect(options[:format]).to be_nil
407
- expect(options[:color]).to be_truthy
408
- end
409
-
410
- it "parses -e 'full spec description'" do
411
- File.open("./custom.opts", "w") {|f| f << "-e 'The quick brown fox jumps over the lazy dog'"}
412
- options = parse_options("-O", "./custom.opts")
413
- expect(options[:full_description]).to eq([/The\ quick\ brown\ fox\ jumps\ over\ the\ lazy\ dog/])
414
- end
415
- end
416
- end
417
- end