rspec-core 2.99.0.beta1 → 2.99.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -1,3 +1,43 @@
1
+ ### 2.99.0.beta2 / 2014-02-17
2
+ [full changelog](http://github.com/rspec/rspec-core/compare/v2.99.0.beta1...v2.99.0.beta2)
3
+
4
+ Enhancements:
5
+
6
+ * Add `is_expected` for one-liners that read well with the
7
+ `expect`-based syntax. `is_expected` is simply defined as
8
+ `expect(subject)` and can be used in an expression like:
9
+ `it { is_expected.to read_well }`. (Myron Marston)
10
+ * Backport `skip` from RSpec 3, which acts like `pending` did in RSpec 2
11
+ when not given a block, since the behavior of `pending` is changing in
12
+ RSpec 3. (Xavier Shay)
13
+
14
+ Deprecations:
15
+
16
+ * Deprecate inexact `mock_with` config options. RSpec 3 will only support
17
+ the exact symbols `:rspec`, `:mocha`, `:flexmock`, `:rr` or `:nothing`
18
+ (or any module that implements the adapter interface). RSpec 2 did
19
+ fuzzy matching but this will not be supported going forward.
20
+ (Myron Marston)
21
+ * Deprecate `show_failures_in_pending_blocks` config option. To achieve
22
+ the same behavior as the option enabled, you can use a custom
23
+ formatter instead. (Xavier Shay)
24
+ * Add a deprecation warning for the fact that the behavior of `pending`
25
+ is changing in RSpec 3 -- rather than skipping the example (as it did
26
+ in 2.x when no block was provided), it will run the example and mark
27
+ it as failed if no exception is raised. Use `skip` instead to preserve
28
+ the old behavior. (Xavier Shay)
29
+ * Deprecate 's', 'n', 'spec' and 'nested' as aliases for documentation
30
+ formatter. (Jon Rowe)
31
+ * Deprecate `RSpec::Core::Reporter#abort` in favor of
32
+ `RSpec::Core::Reporter#finish`. (Jon Rowe)
33
+
34
+ Bug Fixes:
35
+
36
+ * Fix failure (undefined method `path`) in end-of-run summary
37
+ when `raise_errors_for_deprecations!` is configured. (Myron Marston)
38
+ * Fix issue were overridding spec ordering from the command line wasnt
39
+ fully recognised interally. (Jon Rowe)
40
+
1
41
  ### 2.99.0.beta1 / 2013-11-07
2
42
  [full changelog](http://github.com/rspec/rspec-core/compare/v2.14.7...v2.99.0.beta1)
3
43
 
@@ -46,9 +46,9 @@ Feature: --line_number option
46
46
 
47
47
  describe 9 do
48
48
 
49
- it { should be > 8 }
49
+ it { is_expected.to be > 8 }
50
50
 
51
- it { should be < 10 }
51
+ it { is_expected.not_to be < 10 }
52
52
 
53
53
  end
54
54
  """
@@ -23,7 +23,7 @@ Feature: basic structure (describe/it)
23
23
  end
24
24
  end
25
25
  """
26
- When I run `rspec sample_spec.rb -fn`
26
+ When I run `rspec sample_spec.rb -f doc`
27
27
  Then the output should contain:
28
28
  """
29
29
  something
@@ -23,7 +23,7 @@ Feature: configure expectation framework
23
23
  end
24
24
 
25
25
  describe 6 do
26
- it { should be_a_multiple_of(3) }
26
+ it { is_expected.to be_a_multiple_of 3 }
27
27
  end
28
28
  """
29
29
  When I run `rspec example_spec.rb`
@@ -73,7 +73,7 @@ Feature: explicit subject
73
73
  context "with index out of bounds" do
74
74
  before { Array.should_receive(:one_two_three).once.and_return([1,2,3]) }
75
75
  subject { Array.one_two_three[42] }
76
- it { should be_nil }
76
+ it { is_expected.to be_nil }
77
77
  end
78
78
  end
79
79
  end
@@ -0,0 +1,71 @@
1
+ Feature: One-liner syntax
2
+
3
+ RSpec supports a one-liner syntax for setting an expectation
4
+ on the `subject`. RSpec will give the examples a doc string
5
+ that is auto-generated from the matcher used in the example.
6
+ This is designed specifically to help avoid duplication in
7
+ situations where the doc string and the matcher used in the
8
+ example mirror each other exactly. When used excessively,
9
+ it can produce documentation output that does not read well
10
+ or contribute to understanding the object you are describing.
11
+
12
+ This comes in two flavors:
13
+
14
+ * `is_expected` is defined simply as `expect(subject)` and is
15
+ designed for when you are using rspec-expectations with its
16
+ newer expect-based syntax.
17
+ * `should` was designed back when rspec-expectations only had
18
+ a should-based syntax. However, it continues to be available
19
+ and work even if the `:should` syntax is disabled (since that
20
+ merely removes `Object#should` but this is
21
+ `RSpec::Core::ExampleGroup#should`).
22
+
23
+ Note: this feature is only available when using rspec-expectations.
24
+
25
+ Scenario: implicit subject
26
+ Given a file named "example_spec.rb" with:
27
+ """ruby
28
+ describe Array do
29
+ describe "when first created" do
30
+ # Rather than:
31
+ # it "should be empty" do
32
+ # subject.should be_empty
33
+ # end
34
+
35
+ it { should be_empty }
36
+ # or
37
+ it { is_expected.to be_empty }
38
+ end
39
+ end
40
+ """
41
+ When I run `rspec example_spec.rb --format doc`
42
+ Then the examples should all pass
43
+ And the output should contain:
44
+ """
45
+ Array
46
+ when first created
47
+ should be empty
48
+ should be empty
49
+ """
50
+
51
+ Scenario: explicit subject
52
+ Given a file named "example_spec.rb" with:
53
+ """ruby
54
+ describe Array do
55
+ describe "with 3 items" do
56
+ subject { [1,2,3] }
57
+ it { should_not be_empty }
58
+ # or
59
+ it { is_expected.not_to be_empty }
60
+ end
61
+ end
62
+ """
63
+ When I run `rspec example_spec.rb --format doc`
64
+ Then the examples should all pass
65
+ And the output should contain:
66
+ """
67
+ Array
68
+ with 3 items
69
+ should not be empty
70
+ should not be empty
71
+ """
@@ -3,53 +3,58 @@ module RSpec
3
3
  # non-rspec lines. This enables errors to be reported at the call site in
4
4
  # the code using the library, which is far more useful than the particular
5
5
  # internal method that raised an error.
6
- class CallerFilter
7
-
8
- RSPEC_LIBS = %w[
9
- core
10
- mocks
11
- expectations
12
- matchers
13
- rails
14
- ]
15
-
16
- ADDITIONAL_TOP_LEVEL_FILES = %w[ autorun ]
17
-
18
- LIB_REGEX = %r{/lib/rspec/(#{(RSPEC_LIBS + ADDITIONAL_TOP_LEVEL_FILES).join('|')})(\.rb|/)}
19
-
20
- if RUBY_VERSION >= '2.0.0'
21
- def self.first_non_rspec_line
22
- # `caller` is an expensive method that scales linearly with the size of
23
- # the stack. The performance hit for fetching it in chunks is small,
24
- # and since the target line is probably near the top of the stack, the
25
- # overall improvement of a chunked search like this is significant.
26
- #
27
- # See benchmarks/caller.rb for measurements.
28
-
29
- # Initial value here is mostly arbitrary, but is chosen to give good
30
- # performance on the common case of creating a double.
31
- increment = 5
32
- i = 1
33
- line = nil
34
-
35
- while !line
36
- stack = caller(i, increment)
37
- raise "No non-lib lines in stack" unless stack
38
-
39
- line = stack.find { |l| l !~ LIB_REGEX }
40
-
41
- i += increment
42
- increment *= 2 # The choice of two here is arbitrary.
43
- end
44
6
 
45
- line
46
- end
47
- else
48
- # Earlier rubies do not support the two argument form of `caller`. This
49
- # fallback is logically the same, but slower.
50
- def self.first_non_rspec_line
51
- caller.find { |line| line !~ LIB_REGEX }
7
+ unless defined?(CallerFilter)
8
+
9
+ class CallerFilter
10
+
11
+ RSPEC_LIBS = %w[
12
+ core
13
+ mocks
14
+ expectations
15
+ matchers
16
+ rails
17
+ ]
18
+
19
+ ADDITIONAL_TOP_LEVEL_FILES = %w[ autorun ]
20
+
21
+ LIB_REGEX = %r{/lib/rspec/(#{(RSPEC_LIBS + ADDITIONAL_TOP_LEVEL_FILES).join('|')})(\.rb|/)}
22
+
23
+ if RUBY_VERSION >= '2.0.0'
24
+ def self.first_non_rspec_line
25
+ # `caller` is an expensive method that scales linearly with the size of
26
+ # the stack. The performance hit for fetching it in chunks is small,
27
+ # and since the target line is probably near the top of the stack, the
28
+ # overall improvement of a chunked search like this is significant.
29
+ #
30
+ # See benchmarks/caller.rb for measurements.
31
+
32
+ # Initial value here is mostly arbitrary, but is chosen to give good
33
+ # performance on the common case of creating a double.
34
+ increment = 5
35
+ i = 1
36
+ line = nil
37
+
38
+ while !line
39
+ stack = caller(i, increment)
40
+ return nil unless stack
41
+
42
+ line = stack.find { |l| l !~ LIB_REGEX }
43
+
44
+ i += increment
45
+ increment *= 2 # The choice of two here is arbitrary.
46
+ end
47
+
48
+ line
49
+ end
50
+ else
51
+ # Earlier rubies do not support the two argument form of `caller`. This
52
+ # fallback is logically the same, but slower.
53
+ def self.first_non_rspec_line
54
+ caller.find { |line| line !~ LIB_REGEX }
55
+ end
52
56
  end
53
57
  end
58
+
54
59
  end
55
60
  end
@@ -190,7 +190,27 @@ module RSpec
190
190
 
191
191
  # When a block passed to pending fails (as expected), display the failure
192
192
  # without reporting it as a failure (default: false).
193
- add_setting :show_failures_in_pending_blocks
193
+ def show_failures_in_pending_blocks=(value)
194
+ RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''))
195
+ |RSpec.configuration.show_failures_in_pending_blocks is being removed
196
+ |with no replacement. Called from #{CallerFilter.first_non_rspec_line}.
197
+ EOS
198
+
199
+ @show_failures_in_pending_blocks = value
200
+ end
201
+
202
+ def show_failures_in_pending_blocks
203
+ RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''))
204
+ |RSpec.configuration.show_failures_in_pending_blocks is being removed
205
+ |with no replacement. Called from #{CallerFilter.first_non_rspec_line}.
206
+ EOS
207
+
208
+ @show_failures_in_pending_blocks
209
+ end
210
+
211
+ def show_failures_in_pending_blocks?
212
+ !!show_failures_in_pending_blocks
213
+ end
194
214
 
195
215
  # Convert symbols to hashes with the symbol as a key with a value of
196
216
  # `true` (default: false).
@@ -250,6 +270,7 @@ module RSpec
250
270
  @filter_manager = FilterManager.new
251
271
  @preferred_options = {}
252
272
  @seed = srand % 0xFFFF
273
+ @ordering_already_forced = false
253
274
  @failure_color = :red
254
275
  @success_color = :green
255
276
  @pending_color = :yellow
@@ -266,9 +287,9 @@ module RSpec
266
287
  # Used to set higher priority option values from the command line.
267
288
  def force(hash)
268
289
  if hash.has_key?(:seed)
269
- hash[:order], hash[:seed] = order_and_seed_from_seed(hash[:seed])
290
+ hash[:order], hash[:seed] = order_and_seed_from_seed(hash[:seed], true)
270
291
  elsif hash.has_key?(:order)
271
- set_order_and_seed(hash)
292
+ set_order_and_seed(hash, true)
272
293
  end
273
294
  @preferred_options.merge!(hash)
274
295
  self.warnings = value_for :warnings, nil
@@ -427,14 +448,19 @@ module RSpec
427
448
  when String, Symbol
428
449
  require case framework.to_s
429
450
  when /rspec/i
451
+ deprecate_unless_mock_adapter_name_is_exact(framework, :rspec)
430
452
  'rspec/core/mocking/with_rspec'
431
453
  when /mocha/i
454
+ deprecate_unless_mock_adapter_name_is_exact(framework, :mocha)
432
455
  'rspec/core/mocking/with_mocha'
433
456
  when /rr/i
457
+ deprecate_unless_mock_adapter_name_is_exact(framework, :rr)
434
458
  'rspec/core/mocking/with_rr'
435
459
  when /flexmock/i
460
+ deprecate_unless_mock_adapter_name_is_exact(framework, :flexmock)
436
461
  'rspec/core/mocking/with_flexmock'
437
462
  else
463
+ deprecate_unless_mock_adapter_name_is_exact(framework, :nothing)
438
464
  'rspec/core/mocking/with_absolutely_nothing'
439
465
  end
440
466
  RSpec::Core::MockFrameworkAdapter
@@ -567,10 +593,13 @@ module RSpec
567
593
  end
568
594
 
569
595
  def debug=(bool)
570
- if bool
571
- # Usually this is called automatically by the --debug CLI option, so the
572
- # deprecation message doesn't mention `RSpec::Core::Configuration#debug=`
596
+ if bool == :cli
573
597
  RSpec.deprecate("RSpec's built-in debugger support",
598
+ :replacement => "a CLI option like `-rruby-debug` or `-rdebugger`",
599
+ :call_site => nil)
600
+ bool = true
601
+ elsif bool
602
+ RSpec.deprecate("RSpec::Core::Configuration#debug=",
574
603
  :replacement => "a CLI option like `-rruby-debug` or `-rdebugger`")
575
604
  else
576
605
  # ...but the only way to call this with a false value is to
@@ -1260,7 +1289,12 @@ MESSAGE
1260
1289
 
1261
1290
  def built_in_formatter(key)
1262
1291
  case key.to_s
1263
- when 'd', 'doc', 'documentation', 's', 'n', 'spec', 'nested'
1292
+ when 'd', 'doc', 'documentation'
1293
+ require 'rspec/core/formatters/documentation_formatter'
1294
+ RSpec::Core::Formatters::DocumentationFormatter
1295
+ when 's', 'n', 'spec', 'nested'
1296
+ RSpec.deprecate "Using `#{key.to_s}` as a shortcut for the DocumentationFormatter",
1297
+ :replacement => "`d`, `doc`, or `documentation`"
1264
1298
  require 'rspec/core/formatters/documentation_formatter'
1265
1299
  RSpec::Core::Formatters::DocumentationFormatter
1266
1300
  when 'h', 'html'
@@ -1319,26 +1353,22 @@ MESSAGE
1319
1353
  File.new(path, 'w')
1320
1354
  end
1321
1355
 
1322
- def order_and_seed_from_seed(value)
1323
- @group_ordering_block = RANDOM_ORDERING
1324
- @example_ordering_block = RANDOM_ORDERING
1325
- @order, @seed = 'rand', value.to_i
1326
- [@order, @seed]
1356
+ def order_and_seed_from_seed(value, force = false)
1357
+ order_and_seed_from_order "rand:#{value}", force
1327
1358
  end
1328
1359
 
1329
- def set_order_and_seed(hash)
1330
- hash[:order], seed = order_and_seed_from_order(hash[:order])
1360
+ def set_order_and_seed(hash, force = false)
1361
+ hash[:order], seed = order_and_seed_from_order(hash[:order], force)
1331
1362
  hash[:seed] = seed if seed
1332
1363
  end
1333
1364
 
1334
- def order_and_seed_from_order(type)
1365
+ def order_and_seed_from_order(type, force = false)
1335
1366
  order, seed = type.to_s.split(':')
1336
1367
  @order = order
1337
1368
  @seed = seed = seed.to_i if seed
1338
1369
 
1339
1370
  if order.to_s.match(/rand/)
1340
- @group_ordering_block = RANDOM_ORDERING
1341
- @example_ordering_block = RANDOM_ORDERING
1371
+ ordering = RANDOM_ORDERING
1342
1372
  elsif %w[ default defined ].include?(order)
1343
1373
  if order == 'default'
1344
1374
  RSpec.deprecate("RSpec::Core::Configuration#order = 'default'",
@@ -1346,10 +1376,15 @@ MESSAGE
1346
1376
  end
1347
1377
 
1348
1378
  @order, @seed = nil, nil
1349
- @group_ordering_block = DEFAULT_ORDERING
1350
- @example_ordering_block = DEFAULT_ORDERING
1379
+ ordering = DEFAULT_ORDERING
1351
1380
  end
1352
1381
 
1382
+ unless @ordering_already_forced
1383
+ @group_ordering_block = ordering
1384
+ @example_ordering_block = ordering
1385
+ end
1386
+ @ordering_already_forced = true if force
1387
+
1353
1388
  return order, seed
1354
1389
  end
1355
1390
 
@@ -1357,6 +1392,11 @@ MESSAGE
1357
1392
  [DEFAULT_ORDERING, RANDOM_ORDERING].include?(block)
1358
1393
  end
1359
1394
 
1395
+ def deprecate_unless_mock_adapter_name_is_exact(name, expected)
1396
+ return if name == expected
1397
+ RSpec.deprecate("`config.mock_with #{name.inspect}`", :replacement => "`config.mock_with :#{expected}`")
1398
+ end
1399
+
1360
1400
  end
1361
1401
  end
1362
1402
  end
@@ -44,7 +44,7 @@ module RSpec
44
44
  delegate_to_metadata :full_description, :execution_result, :file_path, :pending, :location
45
45
 
46
46
  # Returns the string submitted to `example` or its aliases (e.g.
47
- # `specify`, `it`, etc). If no string is submitted (e.g. `it { should
47
+ # `specify`, `it`, etc). If no string is submitted (e.g. `it { is_expected.to
48
48
  # do_something }`) it returns the message generated by the matcher if
49
49
  # there is one, otherwise returns a message including the location of the
50
50
  # example.
@@ -62,6 +62,22 @@ module RSpec
62
62
  def self.define_example_method(name, extra_options={})
63
63
  module_eval(<<-END_RUBY, __FILE__, __LINE__)
64
64
  def #{name}(desc=nil, *args, &block)
65
+ if #{name.inspect} == :pending
66
+ RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\\|/, ''))
67
+ |The semantics of `RSpec::Core::ExampleGroup#pending` are changing in RSpec 3.
68
+ |In RSpec 2.x, it caused the example to be skipped. In RSpec 3, the example will
69
+ |still be run but is expected to fail, and will be marked as a failure (rather
70
+ |than as pending) if the example passes, just like how `pending` with a block
71
+ |from within an example already works.
72
+ |
73
+ |To keep the same skip semantics, change `pending` to `skip`. Otherwise, if you
74
+ |want the new RSpec 3 behavior, you can safely ignore this warning and continue
75
+ |to upgrade to RSpec 3 without addressing it.
76
+ |
77
+ |Called from \#{CallerFilter.first_non_rspec_line}.
78
+ |
79
+ EOS
80
+ end
65
81
  options = build_metadata_hash_from(args)
66
82
  options.update(:pending => RSpec::Core::Pending::NOT_YET_IMPLEMENTED) unless block
67
83
  options.update(#{extra_options.inspect})
@@ -108,6 +124,10 @@ module RSpec
108
124
  # Shortcut to define an example with :pending => true
109
125
  # @see example
110
126
  define_example_method :pending, :pending => true
127
+ # Shortcut to define an example with :pending => true
128
+ # Backported from RSpec 3 to aid migration.
129
+ # @see example
130
+ define_example_method :skip, :pending => true
111
131
  # Shortcut to define an example with :pending => 'Temporarily disabled with xexample'
112
132
  # @see example
113
133
  define_example_method :xexample, :pending => 'Temporarily disabled with xexample'