rspec-core 2.99.0.beta2 → 2.99.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/Changelog.md +122 -43
  3. data/features/command_line/line_number_option.feature +6 -11
  4. data/features/configuration/read_options_from_file.feature +2 -2
  5. data/features/expectation_framework_integration/configure_expectation_framework.feature +120 -25
  6. data/lib/autotest/discover.rb +10 -1
  7. data/lib/autotest/rspec2.rb +1 -1
  8. data/lib/rspec/core/command_line.rb +16 -5
  9. data/lib/rspec/core/configuration.rb +151 -119
  10. data/lib/rspec/core/deprecated_mutable_array_proxy.rb +32 -0
  11. data/lib/rspec/core/example.rb +3 -1
  12. data/lib/rspec/core/example_group.rb +174 -125
  13. data/lib/rspec/core/filter_manager.rb +48 -10
  14. data/lib/rspec/core/formatters.rb +137 -0
  15. data/lib/rspec/core/formatters/base_text_formatter.rb +25 -29
  16. data/lib/rspec/core/formatters/console_codes.rb +42 -0
  17. data/lib/rspec/core/formatters/deprecation_formatter.rb +14 -5
  18. data/lib/rspec/core/formatters/helpers.rb +1 -1
  19. data/lib/rspec/core/memoized_helpers.rb +2 -1
  20. data/lib/rspec/core/metadata.rb +63 -1
  21. data/lib/rspec/core/minitest_assertions_adapter.rb +28 -0
  22. data/lib/rspec/core/option_parser.rb +20 -1
  23. data/lib/rspec/core/pending.rb +26 -4
  24. data/lib/rspec/core/reporter.rb +1 -1
  25. data/lib/rspec/core/runner.rb +2 -2
  26. data/lib/rspec/core/shared_example_group.rb +11 -4
  27. data/lib/rspec/core/test_unit_assertions_adapter.rb +30 -0
  28. data/lib/rspec/core/version.rb +1 -1
  29. data/lib/rspec/core/world.rb +2 -2
  30. data/spec/autotest/discover_spec.rb +38 -8
  31. data/spec/rspec/core/command_line_spec.rb +47 -29
  32. data/spec/rspec/core/configuration_options_spec.rb +1 -1
  33. data/spec/rspec/core/configuration_spec.rb +223 -37
  34. data/spec/rspec/core/example_group_spec.rb +116 -6
  35. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +24 -4
  36. data/spec/rspec/core/formatters/console_codes_spec.rb +50 -0
  37. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +20 -3
  38. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -0
  39. data/spec/rspec/core/formatters/html_formatted.html +3 -4
  40. data/spec/rspec/core/formatters/html_formatter_spec.rb +10 -4
  41. data/spec/rspec/core/formatters/text_mate_formatted.html +3 -4
  42. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +9 -3
  43. data/spec/rspec/core/hooks_filtering_spec.rb +5 -5
  44. data/spec/rspec/core/memoized_helpers_spec.rb +38 -0
  45. data/spec/rspec/core/metadata_spec.rb +24 -1
  46. data/spec/rspec/core/option_parser_spec.rb +39 -2
  47. data/spec/rspec/core/pending_example_spec.rb +14 -0
  48. data/spec/rspec/core/pending_spec.rb +27 -0
  49. data/spec/rspec/core/runner_spec.rb +3 -3
  50. data/spec/rspec/core/shared_context_spec.rb +1 -1
  51. data/spec/rspec/core/shared_example_group_spec.rb +18 -0
  52. data/spec/support/helper_methods.rb +4 -0
  53. metadata +105 -106
@@ -0,0 +1,28 @@
1
+ begin
2
+ # Only the minitest 5.x gem includes the minitest.rb and assertions.rb files
3
+ require 'minitest'
4
+ require 'minitest/assertions'
5
+ rescue LoadError => _ignored
6
+ # We must be using Ruby Core's MiniTest or the Minitest gem 4.x
7
+ require 'minitest/unit'
8
+ Minitest = MiniTest
9
+ end
10
+
11
+ module RSpec
12
+ module Core
13
+ # @private
14
+ module MinitestAssertionsAdapter
15
+ include ::Minitest::Assertions
16
+
17
+ # Minitest 5.x requires this accessor to be available. See
18
+ # https://github.com/seattlerb/minitest/blob/38f0a5fcbd9c37c3f80a3eaad4ba84d3fc9947a0/lib/minitest/assertions.rb#L8
19
+ #
20
+ # It is not required for other extension libraries, and RSpec does not
21
+ # report or make this information available to formatters.
22
+ attr_writer :assertions
23
+ def assertions
24
+ @assertions ||= 0
25
+ end
26
+ end
27
+ end
28
+ end
@@ -14,6 +14,7 @@ module RSpec::Core
14
14
  def parse!(args)
15
15
  return {} if args.empty?
16
16
 
17
+ pre_parse(args)
17
18
  convert_deprecated_args(args)
18
19
 
19
20
  options = args.delete('--tty') ? {:tty => true} : {}
@@ -30,9 +31,10 @@ module RSpec::Core
30
31
  args.map! { |arg|
31
32
  case arg
32
33
  when "--formatter"
33
- RSpec.deprecate("the --formatter option", :replacement => "-f or --format")
34
+ RSpec.deprecate("The `--formatter` option", :replacement => "-f or --format", :call_site => nil)
34
35
  "--format"
35
36
  when "--default_path"
37
+ RSpec.deprecate("The `--default_path` option", :replacement => "--default-path", :call_site => nil)
36
38
  "--default-path"
37
39
  when "--line_number"
38
40
  "--line-number"
@@ -132,6 +134,11 @@ module RSpec::Core
132
134
  options[:formatters].last << o
133
135
  end
134
136
 
137
+ parser.on('--deprecation-out FILE', 'Write deprecation warnings to a file instead of $stdout.') do |file|
138
+ # Handled in `pre_parse` so we can set the deprecation stream as early as
139
+ # possible in case any other options cause deprecations to be issued.
140
+ end
141
+
135
142
  parser.on('-b', '--backtrace', 'Enable full backtrace.') do |o|
136
143
  options[:full_backtrace] = true
137
144
  end
@@ -184,6 +191,10 @@ FILTERING
184
191
 
185
192
  parser.on('-l', '--line-number LINE', 'Specify line number of an example or group (may be',
186
193
  ' used more than once).') do |o|
194
+ Metadata.line_number_filter_deprecation_issued = true
195
+ RSpec.deprecate("The `--line-number`/`-l` CLI option",
196
+ :replacement => "the `path/to/file.rb:num` form",
197
+ :call_site => nil)
187
198
  (options[:line_numbers] ||= []) << o
188
199
  end
189
200
 
@@ -220,5 +231,13 @@ FILTERING
220
231
 
221
232
  end
222
233
  end
234
+
235
+ def pre_parse(args)
236
+ args.each_cons(2) do |arg, value|
237
+ if arg == "--deprecation-out"
238
+ RSpec.configuration.deprecation_stream = value
239
+ end
240
+ end
241
+ end
223
242
  end
224
243
  end
@@ -1,7 +1,14 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Pending
4
- class PendingDeclaredInExample < StandardError; end
4
+ class SkipDeclaredInExample < StandardError
5
+ attr_reader :argument
6
+
7
+ def initialize(argument)
8
+ super(argument.to_s)
9
+ @argument = argument
10
+ end
11
+ end
5
12
 
6
13
  # If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit
7
14
  # will report unmet RSpec expectations as failures rather than errors.
@@ -126,11 +133,24 @@ module RSpec
126
133
  raise PendingExampleFixedError.new
127
134
  end
128
135
  end
129
- raise PendingDeclaredInExample.new(message)
136
+ raise SkipDeclaredInExample.new(message)
130
137
  end
131
138
 
132
139
  # Backport from RSpec 3 to aid in upgrading.
133
- alias_method :skip, :pending_no_warning
140
+ #
141
+ # Not using alias method because we explictly want to discard any block.
142
+ def skip(*args)
143
+ pending_no_warning(*args)
144
+ end
145
+
146
+ def self.const_missing(name)
147
+ return super unless name == :PendingDeclaredInExample
148
+
149
+ RSpec.deprecate("RSpec::Core::PendingDeclaredInExample",
150
+ :replacement => "RSpec::Core::Pending::SkipDeclaredInExample")
151
+
152
+ SkipDeclaredInExample
153
+ end
134
154
  end
135
155
 
136
156
  # Alias the error for compatibility with extension gems (e.g. formatters)
@@ -138,7 +158,9 @@ module RSpec
138
158
  def self.const_missing(name)
139
159
  return super unless name == :PendingExampleFixedError
140
160
 
141
- RSpec.deprecate("RSpec::Core::PendingExampleFixedError", :replacement => "RSpec::Core::Pending::PendingExampleFixedError")
161
+ RSpec.deprecate("RSpec::Core::PendingExampleFixedError",
162
+ :replacement => "RSpec::Core::Pending::PendingExampleFixedError")
163
+
142
164
  Pending::PendingExampleFixedError
143
165
  end
144
166
  end
@@ -107,8 +107,8 @@ module RSpec::Core
107
107
  notify :start_dump
108
108
  notify :dump_pending
109
109
  notify :dump_failures
110
- notify :dump_summary, @duration, @example_count, @failure_count, @pending_count
111
110
  notify :deprecation_summary
111
+ notify :dump_summary, @duration, @example_count, @failure_count, @pending_count
112
112
  notify :seed, seed if seed
113
113
  ensure
114
114
  notify :close
@@ -83,10 +83,10 @@ module RSpec
83
83
  DRbCommandLine.new(options).run(err, out)
84
84
  rescue DRb::DRbConnError
85
85
  err.puts "No DRb server is running. Running in local process instead ..."
86
- CommandLine.new(options).run(err, out)
86
+ new(options).run(err, out)
87
87
  end
88
88
  else
89
- CommandLine.new(options).run(err, out)
89
+ new(options).run(err, out)
90
90
  end
91
91
  ensure
92
92
  RSpec.reset
@@ -33,9 +33,13 @@ module RSpec
33
33
  end
34
34
 
35
35
  alias_method :shared_context, :shared_examples
36
- alias_method :share_examples_for, :shared_examples
37
36
  alias_method :shared_examples_for, :shared_examples
38
37
 
38
+ def share_examples_for(*args, &block)
39
+ RSpec.deprecate("`share_examples_for`", :replacement => "`shared_examples` or `shared_examples_for`")
40
+ shared_examples(*args, &block)
41
+ end
42
+
39
43
  # @deprecated
40
44
  def share_as(name, &block)
41
45
  RSpec.deprecate("Rspec::Core::SharedExampleGroup#share_as",
@@ -53,12 +57,15 @@ module RSpec
53
57
  end
54
58
 
55
59
  alias_method :shared_context, :shared_examples
56
- alias_method :share_examples_for, :shared_examples
57
60
  alias_method :shared_examples_for, :shared_examples
58
61
 
62
+ def share_examples_for(*args, &block)
63
+ RSpec.deprecate("`share_examples_for`", :replacement => "`shared_examples` or `shared_examples_for`")
64
+ shared_examples(*args, &block)
65
+ end
66
+
59
67
  def share_as(name, &block)
60
- RSpec.deprecate("Rspec::Core::SharedExampleGroup#share_as",
61
- :replacement => "RSpec::SharedContext or shared_examples")
68
+ RSpec.deprecate("`share_as`", :replacement => "`RSpec::SharedContext` or `shared_examples`")
62
69
  SharedExampleGroup.registry.add_const('main', name, &block)
63
70
  end
64
71
 
@@ -0,0 +1,30 @@
1
+ require 'test/unit/assertions'
2
+
3
+ module RSpec
4
+ module Core
5
+ # @private
6
+ module TestUnitAssertionsAdapter
7
+ include ::Test::Unit::Assertions
8
+
9
+ # If using test/unit from Ruby core with Ruby 1.9+, it includes
10
+ # MiniTest::Assertions by default. Note the upcasing of 'Test'.
11
+ #
12
+ # If the test/unit gem is being loaded, it will not include any minitest
13
+ # assertions.
14
+ #
15
+ # Only if Minitest 5.x is included / loaded do we need to worry about
16
+ # adding a shim for the new updates. Thus instead of checking on the
17
+ # RUBY_VERSION we need to check ancestors.
18
+ begin
19
+ # MiniTest is 4.x
20
+ # Minitest is 5.x
21
+ if ancestors.include?(::Minitest::Assertions)
22
+ require 'rspec/core/minitest_assertions_adapter'
23
+ include ::RSpec::Core::MinitestAssertionsAdapter
24
+ end
25
+ rescue NameError => _ignored
26
+ # No-op. Minitest 5.x was not loaded
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Version
4
- STRING = '2.99.0.beta2'
4
+ STRING = '2.99.0.rc1'
5
5
  end
6
6
  end
7
7
  end
@@ -86,7 +86,7 @@ module RSpec
86
86
  example_groups.clear
87
87
  if filter_manager.empty?
88
88
  reporter.message("No examples found.")
89
- elsif exclusion_filter.empty_without_conditional_filters?
89
+ elsif exclusion_filter.rules_empty?
90
90
  message = everything_filtered_message
91
91
  if @configuration.run_all_when_everything_filtered?
92
92
  message << "; ignoring #{inclusion_filter.description}"
@@ -109,7 +109,7 @@ module RSpec
109
109
  end
110
110
 
111
111
  def announce_exclusion_filter(announcements)
112
- unless exclusion_filter.empty_without_conditional_filters?
112
+ unless exclusion_filter.rules_empty?
113
113
  announcements << "exclude #{exclusion_filter.description}"
114
114
  end
115
115
  end
@@ -1,19 +1,49 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "autotest/discover.rb" do
4
+ before { File.stub(:exist?).and_call_original }
5
+
4
6
  context "with ./.rspec present" do
5
- it "adds 'rspec2' to the list of discoveries" do
6
- File.stub(:exist?).with("./.rspec") { true }
7
- Autotest.should_receive(:add_discovery)
8
- load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
7
+ before { File.stub(:exist?).with("./.rspec") { true } }
8
+
9
+ context "when RSpec::Autotest is defined" do
10
+ before { stub_const "RSpec::Autotest", Module.new }
11
+
12
+ it "does not add 'rspec2' to the list of discoveries" do
13
+ Autotest.should_not_receive(:add_discovery)
14
+ load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
15
+ end
16
+ end
17
+
18
+ context "when RSpec::Autotest is not defined" do
19
+ before { hide_const "RSpec::Autotest" }
20
+
21
+ it "adds 'rspec2' to the list of discoveries" do
22
+ Autotest.should_receive(:add_discovery)
23
+ load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
24
+ end
9
25
  end
10
26
  end
11
27
 
12
28
  context "with ./.rspec absent" do
13
- it "does not add 'rspec2' to the list of discoveries" do
14
- File.stub(:exist?) { false }
15
- Autotest.should_not_receive(:add_discovery)
16
- load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
29
+ before { File.stub(:exist?).with("./.rspec") { false } }
30
+
31
+ context "when RSpec::Autotest is defined" do
32
+ before { stub_const "RSpec::Autotest", Module.new }
33
+
34
+ it "does not add 'rspec2' to the list of discoveries" do
35
+ Autotest.should_not_receive(:add_discovery)
36
+ load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
37
+ end
38
+ end
39
+
40
+ context "when RSpec::Autotest is not defined" do
41
+ before { hide_const "RSpec::Autotest" }
42
+
43
+ it "does not add 'rspec2' to the list of discoveries" do
44
+ Autotest.should_not_receive(:add_discovery)
45
+ load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
46
+ end
17
47
  end
18
48
  end
19
49
  end
@@ -3,7 +3,7 @@ require "stringio"
3
3
  require 'tmpdir'
4
4
 
5
5
  module RSpec::Core
6
- describe CommandLine do
6
+ describe Runner do
7
7
 
8
8
  let(:out) { StringIO.new }
9
9
  let(:err) { StringIO.new }
@@ -21,20 +21,14 @@ module RSpec::Core
21
21
  config.should_receive(:output_stream=).ordered
22
22
  config.should_receive(:force).at_least(:once).ordered
23
23
 
24
- command_line = build_command_line
25
- command_line.run err, out
26
- end
27
-
28
- it "assigns ConfigurationOptions built from Array of options to @options" do
29
- config_options = ConfigurationOptions.new(%w[--color])
30
- command_line = CommandLine.new(%w[--color])
31
- expect(command_line.instance_eval { @options.options }).to eq(config_options.parse_options)
24
+ runner = build_runner
25
+ runner.run err, out
32
26
  end
33
27
 
34
28
  it "assigns submitted ConfigurationOptions to @options" do
35
29
  config_options = ConfigurationOptions.new(%w[--color])
36
- command_line = CommandLine.new(config_options)
37
- expect(command_line.instance_eval { @options }).to be(config_options)
30
+ runner = Runner.new(config_options)
31
+ expect(runner.instance_eval { @options }).to be(config_options)
38
32
  end
39
33
 
40
34
  describe "#run" do
@@ -42,18 +36,18 @@ module RSpec::Core
42
36
  include_context "spec files"
43
37
 
44
38
  it "returns 0 if spec passes" do
45
- command_line = build_command_line passing_spec_filename
46
- expect(command_line.run(err, out)).to eq 0
39
+ runner = build_runner passing_spec_filename
40
+ expect(runner.run(err, out)).to eq 0
47
41
  end
48
42
 
49
43
  it "returns 1 if spec fails" do
50
- command_line = build_command_line failing_spec_filename
51
- expect(command_line.run(err, out)).to eq 1
44
+ runner = build_runner failing_spec_filename
45
+ expect(runner.run(err, out)).to eq 1
52
46
  end
53
47
 
54
48
  it "returns 2 if spec fails and --failure-exit-code is 2" do
55
- command_line = build_command_line failing_spec_filename, "--failure-exit-code", "2"
56
- expect(command_line.run(err, out)).to eq 2
49
+ runner = build_runner failing_spec_filename, "--failure-exit-code", "2"
50
+ expect(runner.run(err, out)).to eq 2
57
51
  end
58
52
  end
59
53
 
@@ -62,22 +56,22 @@ module RSpec::Core
62
56
 
63
57
  it "runs before suite hooks" do
64
58
  config.should_receive(:run_hook).with(:before, :suite)
65
- command_line = build_command_line
66
- command_line.run err, out
59
+ runner = build_runner
60
+ runner.run err, out
67
61
  end
68
62
 
69
63
  it "runs after suite hooks" do
70
64
  config.should_receive(:run_hook).with(:after, :suite)
71
- command_line = build_command_line
72
- command_line.run err, out
65
+ runner = build_runner
66
+ runner.run err, out
73
67
  end
74
68
 
75
69
  it "runs after suite hooks even after an error" do
76
70
  config.should_receive(:run_hook).with(:before, :suite).and_raise "this error"
77
71
  config.should_receive(:run_hook).with(:after , :suite)
78
72
  expect do
79
- command_line = build_command_line
80
- command_line.run err, out
73
+ runner = build_runner
74
+ runner.run err, out
81
75
  end.to raise_error
82
76
  end
83
77
  end
@@ -86,18 +80,18 @@ module RSpec::Core
86
80
  describe "#run with custom output" do
87
81
  before { config.stub :files_to_run => [] }
88
82
 
89
- let(:output_file) { File.new("#{Dir.tmpdir}/command_line_spec_output.txt", 'w') }
83
+ let(:output_file) { File.new("#{Dir.tmpdir}/runner_spec_output.txt", 'w') }
90
84
 
91
85
  it "doesn't override output_stream" do
92
86
  config.output_stream = output_file
93
- command_line = build_command_line
94
- command_line.run err, out
95
- expect(command_line.instance_eval { @configuration.output_stream }).to eq output_file
87
+ runner = build_runner
88
+ runner.run err, out
89
+ expect(runner.instance_eval { @configuration.output_stream }).to eq output_file
96
90
  end
97
91
  end
98
92
 
99
- def build_command_line *args
100
- CommandLine.new build_config_options(*args)
93
+ def build_runner *args
94
+ Runner.new build_config_options(*args)
101
95
  end
102
96
 
103
97
  def build_config_options *args
@@ -106,4 +100,28 @@ module RSpec::Core
106
100
  options
107
101
  end
108
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
109
127
  end