rspec-core 3.0.0.beta1 → 3.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data.tar.gz.sig +0 -0
  2. data/Changelog.md +137 -0
  3. data/README.md +2 -2
  4. data/exe/rspec +2 -23
  5. data/features/README.md +1 -5
  6. data/features/command_line/README.md +7 -10
  7. data/features/command_line/exit_status.feature +1 -1
  8. data/features/command_line/format_option.feature +1 -1
  9. data/features/command_line/init.feature +40 -1
  10. data/features/command_line/line_number_option.feature +2 -2
  11. data/features/command_line/ruby.feature +5 -4
  12. data/features/configuration/enable_global_dsl.feature +54 -0
  13. data/features/example_groups/aliasing.feature +48 -0
  14. data/features/example_groups/basic_structure.feature +1 -1
  15. data/features/expectation_framework_integration/configure_expectation_framework.feature +1 -1
  16. data/features/filtering/if_and_unless.feature +0 -30
  17. data/features/formatters/custom_formatter.feature +32 -0
  18. data/features/formatters/regression_tests.feature +95 -0
  19. data/features/hooks/around_hooks.feature +1 -0
  20. data/features/hooks/before_and_after_hooks.feature +2 -2
  21. data/features/mock_framework_integration/use_flexmock.feature +11 -13
  22. data/features/mock_framework_integration/use_mocha.feature +11 -13
  23. data/features/mock_framework_integration/use_rr.feature +11 -13
  24. data/features/mock_framework_integration/use_rspec.feature +11 -13
  25. data/features/pending_and_skipped_examples/README.md +3 -0
  26. data/features/pending_and_skipped_examples/pending_examples.feature +118 -0
  27. data/features/pending_and_skipped_examples/skipped_examples.feature +106 -0
  28. data/features/step_definitions/additional_cli_steps.rb +34 -0
  29. data/features/subject/explicit_subject.feature +1 -1
  30. data/features/subject/one_liner_syntax.feature +71 -0
  31. data/lib/rspec/core.rb +6 -14
  32. data/lib/rspec/core/backtrace_formatter.rb +16 -4
  33. data/lib/rspec/core/command_line.rb +2 -3
  34. data/lib/rspec/core/configuration.rb +114 -125
  35. data/lib/rspec/core/configuration_options.rb +32 -18
  36. data/lib/rspec/core/dsl.rb +80 -18
  37. data/lib/rspec/core/example.rb +84 -33
  38. data/lib/rspec/core/example_group.rb +95 -43
  39. data/lib/rspec/core/filter_manager.rb +31 -40
  40. data/lib/rspec/core/formatters.rb +137 -0
  41. data/lib/rspec/core/formatters/base_formatter.rb +28 -41
  42. data/lib/rspec/core/formatters/base_text_formatter.rb +26 -37
  43. data/lib/rspec/core/formatters/deprecation_formatter.rb +48 -27
  44. data/lib/rspec/core/formatters/documentation_formatter.rb +27 -22
  45. data/lib/rspec/core/formatters/html_formatter.rb +48 -56
  46. data/lib/rspec/core/formatters/html_printer.rb +11 -18
  47. data/lib/rspec/core/formatters/json_formatter.rb +18 -22
  48. data/lib/rspec/core/formatters/legacy_formatter.rb +227 -0
  49. data/lib/rspec/core/formatters/progress_formatter.rb +7 -10
  50. data/lib/rspec/core/hooks.rb +250 -217
  51. data/lib/rspec/core/memoized_helpers.rb +43 -9
  52. data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
  53. data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
  54. data/lib/rspec/core/mocking_adapters/null.rb +12 -0
  55. data/lib/rspec/core/mocking_adapters/rr.rb +28 -0
  56. data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
  57. data/lib/rspec/core/notifications.rb +100 -0
  58. data/lib/rspec/core/option_parser.rb +11 -18
  59. data/lib/rspec/core/pending.rb +78 -47
  60. data/lib/rspec/core/project_initializer.rb +2 -49
  61. data/lib/rspec/core/project_initializer/dot_rspec +3 -0
  62. data/lib/rspec/core/project_initializer/spec_helper.rb +82 -0
  63. data/lib/rspec/core/rake_task.rb +5 -14
  64. data/lib/rspec/core/reporter.rb +24 -32
  65. data/lib/rspec/core/ruby_project.rb +1 -1
  66. data/lib/rspec/core/runner.rb +14 -4
  67. data/lib/rspec/core/shared_example_group.rb +40 -13
  68. data/lib/rspec/core/version.rb +1 -1
  69. data/spec/command_line/order_spec.rb +15 -15
  70. data/spec/rspec/core/backtrace_formatter_spec.rb +15 -1
  71. data/spec/rspec/core/command_line_spec.rb +18 -17
  72. data/spec/rspec/core/configuration_options_spec.rb +57 -34
  73. data/spec/rspec/core/configuration_spec.rb +162 -184
  74. data/spec/rspec/core/drb_command_line_spec.rb +5 -7
  75. data/spec/rspec/core/drb_options_spec.rb +2 -2
  76. data/spec/rspec/core/dsl_spec.rb +79 -15
  77. data/spec/rspec/core/example_group_spec.rb +253 -39
  78. data/spec/rspec/core/example_spec.rb +149 -33
  79. data/spec/rspec/core/filter_manager_spec.rb +9 -26
  80. data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -5
  81. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +42 -145
  82. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +64 -34
  83. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +15 -28
  84. data/spec/rspec/core/formatters/helpers_spec.rb +2 -2
  85. data/spec/rspec/core/formatters/{html_formatted-1.8.7.html → html_formatted-2.1.0.html} +22 -44
  86. data/spec/rspec/core/formatters/{html_formatted-1.8.7-jruby.html → html_formatted.html} +30 -49
  87. data/spec/rspec/core/formatters/html_formatter_spec.rb +35 -19
  88. data/spec/rspec/core/formatters/json_formatter_spec.rb +42 -40
  89. data/spec/rspec/core/formatters/legacy_formatter_spec.rb +137 -0
  90. data/spec/rspec/core/formatters/progress_formatter_spec.rb +38 -25
  91. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +1 -1
  92. data/spec/rspec/core/formatters_spec.rb +120 -0
  93. data/spec/rspec/core/hooks_filtering_spec.rb +1 -1
  94. data/spec/rspec/core/hooks_spec.rb +13 -2
  95. data/spec/rspec/core/memoized_helpers_spec.rb +17 -8
  96. data/spec/rspec/core/metadata_spec.rb +3 -3
  97. data/spec/rspec/core/option_parser_spec.rb +53 -46
  98. data/spec/rspec/core/ordering_spec.rb +4 -4
  99. data/spec/rspec/core/pending_example_spec.rb +23 -126
  100. data/spec/rspec/core/pending_spec.rb +8 -0
  101. data/spec/rspec/core/project_initializer_spec.rb +8 -41
  102. data/spec/rspec/core/rake_task_spec.rb +15 -4
  103. data/spec/rspec/core/random_spec.rb +1 -1
  104. data/spec/rspec/core/reporter_spec.rb +50 -37
  105. data/spec/rspec/core/resources/formatter_specs.rb +9 -11
  106. data/spec/rspec/core/rspec_matchers_spec.rb +1 -1
  107. data/spec/rspec/core/ruby_project_spec.rb +3 -3
  108. data/spec/rspec/core/runner_spec.rb +65 -23
  109. data/spec/rspec/core/shared_context_spec.rb +4 -4
  110. data/spec/rspec/core/shared_example_group/collection_spec.rb +1 -1
  111. data/spec/rspec/core/shared_example_group_spec.rb +20 -11
  112. data/spec/rspec/core/warnings_spec.rb +1 -1
  113. data/spec/rspec/core/world_spec.rb +10 -10
  114. data/spec/rspec/core_spec.rb +2 -2
  115. data/spec/spec_helper.rb +12 -24
  116. data/spec/support/config_options_helper.rb +1 -3
  117. data/spec/support/formatter_support.rb +83 -0
  118. data/spec/support/isolate_load_path_mutation.rb +1 -2
  119. data/spec/support/isolated_directory.rb +1 -1
  120. data/spec/support/isolated_home_directory.rb +1 -1
  121. data/spec/support/legacy_formatter_using_sub_classing_example.rb +87 -0
  122. data/spec/support/matchers.rb +20 -0
  123. data/spec/support/mathn_integration_support.rb +2 -2
  124. data/spec/support/old_style_formatter_example.rb +69 -0
  125. data/spec/support/shared_example_groups.rb +1 -1
  126. data/spec/support/spec_files.rb +3 -3
  127. metadata +192 -69
  128. metadata.gz.sig +3 -1
  129. checksums.yaml +0 -15
  130. checksums.yaml.gz.sig +0 -2
  131. data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
  132. data/features/pending/pending_examples.feature +0 -229
  133. data/features/subject/implicit_receiver.feature +0 -29
  134. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  135. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  136. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  137. data/lib/rspec/core/mocking/with_rspec.rb +0 -27
  138. data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +0 -477
  139. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -425
  140. data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +0 -416
  141. data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +0 -477
  142. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -419
  143. data/spec/rspec/core/formatters/html_formatted-2.0.0.html +0 -425
  144. data/spec/support/in_sub_process.rb +0 -37
  145. data/spec/support/sandboxed_mock_space.rb +0 -100
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Version
4
- STRING = '3.0.0.beta1'
4
+ STRING = '3.0.0.beta2'
5
5
  end
6
6
  end
7
7
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'command line', :ui do
3
+ RSpec.describe 'command line', :ui, :slow do
4
4
  let(:stderr) { StringIO.new }
5
5
  let(:stdout) { StringIO.new }
6
6
 
7
7
  before :all do
8
8
  write_file 'spec/simple_spec.rb', """
9
- describe 'group 1' do
9
+ RSpec.describe 'group 1' do
10
10
  specify('group 1 example 1') {}
11
11
  specify('group 1 example 2') {}
12
12
  specify('group 1 example 3') {}
@@ -19,7 +19,7 @@ describe 'command line', :ui do
19
19
  """
20
20
 
21
21
  write_file 'spec/simple_spec2.rb', """
22
- describe 'group 2' do
22
+ RSpec.describe 'group 2' do
23
23
  specify('group 2 example 1') {}
24
24
  specify('group 2 example 2') {}
25
25
  specify('group 2 example 3') {}
@@ -32,7 +32,7 @@ describe 'command line', :ui do
32
32
  """
33
33
 
34
34
  write_file 'spec/order_spec.rb', """
35
- describe 'group 1' do
35
+ RSpec.describe 'group 1' do
36
36
  specify('group 1 example 1') {}
37
37
  specify('group 1 example 2') {}
38
38
  specify('group 1 example 3') {}
@@ -68,15 +68,15 @@ describe 'command line', :ui do
68
68
  describe('group 1-10') { specify('example') {} }
69
69
  end
70
70
 
71
- describe('group 2') { specify('example') {} }
72
- describe('group 3') { specify('example') {} }
73
- describe('group 4') { specify('example') {} }
74
- describe('group 5') { specify('example') {} }
75
- describe('group 6') { specify('example') {} }
76
- describe('group 7') { specify('example') {} }
77
- describe('group 8') { specify('example') {} }
78
- describe('group 9') { specify('example') {} }
79
- describe('group 10') { specify('example') {} }
71
+ RSpec.describe('group 2') { specify('example') {} }
72
+ RSpec.describe('group 3') { specify('example') {} }
73
+ RSpec.describe('group 4') { specify('example') {} }
74
+ RSpec.describe('group 5') { specify('example') {} }
75
+ RSpec.describe('group 6') { specify('example') {} }
76
+ RSpec.describe('group 7') { specify('example') {} }
77
+ RSpec.describe('group 8') { specify('example') {} }
78
+ RSpec.describe('group 9') { specify('example') {} }
79
+ RSpec.describe('group 10') { specify('example') {} }
80
80
  """
81
81
  end
82
82
 
@@ -158,14 +158,14 @@ describe 'command line', :ui do
158
158
  end
159
159
  end
160
160
 
161
- describe 'group B' do
161
+ RSpec.describe 'group B' do
162
162
  specify('group B example D') {}
163
163
  specify('group B example B') {}
164
164
  specify('group B example A') {}
165
165
  specify('group B example C') {}
166
166
  end
167
167
 
168
- describe 'group A' do
168
+ RSpec.describe 'group A' do
169
169
  specify('group A example 1') {}
170
170
  end
171
171
  """
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  module RSpec::Core
4
- describe BacktraceFormatter do
4
+ RSpec.describe BacktraceFormatter do
5
5
  def make_backtrace_formatter(exclusion_patterns=nil, inclusion_patterns=nil)
6
6
  BacktraceFormatter.new.tap do |bc|
7
7
  bc.exclusion_patterns = exclusion_patterns if exclusion_patterns
@@ -93,6 +93,20 @@ module RSpec::Core
93
93
  expect(BacktraceFormatter.new.format_backtrace(backtrace).drop(4).join).to match(/Showing full backtrace/)
94
94
  end
95
95
  end
96
+
97
+ context "when rspec is installed in the current working directory" do
98
+ it "excludes lines from rspec libs by default", :unless => RSpec.windows_os? do
99
+ backtrace = [
100
+ "#{Dir.getwd}/.bundle/path/to/rspec-expectations/lib/rspec/expectations/foo.rb:37",
101
+ "#{Dir.getwd}/.bundle/path/to/rspec-expectations/lib/rspec/matchers/foo.rb:37",
102
+ "#{Dir.getwd}/my_spec.rb:5",
103
+ "#{Dir.getwd}/.bundle/path/to/rspec-mocks/lib/rspec/mocks/foo.rb:37",
104
+ "#{Dir.getwd}/.bundle/path/to/rspec-core/lib/rspec/core/foo.rb:37"
105
+ ]
106
+
107
+ expect(BacktraceFormatter.new.format_backtrace(backtrace)).to eq(["./my_spec.rb:5"])
108
+ end
109
+ end
96
110
  end
97
111
 
98
112
  describe "#full_backtrace=true" do
@@ -3,25 +3,28 @@ require "stringio"
3
3
  require 'tmpdir'
4
4
 
5
5
  module RSpec::Core
6
- describe CommandLine do
6
+ RSpec.describe CommandLine do
7
7
 
8
8
  let(:out) { StringIO.new }
9
9
  let(:err) { StringIO.new }
10
10
  let(:config) { RSpec::configuration }
11
11
  let(:world) { RSpec::world }
12
12
 
13
- before { config.stub :run_hook }
13
+ before do
14
+ allow(config.hooks).to receive(:run)
15
+ end
14
16
 
15
17
  it "configures streams before command line options" do
18
+ allow(RSpec).to receive(:deprecate) # remove this and should_receive when ordered
16
19
  stdout = StringIO.new
17
- config.stub :load_spec_files
18
- config.stub(:reporter => double.as_null_object)
20
+ allow(config).to receive(:load_spec_files)
21
+ allow(config).to receive(:reporter).and_return(double.as_null_object)
19
22
  config.output_stream = $stdout
20
23
 
21
24
  # this is necessary to ensure that color works correctly on windows
22
- config.should_receive(:error_stream=).ordered
23
- config.should_receive(:output_stream=).ordered
24
- config.should_receive(:force).at_least(:once).ordered
25
+ expect(config).to receive(:error_stream=).ordered
26
+ expect(config).to receive(:output_stream=).ordered
27
+ expect(config).to receive(:force).at_least(:once).ordered
25
28
 
26
29
  command_line = build_command_line
27
30
  command_line.run err, stdout
@@ -30,7 +33,7 @@ module RSpec::Core
30
33
  it "assigns ConfigurationOptions built from Array of options to @options" do
31
34
  config_options = ConfigurationOptions.new(%w[--color])
32
35
  command_line = CommandLine.new(%w[--color])
33
- expect(command_line.instance_eval { @options.options }).to eq(config_options.parse_options)
36
+ expect(command_line.instance_eval { @options.options }).to eq(config_options.options)
34
37
  end
35
38
 
36
39
  it "assigns submitted ConfigurationOptions to @options" do
@@ -60,23 +63,23 @@ module RSpec::Core
60
63
  end
61
64
 
62
65
  context "running hooks" do
63
- before { config.stub :load_spec_files }
66
+ before { allow(config).to receive :load_spec_files }
64
67
 
65
68
  it "runs before suite hooks" do
66
- config.should_receive(:run_hook).with(:before, :suite)
69
+ expect(config.hooks).to receive(:run).with(:before, :suite)
67
70
  command_line = build_command_line
68
71
  command_line.run err, out
69
72
  end
70
73
 
71
74
  it "runs after suite hooks" do
72
- config.should_receive(:run_hook).with(:after, :suite)
75
+ expect(config.hooks).to receive(:run).with(:after, :suite)
73
76
  command_line = build_command_line
74
77
  command_line.run err, out
75
78
  end
76
79
 
77
80
  it "runs after suite hooks even after an error" do
78
- config.should_receive(:run_hook).with(:before, :suite).and_raise "this error"
79
- config.should_receive(:run_hook).with(:after , :suite)
81
+ expect(config.hooks).to receive(:run).with(:before, :suite).and_raise "this error"
82
+ expect(config.hooks).to receive(:run).with(:after , :suite)
80
83
  expect do
81
84
  command_line = build_command_line
82
85
  command_line.run err, out
@@ -86,7 +89,7 @@ module RSpec::Core
86
89
  end
87
90
 
88
91
  describe "#run with custom output" do
89
- before { config.stub :files_to_run => [] }
92
+ before { allow(config).to receive_messages :files_to_run => [] }
90
93
 
91
94
  let(:output_file) { File.new("#{Dir.tmpdir}/command_line_spec_output.txt", 'w') }
92
95
 
@@ -103,9 +106,7 @@ module RSpec::Core
103
106
  end
104
107
 
105
108
  def build_config_options *args
106
- options = ConfigurationOptions.new args
107
- options.parse_options
108
- options
109
+ ConfigurationOptions.new args
109
110
  end
110
111
  end
111
112
  end
@@ -2,74 +2,92 @@ require 'spec_helper'
2
2
  require 'ostruct'
3
3
  require 'rspec/core/drb_options'
4
4
 
5
- describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolated_home => true do
5
+ RSpec.describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolated_home => true do
6
6
  include ConfigOptionsHelper
7
7
 
8
8
  it "warns when HOME env var is not set", :unless => (RUBY_PLATFORM == 'java') do
9
9
  without_env_vars 'HOME' do
10
10
  expect_warning_with_call_site(__FILE__, __LINE__ + 1)
11
- RSpec::Core::ConfigurationOptions.new([]).parse_options
11
+ RSpec::Core::ConfigurationOptions.new([]).options
12
12
  end
13
13
  end
14
14
 
15
- it "duplicates the arguments array" do
15
+ it "does not mutate the provided args array" do
16
16
  args = ['-e', 'some spec']
17
- coo = RSpec::Core::ConfigurationOptions.new(args)
18
- coo.parse_options
17
+ RSpec::Core::ConfigurationOptions.new(args).options
19
18
  expect(args).to eq(['-e', 'some spec'])
20
19
  end
21
20
 
22
21
  describe "#configure" do
22
+ let(:config) { RSpec::Core::Configuration.new }
23
+
23
24
  it "sends libs before requires" do
24
25
  opts = config_options_object(*%w[--require a/path -I a/lib])
25
26
  config = double("config").as_null_object
26
- config.should_receive(:libs=).ordered
27
- config.should_receive(:setup_load_path_and_require).ordered
27
+ expect(config).to receive(:libs=).ordered
28
+ expect(config).to receive(:requires=).ordered
28
29
  opts.configure(config)
29
30
  end
30
31
 
31
- it "sends loads requires before loading specs" do
32
+ it "loads requires before loading specs" do
32
33
  opts = config_options_object(*%w[-rspec_helper])
33
- config = double("config").as_null_object
34
- expect(config).to receive(:setup_load_path_and_require).ordered
35
- expect(config).to receive(:files_or_directories_to_run=).ordered
34
+ config = RSpec::Core::Configuration.new
35
+ expect(config).to receive(:requires=).ordered
36
+ expect(config).to receive(:get_files_to_run).ordered
36
37
  opts.configure(config)
38
+ config.files_to_run
37
39
  end
38
40
 
39
41
  it "sets up load path and requires before formatter" do
40
42
  opts = config_options_object(*%w[--require a/path -f a/formatter])
41
43
  config = double("config").as_null_object
42
- config.should_receive(:setup_load_path_and_require).ordered
43
- config.should_receive(:add_formatter).ordered
44
+ expect(config).to receive(:requires=).ordered
45
+ expect(config).to receive(:add_formatter).ordered
44
46
  opts.configure(config)
45
47
  end
46
48
 
47
- it "sends default_path before files_or_directories_to_run" do
49
+ it "sets default_path before loading specs" do
48
50
  opts = config_options_object(*%w[--default_path spec])
49
- config = double("config").as_null_object
50
- config.should_receive(:force).with(:default_path => 'spec').ordered
51
- config.should_receive(:files_or_directories_to_run=).ordered
51
+ config = RSpec::Core::Configuration.new
52
+ expect(config).to receive(:force).with(:default_path => 'spec').ordered
53
+ expect(config).to receive(:get_files_to_run).ordered
54
+ opts.configure(config)
55
+ config.files_to_run
56
+ end
57
+
58
+ it "sets `files_or_directories_to_run` before `requires` so users can check `files_to_run` in a spec_helper loaded by `--require`" do
59
+ opts = config_options_object(*%w[--require spec_helper])
60
+ config = RSpec::Core::Configuration.new
61
+ expect(config).to receive(:files_or_directories_to_run=).ordered
62
+ expect(config).to receive(:requires=).ordered
63
+ opts.configure(config)
64
+ end
65
+
66
+ it "sets default_path before `files_or_directories_to_run` since it relies on it" do
67
+ opts = config_options_object(*%w[--default_path spec])
68
+ config = RSpec::Core::Configuration.new
69
+ expect(config).to receive(:force).with(:default_path => 'spec').ordered
70
+ expect(config).to receive(:files_or_directories_to_run=).ordered
52
71
  opts.configure(config)
53
72
  end
54
73
 
55
- it "sends pattern before files_or_directories_to_run" do
74
+ it "sets pattern before loading specs" do
56
75
  opts = config_options_object(*%w[--pattern **/*.spec])
57
- config = double("config").as_null_object
58
- config.should_receive(:force).with(:pattern => '**/*.spec').ordered
59
- config.should_receive(:files_or_directories_to_run=).ordered
76
+ config = RSpec::Core::Configuration.new
77
+ expect(config).to receive(:force).with(:pattern => '**/*.spec').ordered
78
+ expect(config).to receive(:get_files_to_run).ordered
60
79
  opts.configure(config)
80
+ config.files_to_run
61
81
  end
62
82
 
63
83
  it "assigns inclusion_filter" do
64
84
  opts = config_options_object(*%w[--tag awesome])
65
- config = RSpec::Core::Configuration.new
66
85
  opts.configure(config)
67
86
  expect(config.inclusion_filter).to have_key(:awesome)
68
87
  end
69
88
 
70
89
  it "merges the :exclusion_filter option with the default exclusion_filter" do
71
90
  opts = config_options_object(*%w[--tag ~slow])
72
- config = RSpec::Core::Configuration.new
73
91
  opts.configure(config)
74
92
  expect(config.exclusion_filter).to have_key(:slow)
75
93
  end
@@ -77,7 +95,7 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
77
95
  it "forces color_enabled" do
78
96
  opts = config_options_object(*%w[--color])
79
97
  config = RSpec::Core::Configuration.new
80
- config.should_receive(:force).with(:color => true)
98
+ expect(config).to receive(:force).with(:color => true)
81
99
  opts.configure(config)
82
100
  end
83
101
 
@@ -93,7 +111,7 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
93
111
  it "forces #{config_key}" do
94
112
  opts = config_options_object(cli_option, cli_value)
95
113
  config = RSpec::Core::Configuration.new
96
- config.should_receive(:force) do |pair|
114
+ expect(config).to receive(:force) do |pair|
97
115
  expect(pair.keys.first).to eq(config_key)
98
116
  expect(pair.values.first).to eq(config_value)
99
117
  end
@@ -104,9 +122,8 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
104
122
  it "merges --require specified by multiple configuration sources" do
105
123
  with_env_vars 'SPEC_OPTS' => "--require file_from_env" do
106
124
  opts = config_options_object(*%w[--require file_from_opts])
107
- config = RSpec::Core::Configuration.new
108
- config.should_receive(:require).with("file_from_opts")
109
- config.should_receive(:require).with("file_from_env")
125
+ expect(config).to receive(:require).with("file_from_opts")
126
+ expect(config).to receive(:require).with("file_from_env")
110
127
  opts.configure(config)
111
128
  end
112
129
  end
@@ -114,8 +131,7 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
114
131
  it "merges --I specified by multiple configuration sources" do
115
132
  with_env_vars 'SPEC_OPTS' => "-I dir_from_env" do
116
133
  opts = config_options_object(*%w[-I dir_from_opts])
117
- config = RSpec::Core::Configuration.new
118
- config.should_receive(:libs=).with(["dir_from_opts", "dir_from_env"])
134
+ expect(config).to receive(:libs=).with(["dir_from_opts", "dir_from_env"])
119
135
  opts.configure(config)
120
136
  end
121
137
  end
@@ -295,19 +311,26 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
295
311
  )
296
312
  end
297
313
 
314
+ it "parses file names that look like options line-number and default-path" do
315
+ expect(parse_options("spec/default_path_spec.rb", "spec/line_number_spec.rb")).to include(
316
+ :files_or_directories_to_run => ["spec/default_path_spec.rb", "spec/line_number_spec.rb"]
317
+ )
318
+ end
319
+
298
320
  it "provides no files or directories if spec directory does not exist" do
299
- FileTest.stub(:directory?).with("spec").and_return false
321
+ allow(FileTest).to receive(:directory?).with("spec").and_return false
300
322
  expect(parse_options()).to include(:files_or_directories_to_run => [])
301
323
  end
302
324
  end
303
325
 
304
326
  describe "default_path" do
305
327
  it "gets set before files_or_directories_to_run" do
306
- config = double("config").as_null_object
307
- config.should_receive(:force).with(:default_path => 'foo').ordered
308
- config.should_receive(:files_or_directories_to_run=).ordered
328
+ config = RSpec::Core::Configuration.new
329
+ expect(config).to receive(:force).with(:default_path => 'foo').ordered
330
+ expect(config).to receive(:get_files_to_run).ordered
309
331
  opts = config_options_object("--default_path", "foo")
310
332
  opts.configure(config)
333
+ config.files_to_run
311
334
  end
312
335
  end
313
336
 
@@ -3,19 +3,10 @@ require 'tmpdir'
3
3
 
4
4
  module RSpec::Core
5
5
 
6
- describe Configuration do
6
+ RSpec.describe Configuration do
7
7
 
8
8
  let(:config) { Configuration.new }
9
9
 
10
- describe "RSpec.configuration with a block" do
11
- before { RSpec.stub(:warn_deprecation) }
12
-
13
- it "is deprecated" do
14
- RSpec.should_receive(:warn_deprecation)
15
- RSpec.configuration {}
16
- end
17
- end
18
-
19
10
  describe '#deprecation_stream' do
20
11
  it 'defaults to standard error' do
21
12
  expect($rspec_core_without_stderr_monkey_patch.deprecation_stream).to eq STDERR
@@ -62,7 +53,7 @@ module RSpec::Core
62
53
  end
63
54
  end
64
55
 
65
- describe "#setup_load_path_and_require" do
56
+ describe "#requires=" do
66
57
  include_context "isolate load path mutation"
67
58
 
68
59
  def absolute_path_to(dir)
@@ -74,7 +65,7 @@ module RSpec::Core
74
65
  $LOAD_PATH.delete(lib_dir)
75
66
 
76
67
  expect($LOAD_PATH).not_to include(lib_dir)
77
- config.setup_load_path_and_require []
68
+ config.requires = []
78
69
  expect($LOAD_PATH).to include(lib_dir)
79
70
  end
80
71
 
@@ -83,20 +74,20 @@ module RSpec::Core
83
74
  foo_dir = absolute_path_to("features")
84
75
 
85
76
  expect($LOAD_PATH).not_to include(foo_dir)
86
- config.setup_load_path_and_require []
77
+ config.requires = []
87
78
  expect($LOAD_PATH).to include(foo_dir)
88
79
  end
89
80
 
90
81
  it 'stores the required files' do
91
- config.should_receive(:require).with('a/path')
92
- config.setup_load_path_and_require ['a/path']
82
+ expect(config).to receive(:require).with('a/path')
83
+ config.requires = ['a/path']
93
84
  expect(config.requires).to eq ['a/path']
94
85
  end
95
86
 
96
87
  context "when `default_path` refers to a file rather than a directory" do
97
88
  it 'does not add it to the load path' do
98
89
  config.default_path = 'Rakefile'
99
- config.setup_load_path_and_require []
90
+ config.requires = []
100
91
  expect($LOAD_PATH).not_to include(match(/Rakefile/))
101
92
  end
102
93
  end
@@ -105,27 +96,27 @@ module RSpec::Core
105
96
  describe "#load_spec_files" do
106
97
  it "loads files using load" do
107
98
  config.files_to_run = ["foo.bar", "blah_spec.rb"]
108
- config.should_receive(:load).twice
99
+ expect(config).to receive(:load).twice
109
100
  config.load_spec_files
110
101
  end
111
102
 
112
103
  it "loads each file once, even if duplicated in list" do
113
104
  config.files_to_run = ["a_spec.rb", "a_spec.rb"]
114
- config.should_receive(:load).once
105
+ expect(config).to receive(:load).once
115
106
  config.load_spec_files
116
107
  end
117
108
  end
118
109
 
119
110
  describe "#mock_framework" do
120
111
  it "defaults to :rspec" do
121
- config.should_receive(:require).with('rspec/core/mocking/with_rspec')
112
+ expect(config).to receive(:require).with('rspec/core/mocking_adapters/rspec')
122
113
  config.mock_framework
123
114
  end
124
115
  end
125
116
 
126
117
  describe "#mock_framework="do
127
118
  it "delegates to mock_with" do
128
- config.should_receive(:mock_with).with(:rspec)
119
+ expect(config).to receive(:mock_with).with(:rspec)
129
120
  config.mock_framework = :rspec
130
121
  end
131
122
  end
@@ -134,7 +125,7 @@ module RSpec::Core
134
125
  it "yields a config object if the framework_module supports it" do
135
126
  custom_config = Struct.new(:custom_setting).new
136
127
  mod = Module.new
137
- mod.stub(:configuration => custom_config)
128
+ allow(mod).to receive_messages(:configuration => custom_config)
138
129
 
139
130
  config.send m, mod do |mod_config|
140
131
  mod_config.custom_setting = true
@@ -154,23 +145,14 @@ module RSpec::Core
154
145
  end
155
146
 
156
147
  describe "#mock_with" do
157
- before { config.stub(:require) }
148
+ before { allow(config).to receive(:require) }
158
149
 
159
150
  it_behaves_like "a configurable framework adapter", :mock_with
160
151
 
161
- [:rspec, :mocha, :rr, :flexmock].each do |framework|
162
- context "with #{framework}" do
163
- it "requires the adapter for #{framework}" do
164
- config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
165
- config.mock_with framework
166
- end
167
- end
168
- end
169
-
170
152
  it "allows rspec-mocks to be configured with a provided block" do
171
153
  mod = Module.new
172
154
 
173
- RSpec::Mocks.configuration.should_receive(:add_stub_and_should_receive_to).with(mod)
155
+ expect(RSpec::Mocks.configuration).to receive(:add_stub_and_should_receive_to).with(mod)
174
156
 
175
157
  config.mock_with :rspec do |c|
176
158
  c.add_stub_and_should_receive_to mod
@@ -185,14 +167,33 @@ module RSpec::Core
185
167
  end
186
168
  end
187
169
 
188
- it "uses the null adapter when set to any unknown key" do
189
- config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
190
- config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
170
+ it 'uses the named adapter' do
171
+ expect(config).to receive(:require).with("rspec/core/mocking_adapters/mocha")
172
+ stub_const("RSpec::Core::MockingAdapters::Mocha", Module.new)
173
+ config.mock_with :mocha
174
+ end
175
+
176
+ it "uses the null adapter when given :nothing" do
177
+ expect(config).to receive(:require).with('rspec/core/mocking_adapters/null').and_call_original
178
+ config.mock_with :nothing
179
+ end
180
+
181
+ it "raises an error when given an unknown key" do
182
+ expect {
183
+ config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
184
+ }.to raise_error(ArgumentError, /unknown mocking framework/i)
185
+ end
186
+
187
+ it "raises an error when given another type of object" do
188
+ expect {
189
+ config.mock_with Object.new
190
+ }.to raise_error(ArgumentError, /unknown mocking framework/i)
191
191
  end
192
192
 
193
193
  context 'when there are already some example groups defined' do
194
194
  it 'raises an error since this setting must be applied before any groups are defined' do
195
- RSpec.world.stub(:example_groups).and_return([double.as_null_object])
195
+ allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
196
+ stub_const("RSpec::Core::MockingAdapters::Mocha", double(:framework_name => :mocha))
196
197
  expect {
197
198
  config.mock_with :mocha
198
199
  }.to raise_error(/must be configured before any example groups are defined/)
@@ -200,13 +201,14 @@ module RSpec::Core
200
201
 
201
202
  it 'does not raise an error if the default `mock_with :rspec` is re-configured' do
202
203
  config.mock_framework # called by RSpec when configuring the first example group
203
- RSpec.world.stub(:example_groups).and_return([double.as_null_object])
204
+ allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
204
205
  config.mock_with :rspec
205
206
  end
206
207
 
207
208
  it 'does not raise an error if re-setting the same config' do
209
+ stub_const("RSpec::Core::MockingAdapters::Mocha", double(:framework_name => :mocha))
208
210
  groups = []
209
- RSpec.world.stub(:example_groups => groups)
211
+ allow(RSpec.world).to receive_messages(:example_groups => groups)
210
212
  config.mock_with :mocha
211
213
  groups << double.as_null_object
212
214
  config.mock_with :mocha
@@ -216,14 +218,14 @@ module RSpec::Core
216
218
 
217
219
  describe "#expectation_framework" do
218
220
  it "defaults to :rspec" do
219
- config.should_receive(:require).with('rspec/expectations')
221
+ expect(config).to receive(:require).with('rspec/expectations')
220
222
  config.expectation_frameworks
221
223
  end
222
224
  end
223
225
 
224
226
  describe "#expectation_framework=" do
225
227
  it "delegates to expect_with=" do
226
- config.should_receive(:expect_with).with(:rspec)
228
+ expect(config).to receive(:expect_with).with(:rspec)
227
229
  config.expectation_framework = :rspec
228
230
  end
229
231
  end
@@ -231,7 +233,7 @@ module RSpec::Core
231
233
  describe "#expect_with" do
232
234
  before do
233
235
  stub_const("Test::Unit::Assertions", Module.new)
234
- config.stub(:require)
236
+ allow(config).to receive(:require)
235
237
  end
236
238
 
237
239
  it_behaves_like "a configurable framework adapter", :expect_with
@@ -242,7 +244,7 @@ module RSpec::Core
242
244
  ].each do |framework, required_file|
243
245
  context "with #{framework}" do
244
246
  it "requires #{required_file}" do
245
- config.should_receive(:require).with(required_file)
247
+ expect(config).to receive(:require).with(required_file)
246
248
  config.expect_with framework
247
249
  end
248
250
  end
@@ -269,7 +271,7 @@ module RSpec::Core
269
271
 
270
272
  context 'when there are already some example groups defined' do
271
273
  it 'raises an error since this setting must be applied before any groups are defined' do
272
- RSpec.world.stub(:example_groups).and_return([double.as_null_object])
274
+ allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
273
275
  expect {
274
276
  config.expect_with :rspec
275
277
  }.to raise_error(/must be configured before any example groups are defined/)
@@ -277,13 +279,13 @@ module RSpec::Core
277
279
 
278
280
  it 'does not raise an error if the default `expect_with :rspec` is re-configured' do
279
281
  config.expectation_frameworks # called by RSpec when configuring the first example group
280
- RSpec.world.stub(:example_groups).and_return([double.as_null_object])
282
+ allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
281
283
  config.expect_with :rspec
282
284
  end
283
285
 
284
286
  it 'does not raise an error if re-setting the same config' do
285
287
  groups = []
286
- RSpec.world.stub(:example_groups => groups)
288
+ allow(RSpec.world).to receive_messages(:example_groups => groups)
287
289
  config.expect_with :stdlib
288
290
  groups << double.as_null_object
289
291
  config.expect_with :stdlib
@@ -294,7 +296,7 @@ module RSpec::Core
294
296
  describe "#expecting_with_rspec?" do
295
297
  before do
296
298
  stub_const("Test::Unit::Assertions", Module.new)
297
- config.stub(:require)
299
+ allow(config).to receive(:require)
298
300
  end
299
301
 
300
302
  it "returns false by default" do
@@ -324,26 +326,36 @@ module RSpec::Core
324
326
 
325
327
  describe "#files_to_run" do
326
328
  it "loads files not following pattern if named explicitly" do
327
- config.files_or_directories_to_run = "spec/rspec/core/resources/a_bar.rb"
329
+ assign_files_or_directories_to_run "spec/rspec/core/resources/a_bar.rb"
328
330
  expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_bar.rb"])
329
331
  end
330
332
 
331
333
  it "prevents repetition of dir when start of the pattern" do
332
334
  config.pattern = "spec/**/a_spec.rb"
333
- config.files_or_directories_to_run = "spec"
335
+ assign_files_or_directories_to_run "spec"
334
336
  expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
335
337
  end
336
338
 
337
339
  it "does not prevent repetition of dir when later of the pattern" do
338
340
  config.pattern = "rspec/**/a_spec.rb"
339
- config.files_or_directories_to_run = "spec"
341
+ assign_files_or_directories_to_run "spec"
340
342
  expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
341
343
  end
342
344
 
345
+ it 'reloads when `files_or_directories_to_run` is reassigned' do
346
+ config.pattern = "spec/**/a_spec.rb"
347
+ config.files_or_directories_to_run = "empty_dir"
348
+
349
+ expect {
350
+ config.files_or_directories_to_run = "spec"
351
+ }.to change { config.files_to_run }.
352
+ to(["spec/rspec/core/resources/a_spec.rb"])
353
+ end
354
+
343
355
  context "with <path>:<line_number>" do
344
356
  it "overrides inclusion filters set on config" do
345
357
  config.filter_run_including :foo => :bar
346
- config.files_or_directories_to_run = "path/to/file.rb:37"
358
+ assign_files_or_directories_to_run "path/to/file.rb:37"
347
359
  expect(config.inclusion_filter.size).to eq(1)
348
360
  expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
349
361
  expect(config.inclusion_filter[:locations].values.first).to eq([37])
@@ -351,7 +363,7 @@ module RSpec::Core
351
363
 
352
364
  it "overrides inclusion filters set before config" do
353
365
  config.force(:inclusion_filter => {:foo => :bar})
354
- config.files_or_directories_to_run = "path/to/file.rb:37"
366
+ assign_files_or_directories_to_run "path/to/file.rb:37"
355
367
  expect(config.inclusion_filter.size).to eq(1)
356
368
  expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
357
369
  expect(config.inclusion_filter[:locations].values.first).to eq([37])
@@ -359,14 +371,14 @@ module RSpec::Core
359
371
 
360
372
  it "clears exclusion filters set on config" do
361
373
  config.exclusion_filter = { :foo => :bar }
362
- config.files_or_directories_to_run = "path/to/file.rb:37"
374
+ assign_files_or_directories_to_run "path/to/file.rb:37"
363
375
  expect(config.exclusion_filter).to be_empty,
364
376
  "expected exclusion filter to be empty:\n#{config.exclusion_filter}"
365
377
  end
366
378
 
367
379
  it "clears exclusion filters set before config" do
368
380
  config.force(:exclusion_filter => { :foo => :bar })
369
- config.files_or_directories_to_run = "path/to/file.rb:37"
381
+ assign_files_or_directories_to_run "path/to/file.rb:37"
370
382
  expect(config.exclusion_filter).to be_empty,
371
383
  "expected exclusion filter to be empty:\n#{config.exclusion_filter}"
372
384
  end
@@ -374,51 +386,53 @@ module RSpec::Core
374
386
 
375
387
  context "with default pattern" do
376
388
  it "loads files named _spec.rb" do
377
- config.files_or_directories_to_run = "spec/rspec/core/resources"
389
+ assign_files_or_directories_to_run "spec/rspec/core/resources"
378
390
  expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_spec.rb"])
379
391
  end
380
392
 
381
393
  it "loads files in Windows", :if => RSpec.windows_os? do
382
- config.files_or_directories_to_run = "C:\\path\\to\\project\\spec\\sub\\foo_spec.rb"
394
+ assign_files_or_directories_to_run "C:\\path\\to\\project\\spec\\sub\\foo_spec.rb"
383
395
  expect(config.files_to_run).to eq([ "C:/path/to/project/spec/sub/foo_spec.rb"])
384
396
  end
385
397
 
386
398
  it "loads files in Windows when directory is specified", :if => RSpec.windows_os? do
387
- config.files_or_directories_to_run = "spec\\rspec\\core\\resources"
399
+ assign_files_or_directories_to_run "spec\\rspec\\core\\resources"
388
400
  expect(config.files_to_run).to eq([ "spec/rspec/core/resources/a_spec.rb"])
389
401
  end
390
402
  end
391
403
 
392
404
  context "with default default_path" do
393
405
  it "loads files in the default path when run by rspec" do
394
- config.stub(:command) { 'rspec' }
395
- config.files_or_directories_to_run = []
406
+ allow(config).to receive(:command) { 'rspec' }
407
+ assign_files_or_directories_to_run []
396
408
  expect(config.files_to_run).not_to be_empty
397
409
  end
398
410
 
399
411
  it "loads files in the default path when run with DRB (e.g., spork)" do
400
- config.stub(:command) { 'spork' }
401
- RSpec::Core::Runner.stub(:running_in_drb?) { true }
402
- config.files_or_directories_to_run = []
412
+ allow(config).to receive(:command) { 'spork' }
413
+ allow(RSpec::Core::Runner).to receive(:running_in_drb?) { true }
414
+ assign_files_or_directories_to_run []
403
415
  expect(config.files_to_run).not_to be_empty
404
416
  end
405
417
 
406
418
  it "does not load files in the default path when run by ruby" do
407
- config.stub(:command) { 'ruby' }
408
- config.files_or_directories_to_run = []
419
+ allow(config).to receive(:command) { 'ruby' }
420
+ assign_files_or_directories_to_run []
409
421
  expect(config.files_to_run).to be_empty
410
422
  end
411
423
  end
412
424
 
413
425
  def specify_consistent_ordering_of_files_to_run
414
- File.stub(:directory?).with('a') { true }
426
+ allow(File).to receive(:directory?).with('a') { true }
427
+ globbed_files = nil
428
+ allow(Dir).to receive(:[]).with(/^\{?a/) { globbed_files }
415
429
 
416
430
  orderings = [
417
431
  %w[ a/1.rb a/2.rb a/3.rb ],
418
432
  %w[ a/2.rb a/1.rb a/3.rb ],
419
433
  %w[ a/3.rb a/2.rb a/1.rb ]
420
434
  ].map do |files|
421
- Dir.should_receive(:[]).with(/^\{?a/) { files }
435
+ globbed_files = files
422
436
  yield
423
437
  config.files_to_run
424
438
  end
@@ -430,7 +444,7 @@ module RSpec::Core
430
444
  it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
431
445
  specify_consistent_ordering_of_files_to_run do
432
446
  config.pattern = 'a/*.rb'
433
- config.files_or_directories_to_run = 'a'
447
+ assign_files_or_directories_to_run 'a'
434
448
  end
435
449
  end
436
450
  end
@@ -439,20 +453,20 @@ module RSpec::Core
439
453
  it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
440
454
  specify_consistent_ordering_of_files_to_run do
441
455
  config.pattern = '*.rb'
442
- config.files_or_directories_to_run = 'a'
456
+ assign_files_or_directories_to_run 'a'
443
457
  end
444
458
  end
445
459
  end
446
460
 
447
461
  context 'when given multiple file paths' do
448
462
  it 'orders the files in a consistent ordering, regardless of the given order' do
449
- File.stub(:directory?) { false } # fake it into thinking these a full file paths
463
+ allow(File).to receive(:directory?) { false } # fake it into thinking these a full file paths
450
464
 
451
465
  files = ['a/b/c_spec.rb', 'c/b/a_spec.rb']
452
- config.files_or_directories_to_run = *files
466
+ assign_files_or_directories_to_run(*files)
453
467
  ordering_1 = config.files_to_run
454
468
 
455
- config.files_or_directories_to_run = *(files.reverse)
469
+ assign_files_or_directories_to_run(*files.reverse)
456
470
  ordering_2 = config.files_to_run
457
471
 
458
472
  expect(ordering_1).to eq(ordering_2)
@@ -466,19 +480,19 @@ module RSpec::Core
466
480
  before { config.send(setter, "**/*_foo.rb") }
467
481
  it "loads files following pattern" do
468
482
  file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
469
- config.files_or_directories_to_run = file
483
+ assign_files_or_directories_to_run file
470
484
  expect(config.files_to_run).to include(file)
471
485
  end
472
486
 
473
487
  it "loads files in directories following pattern" do
474
488
  dir = File.expand_path(File.dirname(__FILE__) + "/resources")
475
- config.files_or_directories_to_run = dir
489
+ assign_files_or_directories_to_run dir
476
490
  expect(config.files_to_run).to include("#{dir}/a_foo.rb")
477
491
  end
478
492
 
479
493
  it "does not load files in directories not following pattern" do
480
494
  dir = File.expand_path(File.dirname(__FILE__) + "/resources")
481
- config.files_or_directories_to_run = dir
495
+ assign_files_or_directories_to_run dir
482
496
  expect(config.files_to_run).not_to include("#{dir}/a_bar.rb")
483
497
  end
484
498
  end
@@ -487,7 +501,7 @@ module RSpec::Core
487
501
  it "supports comma separated values" do
488
502
  config.send(setter, "**/*_foo.rb,**/*_bar.rb")
489
503
  dir = File.expand_path(File.dirname(__FILE__) + "/resources")
490
- config.files_or_directories_to_run = dir
504
+ assign_files_or_directories_to_run dir
491
505
  expect(config.files_to_run).to include("#{dir}/a_foo.rb")
492
506
  expect(config.files_to_run).to include("#{dir}/a_bar.rb")
493
507
  end
@@ -495,7 +509,7 @@ module RSpec::Core
495
509
  it "supports comma separated values with spaces" do
496
510
  config.send(setter, "**/*_foo.rb, **/*_bar.rb")
497
511
  dir = File.expand_path(File.dirname(__FILE__) + "/resources")
498
- config.files_or_directories_to_run = dir
512
+ assign_files_or_directories_to_run dir
499
513
  expect(config.files_to_run).to include("#{dir}/a_foo.rb")
500
514
  expect(config.files_to_run).to include("#{dir}/a_bar.rb")
501
515
  end
@@ -503,7 +517,7 @@ module RSpec::Core
503
517
  it "supports curly braces glob syntax" do
504
518
  config.send(setter, "**/*_{foo,bar}.rb")
505
519
  dir = File.expand_path(File.dirname(__FILE__) + "/resources")
506
- config.files_or_directories_to_run = dir
520
+ assign_files_or_directories_to_run dir
507
521
  expect(config.files_to_run).to include("#{dir}/a_foo.rb")
508
522
  expect(config.files_to_run).to include("#{dir}/a_bar.rb")
509
523
  end
@@ -528,7 +542,7 @@ module RSpec::Core
528
542
 
529
543
  describe "path with line number" do
530
544
  it "assigns the line number as a location filter" do
531
- config.files_or_directories_to_run = "path/to/a_spec.rb:37"
545
+ assign_files_or_directories_to_run "path/to/a_spec.rb:37"
532
546
  expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
533
547
  end
534
548
  end
@@ -554,25 +568,25 @@ module RSpec::Core
554
568
 
555
569
  context "with line number" do
556
570
  it "assigns the file and line number as a location filter" do
557
- config.files_or_directories_to_run = "path/to/a_spec.rb:37"
571
+ assign_files_or_directories_to_run "path/to/a_spec.rb:37"
558
572
  expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
559
573
  end
560
574
 
561
575
  it "assigns multiple files with line numbers as location filters" do
562
- config.files_or_directories_to_run = "path/to/a_spec.rb:37", "other_spec.rb:44"
576
+ assign_files_or_directories_to_run "path/to/a_spec.rb:37", "other_spec.rb:44"
563
577
  expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37],
564
578
  File.expand_path("other_spec.rb") => [44]}})
565
579
  end
566
580
 
567
581
  it "assigns files with multiple line numbers as location filters" do
568
- config.files_or_directories_to_run = "path/to/a_spec.rb:37", "path/to/a_spec.rb:44"
582
+ assign_files_or_directories_to_run "path/to/a_spec.rb:37", "path/to/a_spec.rb:44"
569
583
  expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37, 44]}})
570
584
  end
571
585
  end
572
586
 
573
587
  context "with multiple line numbers" do
574
588
  it "assigns the file and line numbers as a location filter" do
575
- config.files_or_directories_to_run = "path/to/a_spec.rb:1:3:5:7"
589
+ assign_files_or_directories_to_run "path/to/a_spec.rb:1:3:5:7"
576
590
  expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [1,3,5,7]}})
577
591
  end
578
592
  end
@@ -687,7 +701,7 @@ module RSpec::Core
687
701
  config.output_stream = output
688
702
 
689
703
  config.tty = true
690
- config.output_stream.stub :tty? => true
704
+ allow(config.output_stream).to receive_messages :tty? => true
691
705
 
692
706
  expect(config.send(color_option)).to be_truthy
693
707
  expect(config.send(color_option, output)).to be_truthy
@@ -700,7 +714,7 @@ module RSpec::Core
700
714
  config.output_stream = output
701
715
 
702
716
  config.tty = true
703
- config.output_stream.stub :tty? => false
717
+ allow(config.output_stream).to receive_messages :tty? => false
704
718
 
705
719
  expect(config.send(color_option)).to be_truthy
706
720
  expect(config.send(color_option, output)).to be_truthy
@@ -713,7 +727,7 @@ module RSpec::Core
713
727
  config.output_stream = output
714
728
 
715
729
  config.tty = false
716
- config.output_stream.stub :tty? => true
730
+ allow(config.output_stream).to receive_messages :tty? => true
717
731
 
718
732
  expect(config.send(color_option)).to be_truthy
719
733
  expect(config.send(color_option, output)).to be_truthy
@@ -726,7 +740,7 @@ module RSpec::Core
726
740
  config.output_stream = output
727
741
 
728
742
  config.tty = false
729
- config.output_stream.stub :tty? => false
743
+ allow(config.output_stream).to receive_messages :tty? => false
730
744
 
731
745
  expect(config.send(color_option)).to be_falsey
732
746
  expect(config.send(color_option, output)).to be_falsey
@@ -737,7 +751,7 @@ module RSpec::Core
737
751
  before do
738
752
  @original_host = RbConfig::CONFIG['host_os']
739
753
  RbConfig::CONFIG['host_os'] = 'mingw'
740
- config.stub(:require)
754
+ allow(config).to receive(:require)
741
755
  end
742
756
 
743
757
  after do
@@ -749,14 +763,14 @@ module RSpec::Core
749
763
 
750
764
  it "enables colors" do
751
765
  config.output_stream = StringIO.new
752
- config.output_stream.stub :tty? => true
766
+ allow(config.output_stream).to receive_messages :tty? => true
753
767
  config.send "#{color_option}=", true
754
768
  expect(config.send(color_option)).to be_truthy
755
769
  end
756
770
 
757
771
  it "leaves output stream intact" do
758
772
  config.output_stream = $stdout
759
- config.stub(:require) do |what|
773
+ allow(config).to receive(:require) do |what|
760
774
  config.output_stream = 'foo' if what =~ /Win32/
761
775
  end
762
776
  config.send "#{color_option}=", true
@@ -770,13 +784,13 @@ module RSpec::Core
770
784
  end
771
785
 
772
786
  it "warns to install ANSICON" do
773
- config.stub(:require) { raise LoadError }
787
+ allow(config).to receive(:require) { raise LoadError }
774
788
  expect_warning_with_call_site(__FILE__, __LINE__ + 1, /You must use ANSICON/)
775
789
  config.send "#{color_option}=", true
776
790
  end
777
791
 
778
792
  it "sets color_enabled to false" do
779
- config.stub(:require) { raise LoadError }
793
+ allow(config).to receive(:require) { raise LoadError }
780
794
  config.send "#{color_option}=", true
781
795
  config.color_enabled = true
782
796
  expect(config.send(color_option)).to be_falsey
@@ -788,78 +802,18 @@ module RSpec::Core
788
802
 
789
803
  it "prefers incoming cli_args" do
790
804
  config.output_stream = StringIO.new
791
- config.output_stream.stub :tty? => true
805
+ allow(config.output_stream).to receive_messages :tty? => true
792
806
  config.force :color => true
793
807
  config.color = false
794
808
  expect(config.color).to be_truthy
795
809
  end
796
810
  end
797
811
 
798
- describe '#formatter=' do
799
- it "delegates to add_formatter (better API for user-facing configuration)" do
800
- config.should_receive(:add_formatter).with('these','options')
801
- config.add_formatter('these','options')
802
- end
803
- end
804
-
805
- describe "#add_formatter" do
806
-
807
- it "adds to the list of formatters" do
808
- config.add_formatter :documentation
809
- expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
810
- end
811
-
812
- it "finds a formatter by name (w/ Symbol)" do
813
- config.add_formatter :documentation
814
- expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
815
- end
816
-
817
- it "finds a formatter by name (w/ String)" do
818
- config.add_formatter 'documentation'
819
- expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
820
- end
821
-
822
- it "finds a formatter by class" do
823
- formatter_class = Class.new(Formatters::BaseTextFormatter)
824
- config.add_formatter formatter_class
825
- expect(config.formatters.first).to be_an_instance_of(formatter_class)
826
- end
827
-
828
- it "finds a formatter by class name" do
829
- stub_const("CustomFormatter", Class.new(Formatters::BaseFormatter))
830
- config.add_formatter "CustomFormatter"
831
- expect(config.formatters.first).to be_an_instance_of(CustomFormatter)
832
- end
833
-
834
- it "finds a formatter by class fully qualified name" do
835
- stub_const("RSpec::CustomFormatter", Class.new(Formatters::BaseFormatter))
836
- config.add_formatter "RSpec::CustomFormatter"
837
- expect(config.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
838
- end
839
-
840
- it "requires a formatter file based on its fully qualified name" do
841
- config.should_receive(:require).with('rspec/custom_formatter') do
842
- stub_const("RSpec::CustomFormatter", Class.new(Formatters::BaseFormatter))
843
- end
844
- config.add_formatter "RSpec::CustomFormatter"
845
- expect(config.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
846
- end
847
-
848
- it "raises NameError if class is unresolvable" do
849
- config.should_receive(:require).with('rspec/custom_formatter3')
850
- expect(lambda { config.add_formatter "RSpec::CustomFormatter3" }).to raise_error(NameError)
851
- end
852
-
853
- it "raises ArgumentError if formatter is unknown" do
854
- expect(lambda { config.add_formatter :progresss }).to raise_error(ArgumentError)
855
- end
856
-
857
- context "with a 2nd arg defining the output" do
858
- it "creates a file at that path and sets it as the output" do
859
- path = File.join(Dir.tmpdir, 'output.txt')
860
- config.add_formatter('doc', path)
861
- expect(config.formatters.first.output).to be_a(File)
862
- expect(config.formatters.first.output.path).to eq(path)
812
+ %w[formatter= add_formatter].each do |config_method|
813
+ describe "##{config_method}" do
814
+ it "delegates to formatters#add" do
815
+ expect(config.formatter_loader).to receive(:add).with('these','options')
816
+ config.send(config_method,'these','options')
863
817
  end
864
818
  end
865
819
  end
@@ -1065,7 +1019,7 @@ module RSpec::Core
1065
1019
  include_context "isolate load path mutation"
1066
1020
 
1067
1021
  it "adds directories to the LOAD_PATH" do
1068
- $LOAD_PATH.should_receive(:unshift).with("a/dir")
1022
+ expect($LOAD_PATH).to receive(:unshift).with("a/dir")
1069
1023
  config.libs = ["a/dir"]
1070
1024
  end
1071
1025
  end
@@ -1079,22 +1033,6 @@ module RSpec::Core
1079
1033
  end
1080
1034
  end
1081
1035
 
1082
- describe "#requires=" do
1083
- before { RSpec.should_receive :deprecate }
1084
-
1085
- it "requires the configured files" do
1086
- config.should_receive(:require).with('foo').ordered
1087
- config.should_receive(:require).with('bar').ordered
1088
- config.requires = ['foo', 'bar']
1089
- end
1090
-
1091
- it "stores require paths" do
1092
- config.should_receive(:require).with("a/path")
1093
- config.requires = ["a/path"]
1094
- expect(config.requires).to eq ['a/path']
1095
- end
1096
- end
1097
-
1098
1036
  describe "#add_setting" do
1099
1037
  describe "with no modifiers" do
1100
1038
  context "with no additional options" do
@@ -1146,14 +1084,6 @@ module RSpec::Core
1146
1084
  end
1147
1085
  end
1148
1086
 
1149
- context "with :alias => " do
1150
- it "is deprecated" do
1151
- RSpec::should_receive(:deprecate).with(/:alias option/, :replacement => ":alias_with")
1152
- config.add_setting :custom_option
1153
- config.add_setting :another_custom_option, :alias => :custom_option
1154
- end
1155
- end
1156
-
1157
1087
  context "with :alias_with => " do
1158
1088
  before do
1159
1089
  config.add_setting :custom_option, :alias_with => :another_custom_option
@@ -1254,6 +1184,48 @@ module RSpec::Core
1254
1184
  end
1255
1185
  end
1256
1186
 
1187
+ describe "#alias_example_group_to" do
1188
+ after do
1189
+ RSpec::Core::DSL.example_group_aliases.delete(:my_group_method)
1190
+
1191
+ RSpec.module_eval do
1192
+ class << self
1193
+ undef :my_group_method if method_defined? :my_group_method
1194
+ end
1195
+ end
1196
+
1197
+ RSpec::Core::ExampleGroup.module_eval do
1198
+ class << self
1199
+ undef :my_group_method if method_defined? :my_group_method
1200
+ end
1201
+ end
1202
+ end
1203
+
1204
+ it_behaves_like "metadata hash builder" do
1205
+ def metadata_hash(*args)
1206
+ config.alias_example_group_to :my_group_method, *args
1207
+ group = ExampleGroup.my_group_method("a group")
1208
+ group.metadata
1209
+ end
1210
+ end
1211
+
1212
+ it "allows adding additional metadata" do
1213
+ config.alias_example_group_to :my_group_method, { :some => "thing" }
1214
+ group = ExampleGroup.my_group_method("a group", :another => "thing")
1215
+ expect(group.metadata).to include(:some => "thing", :another => "thing")
1216
+ end
1217
+
1218
+ context 'when the aliased method is used' do
1219
+ it_behaves_like "metadata hash builder" do
1220
+ def metadata_hash(*args)
1221
+ config.alias_example_group_to :my_group_method
1222
+ group = ExampleGroup.my_group_method("a group", *args)
1223
+ group.metadata
1224
+ end
1225
+ end
1226
+ end
1227
+ end
1228
+
1257
1229
  describe "#alias_example_to" do
1258
1230
  it_behaves_like "metadata hash builder" do
1259
1231
  after do
@@ -1368,7 +1340,7 @@ module RSpec::Core
1368
1340
  end
1369
1341
 
1370
1342
  it 'sets up random ordering' do
1371
- RSpec.stub(:configuration => config)
1343
+ allow(RSpec).to receive_messages(:configuration => config)
1372
1344
  global_ordering = config.ordering_registry.fetch(:global)
1373
1345
  expect(global_ordering).to be_an_instance_of(Ordering::Random)
1374
1346
  end
@@ -1382,7 +1354,7 @@ module RSpec::Core
1382
1354
  end
1383
1355
 
1384
1356
  it 'sets up random ordering' do
1385
- RSpec.stub(:configuration => config)
1357
+ allow(RSpec).to receive_messages(:configuration => config)
1386
1358
  global_ordering = config.ordering_registry.fetch(:global)
1387
1359
  expect(global_ordering).to be_an_instance_of(Ordering::Random)
1388
1360
  end
@@ -1399,7 +1371,7 @@ module RSpec::Core
1399
1371
  end
1400
1372
 
1401
1373
  it 'clears the random ordering' do
1402
- RSpec.stub(:configuration => config)
1374
+ allow(RSpec).to receive_messages(:configuration => config)
1403
1375
  list = [1, 2, 3, 4]
1404
1376
  ordering_strategy = config.ordering_registry.fetch(:global)
1405
1377
  expect(ordering_strategy.order(list)).to eq([1, 2, 3, 4])
@@ -1497,5 +1469,11 @@ module RSpec::Core
1497
1469
  end
1498
1470
  end
1499
1471
 
1472
+ # assigns files_or_directories_to_run and triggers post-processing
1473
+ # via `files_to_run`.
1474
+ def assign_files_or_directories_to_run(*value)
1475
+ config.files_or_directories_to_run = value
1476
+ config.files_to_run
1477
+ end
1500
1478
  end
1501
1479
  end