rspec-core 2.99.0.beta1 → 2.99.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Changelog.md +40 -0
  2. data/features/command_line/line_number_option.feature +2 -2
  3. data/features/example_groups/basic_structure.feature +1 -1
  4. data/features/expectation_framework_integration/configure_expectation_framework.feature +1 -1
  5. data/features/subject/explicit_subject.feature +1 -1
  6. data/features/subject/one_liner_syntax.feature +71 -0
  7. data/lib/rspec/core/caller_filter.rb +50 -45
  8. data/lib/rspec/core/configuration.rb +59 -19
  9. data/lib/rspec/core/example.rb +1 -1
  10. data/lib/rspec/core/example_group.rb +20 -0
  11. data/lib/rspec/core/formatters/base_text_formatter.rb +3 -1
  12. data/lib/rspec/core/formatters/deprecation_formatter.rb +34 -16
  13. data/lib/rspec/core/memoized_helpers.rb +40 -6
  14. data/lib/rspec/core/option_parser.rb +1 -1
  15. data/lib/rspec/core/pending.rb +29 -1
  16. data/lib/rspec/core/reporter.rb +4 -1
  17. data/lib/rspec/core/version.rb +1 -1
  18. data/spec/rspec/core/configuration_options_spec.rb +3 -3
  19. data/spec/rspec/core/configuration_spec.rb +96 -4
  20. data/spec/rspec/core/example_group_spec.rb +36 -14
  21. data/spec/rspec/core/filter_manager_spec.rb +2 -2
  22. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +1 -1
  23. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +46 -0
  24. data/spec/rspec/core/formatters/{html_formatted-1.8.7-jruby.html → html_formatted.html} +24 -30
  25. data/spec/rspec/core/formatters/html_formatter_spec.rb +30 -15
  26. data/spec/rspec/core/formatters/{html_formatted-1.9.3-jruby.html → text_mate_formatted.html} +24 -30
  27. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +38 -33
  28. data/spec/rspec/core/memoized_helpers_spec.rb +11 -2
  29. data/spec/rspec/core/pending_example_spec.rb +26 -0
  30. data/spec/rspec/core/reporter_spec.rb +26 -0
  31. data/spec/rspec/core_spec.rb +1 -1
  32. data/spec/support/sandboxed_mock_space.rb +16 -0
  33. data/spec/support/silence_dsl_deprecations.rb +1 -1
  34. metadata +35 -40
  35. checksums.yaml +0 -15
  36. data/features/subject/implicit_receiver.feature +0 -29
  37. data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +0 -477
  38. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +0 -414
  39. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -425
  40. data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +0 -477
  41. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -425
  42. data/spec/rspec/core/formatters/html_formatted-2.0.0.html +0 -425
  43. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +0 -395
  44. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-rbx.html +0 -477
  45. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +0 -414
  46. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +0 -425
  47. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3-jruby.html +0 -404
  48. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3-rbx.html +0 -477
  49. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +0 -425
  50. data/spec/rspec/core/formatters/text_mate_formatted-2.0.0.html +0 -425
@@ -144,8 +144,10 @@ module RSpec
144
144
  output.puts pending_color(" #{pending_example.full_description}")
145
145
  output.puts detail_color(" # #{pending_example.execution_result[:pending_message]}")
146
146
  output.puts detail_color(" # #{format_caller(pending_example.location)}")
147
+ # instance_variable_get is a hack to avoid a deprecation warning,
148
+ # it's only for 2.99.
147
149
  if pending_example.execution_result[:exception] \
148
- && RSpec.configuration.show_failures_in_pending_blocks?
150
+ && RSpec.configuration.instance_variable_get(:@show_failures_in_pending_blocks)
149
151
  dump_failure_info(pending_example)
150
152
  dump_backtrace(pending_example)
151
153
  end
@@ -16,7 +16,9 @@ module RSpec
16
16
 
17
17
  def printer
18
18
  @printer ||= case deprecation_stream
19
- when File, RaiseErrorStream
19
+ when File
20
+ ImmediatePrinter.new(FileStream.new(deprecation_stream), summary_stream, self)
21
+ when RaiseErrorStream
20
22
  ImmediatePrinter.new(deprecation_stream, summary_stream, self)
21
23
  else
22
24
  DelayedPrinter.new(deprecation_stream, summary_stream, self)
@@ -81,7 +83,7 @@ module RSpec
81
83
  GeneratedDeprecationMessage = Struct.new(:type) do
82
84
  def initialize(data)
83
85
  @data = data
84
- super data[:deprecated]
86
+ super data.fetch(:type, data[:deprecated])
85
87
  end
86
88
 
87
89
  def to_s
@@ -99,19 +101,11 @@ module RSpec
99
101
  end
100
102
 
101
103
  class ImmediatePrinter
102
- include ::RSpec::Core::Formatters::Helpers
103
-
104
104
  attr_reader :deprecation_stream, :summary_stream, :deprecation_formatter
105
105
 
106
106
  def initialize(deprecation_stream, summary_stream, deprecation_formatter)
107
107
  @deprecation_stream = deprecation_stream
108
108
 
109
- # In one of my test suites, I got lots of duplicate output in the
110
- # deprecation file (e.g. 200 of the same deprecation, even though
111
- # the `puts` below was only called 6 times). Setting `sync = true`
112
- # fixes this (but we really have no idea why!).
113
- @deprecation_stream.sync = true
114
-
115
109
  @summary_stream = summary_stream
116
110
  @deprecation_formatter = deprecation_formatter
117
111
  end
@@ -122,10 +116,8 @@ module RSpec
122
116
  end
123
117
 
124
118
  def deprecation_summary
125
- if deprecation_formatter.count > 0
126
- summary_stream.puts "\n#{pluralize(deprecation_formatter.count, 'deprecation')} logged to #{deprecation_stream.path}"
127
- deprecation_stream.puts RAISE_ERROR_CONFIG_NOTICE
128
- end
119
+ return if deprecation_formatter.count.zero?
120
+ deprecation_stream.summarize(summary_stream, deprecation_formatter.count)
129
121
  end
130
122
  end
131
123
 
@@ -180,12 +172,38 @@ module RSpec
180
172
 
181
173
  # Not really a stream, but is usable in place of one.
182
174
  class RaiseErrorStream
175
+ include ::RSpec::Core::Formatters::Helpers
176
+
183
177
  def puts(message)
184
178
  raise DeprecationError, message
185
179
  end
186
180
 
187
- def sync=(value)
188
- # no-op
181
+ def summarize(summary_stream, deprecation_count)
182
+ summary_stream.puts "\n#{pluralize(deprecation_count, 'deprecation')} found."
183
+ end
184
+ end
185
+
186
+ # Wraps a File object and provides file-specific operations.
187
+ class FileStream
188
+ include ::RSpec::Core::Formatters::Helpers
189
+
190
+ def initialize(file)
191
+ @file = file
192
+
193
+ # In one of my test suites, I got lots of duplicate output in the
194
+ # deprecation file (e.g. 200 of the same deprecation, even though
195
+ # the `puts` below was only called 6 times). Setting `sync = true`
196
+ # fixes this (but we really have no idea why!).
197
+ @file.sync = true
198
+ end
199
+
200
+ def puts(*args)
201
+ @file.puts(*args)
202
+ end
203
+
204
+ def summarize(summary_stream, deprecation_count)
205
+ summary_stream.puts "\n#{pluralize(deprecation_count, 'deprecation')} logged to #{@file.path}"
206
+ puts RAISE_ERROR_CONFIG_NOTICE
189
207
  end
190
208
  end
191
209
 
@@ -5,6 +5,8 @@ module RSpec
5
5
  # syntax embraced by shoulda matchers:
6
6
  #
7
7
  # describe Widget do
8
+ # it { is_expected.to validate_presence_of(:name) }
9
+ # # or
8
10
  # it { should validate_presence_of(:name) }
9
11
  # end
10
12
  #
@@ -31,8 +33,10 @@ module RSpec
31
33
  # end
32
34
  # end
33
35
  #
34
- # # one-liner syntax - should is invoked on subject
36
+ # # one-liner syntax - expectation is set on the subject
35
37
  # describe Person do
38
+ # it { is_expected.to be_eligible_to_vote }
39
+ # # or
36
40
  # it { should be_eligible_to_vote }
37
41
  # end
38
42
  #
@@ -64,6 +68,11 @@ module RSpec
64
68
  # end
65
69
  #
66
70
  # @see #subject
71
+ # @see #is_expected
72
+ #
73
+ # @note This only works if you are using rspec-expectations.
74
+ # @note If you are using RSpec's newer expect-based syntax you may
75
+ # want to use `is_expected.to` instead of `should`.
67
76
  def should(matcher=nil, message=nil)
68
77
  RSpec::Expectations::PositiveExpectationHandler.handle_matcher(subject, matcher, message)
69
78
  end
@@ -78,10 +87,34 @@ module RSpec
78
87
  # end
79
88
  #
80
89
  # @see #subject
90
+ # @see #is_expected
91
+ #
92
+ # @note This only works if you are using rspec-expectations.
93
+ # @note If you are using RSpec's newer expect-based syntax you may
94
+ # want to use `is_expected.to_not` instead of `should_not`.
81
95
  def should_not(matcher=nil, message=nil)
82
96
  RSpec::Expectations::NegativeExpectationHandler.handle_matcher(subject, matcher, message)
83
97
  end
84
98
 
99
+ # Wraps the `subject` in `expect` to make it the target of an expectation.
100
+ # Designed to read nicely for one-liners.
101
+ #
102
+ # @example
103
+ #
104
+ # describe [1, 2, 3] do
105
+ # it { is_expected.to be_an Array }
106
+ # it { is_expected.not_to include 4 }
107
+ # end
108
+ #
109
+ # @see #subject
110
+ # @see #should
111
+ # @see #should_not
112
+ #
113
+ # @note This only works if you are using rspec-expectations.
114
+ def is_expected
115
+ expect(subject)
116
+ end
117
+
85
118
  private
86
119
 
87
120
  # @private
@@ -289,8 +322,9 @@ EOS
289
322
  before { __send__(name) }
290
323
  end
291
324
 
292
- # Declares a `subject` for an example group which can then be the
293
- # implicit receiver (through delegation) of calls to `should`.
325
+ # Declares a `subject` for an example group which can then be wrapped
326
+ # with `expect` using `is_expected` to make it the target of an expectation
327
+ # in a concise, one-line example.
294
328
  #
295
329
  # Given a `name`, defines a method with that name which returns the
296
330
  # `subject`. This lets you declare the subject once and access it
@@ -305,13 +339,13 @@ EOS
305
339
  #
306
340
  # describe CheckingAccount, "with $50" do
307
341
  # subject { CheckingAccount.new(Money.new(50, :USD)) }
308
- # it { should have_a_balance_of(Money.new(50, :USD)) }
309
- # it { should_not be_overdrawn }
342
+ # it { is_expected.to have_a_balance_of(Money.new(50, :USD)) }
343
+ # it { is_expected.not_to be_overdrawn }
310
344
  # end
311
345
  #
312
346
  # describe CheckingAccount, "with a non-zero starting balance" do
313
347
  # subject(:account) { CheckingAccount.new(Money.new(50, :USD)) }
314
- # it { should_not be_overdrawn }
348
+ # it { is_expected.not_to be_overdrawn }
315
349
  # it "has a balance equal to the starting balance" do
316
350
  # account.balance.should eq(Money.new(50, :USD))
317
351
  # end
@@ -81,7 +81,7 @@ module RSpec::Core
81
81
  end
82
82
 
83
83
  parser.on('-d', '--debugger', 'Enable debugging.') do |o|
84
- options[:debug] = true
84
+ options[:debug] = :cli
85
85
  end
86
86
 
87
87
  parser.on('--fail-fast', 'Abort the run on first failure.') do |o|
@@ -71,7 +71,32 @@ module RSpec
71
71
  # it "does something", :pending => "something else getting finished" do
72
72
  # # ...
73
73
  # end
74
- def pending(*args)
74
+ def pending(*args, &block)
75
+ RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''))
76
+ |The semantics of `RSpec::Core::Pending#pending` are changing in
77
+ |RSpec 3. In RSpec 2.x, it caused the example to be skipped. In
78
+ |RSpec 3, the rest of the example will still be run but is expected
79
+ |to fail, and will be marked as a failure (rather than as pending)
80
+ |if the example passes.
81
+ |
82
+ |Any passed block will no longer be executed. This feature is being
83
+ |removed since it was semantically inconsistent, and the behaviour it
84
+ |offered is being made available with the other ways of marking an
85
+ |example pending.
86
+ |
87
+ |To keep the same skip semantics, change `pending` to `skip`.
88
+ |Otherwise, if you want the new RSpec 3 behavior, you can safely
89
+ |ignore this warning and continue to upgrade to RSpec 3 without
90
+ |addressing it.
91
+ |
92
+ |Called from #{CallerFilter.first_non_rspec_line}.
93
+ |
94
+ EOS
95
+
96
+ pending_no_warning(*args, &block)
97
+ end
98
+
99
+ def pending_no_warning(*args)
75
100
  return self.class.before(:each) { pending(*args) } unless RSpec.current_example
76
101
 
77
102
  options = args.last.is_a?(Hash) ? args.pop : {}
@@ -103,6 +128,9 @@ module RSpec
103
128
  end
104
129
  raise PendingDeclaredInExample.new(message)
105
130
  end
131
+
132
+ # Backport from RSpec 3 to aid in upgrading.
133
+ alias_method :skip, :pending_no_warning
106
134
  end
107
135
 
108
136
  # Alias the error for compatibility with extension gems (e.g. formatters)
@@ -115,7 +115,10 @@ module RSpec::Core
115
115
  end
116
116
  end
117
117
 
118
- alias_method :abort, :finish
118
+ def abort(seed)
119
+ RSpec.deprecate "RSpec::Core::Reporter#abort", :replacement => "RSpec::Core::Reporter#finish"
120
+ finish(seed)
121
+ end
119
122
 
120
123
  def stop
121
124
  @duration = (RSpec::Core::Time.now - @start).to_f if @start
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Core
3
3
  module Version
4
- STRING = '2.99.0.beta1'
4
+ STRING = '2.99.0.beta2'
5
5
  end
6
6
  end
7
7
  end
@@ -105,7 +105,7 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
105
105
  it "sets debug directly" do
106
106
  opts = config_options_object("--debug")
107
107
  config = RSpec::Core::Configuration.new
108
- config.should_receive(:debug=).with(true)
108
+ config.should_receive(:debug=).with(:cli)
109
109
  opts.configure(config)
110
110
  end
111
111
 
@@ -224,8 +224,8 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
224
224
 
225
225
  describe "--debug, -d" do
226
226
  it "sets :debug => true" do
227
- expect(parse_options("--debug")).to include(:debug => true)
228
- expect(parse_options("-d")).to include(:debug => true)
227
+ expect(parse_options("--debug")).to include(:debug => :cli)
228
+ expect(parse_options("-d")).to include(:debug => :cli)
229
229
  end
230
230
  end
231
231
 
@@ -227,11 +227,40 @@ module RSpec::Core
227
227
  it_behaves_like "a configurable framework adapter", :mock_with
228
228
 
229
229
  [:rspec, :mocha, :rr, :flexmock].each do |framework|
230
- context "with #{framework}" do
230
+ context "with :#{framework}" do
231
231
  it "requires the adapter for #{framework}" do
232
232
  config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
233
233
  config.mock_with framework
234
234
  end
235
+
236
+ it "does not print a deprecation" do
237
+ expect(RSpec).not_to receive(:deprecate)
238
+ config.mock_with framework
239
+ end
240
+ end
241
+
242
+ context "with #{framework.to_s.inspect}" do
243
+ it "requires the adapter for #{framework}" do
244
+ config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
245
+ config.mock_with framework.to_s
246
+ end
247
+
248
+ it "prints a deprecation warning" do
249
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /mock_with/)
250
+ config.mock_with framework.to_s
251
+ end
252
+ end
253
+
254
+ context "with :the_#{framework}_adapter" do
255
+ it "requires the adapter for #{framework}" do
256
+ config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
257
+ config.mock_with :"the_#{framework}_adapter"
258
+ end
259
+
260
+ it "prints a deprecation warning" do
261
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /mock_with/)
262
+ config.mock_with :"the_#{framework}_adapter"
263
+ end
235
264
  end
236
265
  end
237
266
 
@@ -253,9 +282,28 @@ module RSpec::Core
253
282
  end
254
283
  end
255
284
 
256
- it "uses the null adapter when set to any unknown key" do
257
- config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
258
- config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
285
+ context "with an unknown key" do
286
+ it "uses the null adapter" do
287
+ config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
288
+ config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
289
+ end
290
+
291
+ it "prints a deprecation warning" do
292
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /mock_with/)
293
+ config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
294
+ end
295
+ end
296
+
297
+ context "with :nothing" do
298
+ it "uses the null adapter" do
299
+ config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
300
+ config.mock_with :nothing
301
+ end
302
+
303
+ it "does not print a deprecation warning" do
304
+ expect(RSpec).not_to receive(:deprecate)
305
+ config.mock_with :nothing
306
+ end
259
307
  end
260
308
 
261
309
  context 'when there are already some example groups defined' do
@@ -921,6 +969,12 @@ module RSpec::Core
921
969
  expect(lambda { config.add_formatter :progresss }).to raise_error(ArgumentError)
922
970
  end
923
971
 
972
+ it 'warns of deprecation for old document aliases' do
973
+ expect_deprecation_with_call_site __FILE__, __LINE__ + 1, 's'
974
+ config.add_formatter 's'
975
+ expect(config.formatters.first).to be_an_instance_of Formatters::DocumentationFormatter
976
+ end
977
+
924
978
  context "with a 2nd arg defining the output" do
925
979
  it "creates a file at that path and sets it as the output" do
926
980
  path = File.join(Dir.tmpdir, 'output.txt')
@@ -1471,30 +1525,45 @@ module RSpec::Core
1471
1525
  end
1472
1526
 
1473
1527
  describe "#force" do
1528
+ let(:collection) { [1, 2, 3, 4] }
1529
+ let(:ordered) { config.group_ordering_block.call(collection) }
1530
+
1474
1531
  it "forces order (when given default)" do
1475
1532
  config.force :order => "default"
1476
1533
  config.order = "rand"
1534
+
1477
1535
  expect(config.order).to eq("default")
1536
+ expect(ordered).to eq([1, 2, 3, 4])
1478
1537
  end
1479
1538
 
1480
1539
  it "forces order (when given defined)" do
1481
1540
  config.force :order => "defined"
1482
1541
  config.order = "rand"
1542
+
1483
1543
  expect(config.order).to eq("defined")
1544
+ expect(ordered).to eq([1, 2, 3, 4])
1484
1545
  end
1485
1546
 
1486
1547
  it "forces order and seed with :order => 'rand:37'" do
1487
1548
  config.force :order => "rand:37"
1488
1549
  config.order = "default"
1550
+
1489
1551
  expect(config.order).to eq("rand")
1490
1552
  expect(config.seed).to eq(37)
1553
+
1554
+ allow(Kernel).to receive(:rand).and_return(3, 1, 4, 2)
1555
+ expect(ordered).to_not eq([1, 2, 3, 4])
1491
1556
  end
1492
1557
 
1493
1558
  it "forces order and seed with :seed => '37'" do
1494
1559
  config.force :seed => "37"
1495
1560
  config.order = "defined"
1561
+
1496
1562
  expect(config.seed).to eq(37)
1497
1563
  expect(config.order).to eq("rand")
1564
+
1565
+ allow(Kernel).to receive(:rand).and_return(3, 1, 4, 2)
1566
+ expect(ordered).to eq([2, 4, 1, 3])
1498
1567
  end
1499
1568
 
1500
1569
  it 'can set random ordering' do
@@ -1790,5 +1859,28 @@ module RSpec::Core
1790
1859
  end
1791
1860
  end
1792
1861
 
1862
+ describe '#show_failures_in_pending_blocks' do
1863
+ specify 'reader is deprecated' do
1864
+ expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 3,
1865
+ /show_failures_in_pending_blocks/)
1866
+
1867
+ config.show_failures_in_pending_blocks
1868
+ end
1869
+
1870
+ specify 'predicate is deprecated' do
1871
+ expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 3,
1872
+ /show_failures_in_pending_blocks/)
1873
+
1874
+ config.show_failures_in_pending_blocks?
1875
+ end
1876
+
1877
+ specify 'writer is deprecated' do
1878
+ expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 3,
1879
+ /show_failures_in_pending_blocks/)
1880
+
1881
+ config.show_failures_in_pending_blocks = true
1882
+ end
1883
+ end
1884
+
1793
1885
  end
1794
1886
  end