rspec-core 2.99.0.beta2 → 2.99.0.rc1

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 (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
@@ -446,7 +446,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
446
446
  describe "custom_colors" do
447
447
  it "uses the custom success color" do
448
448
  RSpec.configure do |config|
449
- config.color_enabled = true
449
+ config.color = true
450
450
  config.tty = true
451
451
  config.success_color = :cyan
452
452
  end
@@ -456,6 +456,10 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
456
456
  end
457
457
 
458
458
  describe "#colorize" do
459
+ before do
460
+ allow(RSpec.configuration).to receive(:color_enabled?) { true }
461
+ end
462
+
459
463
  it "accepts a VT100 integer code and formats the text with it" do
460
464
  expect(formatter.colorize('abc', 32)).to eq "\e[32mabc\e[0m"
461
465
  end
@@ -469,8 +473,25 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
469
473
  end
470
474
  end
471
475
 
472
- described_class::VT100_COLORS.each do |name, number|
473
- next if name == :black
476
+ describe "#const_missing name" do
477
+
478
+ it "warns of deprecation for VT100_COLORS" do
479
+ expect_deprecation_with_call_site __FILE__, __LINE__ + 1
480
+ expect(described_class::VT100_COLORS).to eq RSpec::Core::Formatters::ConsoleCodes::VT100_CODES
481
+ end
482
+
483
+ it "warns of deprecation for VT100_COLOR_CODES" do
484
+ expect_deprecation_with_call_site __FILE__, __LINE__ + 1
485
+ expect(described_class::VT100_COLOR_CODES).to eq RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.to_set
486
+ end
487
+
488
+ it "behaves normally for other constants" do
489
+ expect { described_class::NoSuchConst }.to raise_error(NameError)
490
+ end
491
+ end
492
+
493
+ RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.each do |name, number|
494
+ next if name == :black || name == :bold
474
495
 
475
496
  describe "##{name}" do
476
497
  before do
@@ -490,5 +511,4 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
490
511
  end
491
512
  end
492
513
  end
493
-
494
514
  end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'rspec/core/formatters/console_codes'
3
+
4
+ RSpec.describe "RSpec::Core::Formatters::ConsoleCodes" do
5
+ let(:console_codes) { RSpec::Core::Formatters::ConsoleCodes }
6
+
7
+ describe "#console_code_for(code_or_symbol)" do
8
+ context "when given a VT100 integer code" do
9
+ it "returns the code" do
10
+ expect(console_codes.console_code_for(32)).to eq 32
11
+ end
12
+ end
13
+
14
+ context "when given a symbolic name" do
15
+ it "returns the code" do
16
+ expect(console_codes.console_code_for(:green)).to eq 32
17
+ end
18
+ end
19
+
20
+ context "when given a nonexistant code" do
21
+ it "returns the code for white" do
22
+ expect(console_codes.console_code_for(:octarine)).to eq 37
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "#wrap" do
28
+ before do
29
+ allow(RSpec.configuration).to receive(:color_enabled?) { true }
30
+ end
31
+
32
+ context "when given a VT100 integer code" do
33
+ it "formats the text with it" do
34
+ expect(console_codes.wrap('abc', 32)).to eq "\e[32mabc\e[0m"
35
+ end
36
+ end
37
+
38
+ context "when given a symbolic color name" do
39
+ it "translates it to the correct integer code and formats the text with it" do
40
+ expect(console_codes.wrap('abc', :green)).to eq "\e[32mabc\e[0m"
41
+ end
42
+ end
43
+
44
+ context "when given :bold" do
45
+ it "formats the text as bold" do
46
+ expect(console_codes.wrap('abc', :bold)).to eq "\e[1mabc\e[0m"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -39,6 +39,23 @@ module RSpec::Core::Formatters
39
39
  expect(deprecation_stream.read).to eq "this message\n"
40
40
  end
41
41
 
42
+ it "surrounds multiline messages in fenceposts" do
43
+ multiline_message = <<-EOS.gsub(/^\s+\|/, '')
44
+ |line one
45
+ |line two
46
+ EOS
47
+ formatter.deprecation(:message => multiline_message)
48
+ deprecation_stream.rewind
49
+
50
+ expected = <<-EOS.gsub(/^\s+\|/, '')
51
+ |--------------------------------------------------------------------------------
52
+ |line one
53
+ |line two
54
+ |--------------------------------------------------------------------------------
55
+ EOS
56
+ expect(deprecation_stream.read).to eq expected
57
+ end
58
+
42
59
  it "includes the method" do
43
60
  formatter.deprecation(:deprecated => "i_am_deprecated")
44
61
  deprecation_stream.rewind
@@ -162,7 +179,7 @@ module RSpec::Core::Formatters
162
179
  |i_am_deprecated is deprecated. Called from foo.rb:1.
163
180
  |i_am_deprecated is deprecated. Called from foo.rb:2.
164
181
  |i_am_deprecated is deprecated. Called from foo.rb:3.
165
- |Too many uses of deprecated 'i_am_deprecated'. Set config.deprecation_stream to a File for full output.
182
+ |Too many uses of deprecated 'i_am_deprecated'. #{DeprecationFormatter::DEPRECATION_STREAM_NOTICE}
166
183
  |
167
184
  |#{DeprecationFormatter::RAISE_ERROR_CONFIG_NOTICE}
168
185
  EOS
@@ -186,7 +203,7 @@ module RSpec::Core::Formatters
186
203
  |i_am_deprecated 0 is deprecated. Called from foo.rb:1.
187
204
  |i_am_deprecated 1 is deprecated. Called from foo.rb:2.
188
205
  |i_am_deprecated 2 is deprecated. Called from foo.rb:3.
189
- |Too many uses of deprecated 'i_am_deprecated'. Set config.deprecation_stream to a File for full output.
206
+ |Too many uses of deprecated 'i_am_deprecated'. #{DeprecationFormatter::DEPRECATION_STREAM_NOTICE}
190
207
  |
191
208
  |#{DeprecationFormatter::RAISE_ERROR_CONFIG_NOTICE}
192
209
  EOS
@@ -207,7 +224,7 @@ module RSpec::Core::Formatters
207
224
  |This is a long string with some callsite info: /path/0/to/some/file.rb:203. And some more stuff can come after.
208
225
  |This is a long string with some callsite info: /path/1/to/some/file.rb:213. And some more stuff can come after.
209
226
  |This is a long string with some callsite info: /path/2/to/some/file.rb:223. And some more stuff can come after.
210
- |Too many similar deprecation messages reported, disregarding further reports. Set config.deprecation_stream to a File for full output.
227
+ |Too many similar deprecation messages reported, disregarding further reports. #{DeprecationFormatter::DEPRECATION_STREAM_NOTICE}
211
228
  |
212
229
  |#{DeprecationFormatter::RAISE_ERROR_CONFIG_NOTICE}
213
230
  EOS
@@ -3,6 +3,7 @@ require 'rspec/core/formatters/documentation_formatter'
3
3
 
4
4
  module RSpec::Core::Formatters
5
5
  describe DocumentationFormatter do
6
+
6
7
  it "numbers the failures" do
7
8
 
8
9
  examples = [
@@ -387,12 +387,11 @@ expected: 2
387
387
  </dd>
388
388
  </dl>
389
389
  </div>
390
+
391
+ 2 deprecation warnings total
390
392
  <script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>n.nnnn seconds</strong>";</script>
391
393
  <script type="text/javascript">document.getElementById('totals').innerHTML = "7 examples, 4 failures, 2 pending";</script>
392
394
  </div>
393
395
  </div>
394
396
  </body>
395
- </html><html><p>
396
-
397
- 2 deprecation warnings total
398
- </p></html>
397
+ </html>
@@ -6,7 +6,7 @@ require 'nokogiri'
6
6
  module RSpec
7
7
  module Core
8
8
  module Formatters
9
- describe HtmlFormatter, :if => RUBY_VERSION =~ /^(1.8.7|1.9.2|1.9.3|2.0.0)$/ do
9
+ describe HtmlFormatter do
10
10
 
11
11
  let(:root) { File.expand_path("#{File.dirname(__FILE__)}/../../../..") }
12
12
  let(:expected_file) do
@@ -23,9 +23,15 @@ module RSpec
23
23
  err.set_encoding("utf-8") if err.respond_to?(:set_encoding)
24
24
  out.set_encoding("utf-8") if out.respond_to?(:set_encoding)
25
25
 
26
- command_line = RSpec::Core::CommandLine.new(options)
27
- command_line.instance_variable_get("@configuration").backtrace_cleaner.inclusion_patterns = []
28
- command_line.run(err, out)
26
+ runner = RSpec::Core::Runner.new(options)
27
+ configuration = runner.instance_variable_get(:@configuration)
28
+
29
+ configuration.backtrace_formatter.inclusion_patterns = []
30
+ configuration.output_stream = out
31
+ configuration.deprecation_stream = err
32
+
33
+ runner.run(err, out)
34
+
29
35
  html = out.string.gsub(/\d+\.\d+(s| seconds)/, "n.nnnn\\1")
30
36
 
31
37
  actual_doc = Nokogiri::HTML(html)
@@ -387,12 +387,11 @@ expected: 2
387
387
  </dd>
388
388
  </dl>
389
389
  </div>
390
+
391
+ 2 deprecation warnings total
390
392
  <script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>n.nnnn seconds</strong>";</script>
391
393
  <script type="text/javascript">document.getElementById('totals').innerHTML = "7 examples, 4 failures, 2 pending";</script>
392
394
  </div>
393
395
  </div>
394
396
  </body>
395
- </html><html><p>
396
-
397
- 2 deprecation warnings total
398
- </p></html>
397
+ </html>
@@ -14,6 +14,7 @@ module RSpec
14
14
  end
15
15
 
16
16
  let(:generated_html) do
17
+ allow(RSpec).to receive(:deprecate)
17
18
  options = RSpec::Core::ConfigurationOptions.new(
18
19
  %w[spec/rspec/core/resources/formatter_specs.rb --format textmate --order defined]
19
20
  )
@@ -23,9 +24,14 @@ module RSpec
23
24
  err.set_encoding("utf-8") if err.respond_to?(:set_encoding)
24
25
  out.set_encoding("utf-8") if out.respond_to?(:set_encoding)
25
26
 
26
- command_line = RSpec::Core::CommandLine.new(options)
27
- command_line.instance_variable_get("@configuration").backtrace_cleaner.inclusion_patterns = []
28
- command_line.run(err, out)
27
+ runner = RSpec::Core::Runner.new(options)
28
+ configuration = runner.instance_variable_get(:@configuration)
29
+
30
+ configuration.backtrace_formatter.inclusion_patterns = []
31
+ configuration.output_stream = out
32
+ configuration.deprecation_stream = err
33
+
34
+ runner.run(err, out)
29
35
  html = out.string.gsub(/\d+\.\d+(s| seconds)/, "n.nnnn\\1")
30
36
 
31
37
  actual_doc = Nokogiri::HTML(html)
@@ -35,7 +35,7 @@ module RSpec::Core
35
35
  c.before(:match => true) { filters << "before each in config"}
36
36
  c.after(:match => true) { filters << "after each in config"}
37
37
  end
38
- group = ExampleGroup.describe(:match => true)
38
+ group = ExampleGroup.describe("group", :match => true)
39
39
  group.example("example") {}
40
40
  group.run
41
41
  expect(filters).to eq([
@@ -55,7 +55,7 @@ module RSpec::Core
55
55
  c.after(:each, :match => true) { filters << "after each in config"}
56
56
  c.after(:all, :match => true) { filters << "after all in config"}
57
57
  end
58
- group = ExampleGroup.describe(:match => true)
58
+ group = ExampleGroup.describe("group", :match => true)
59
59
  group.example("example") {}
60
60
  group.run
61
61
  expect(filters).to eq([
@@ -125,7 +125,7 @@ module RSpec::Core
125
125
  c.after(:each, :match => false) { filters << "after each in config"}
126
126
  c.after(:all, :match => false) { filters << "after all in config"}
127
127
  end
128
- group = ExampleGroup.describe(:match => true)
128
+ group = ExampleGroup.describe("group", :match => true)
129
129
  group.example("example") {}
130
130
  group.run
131
131
  expect(filters).to eq([])
@@ -196,7 +196,7 @@ module RSpec::Core
196
196
  c.after(:each, :one => 1, :two => 2, :three => 3) { filters << "after each in config"}
197
197
  c.after(:all, :one => 1, :three => 3) { filters << "after all in config"}
198
198
  end
199
- group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
199
+ group = ExampleGroup.describe("group", :one => 1, :two => 2, :three => 3)
200
200
  group.example("example") {}
201
201
  group.run
202
202
  expect(filters).to eq([
@@ -217,7 +217,7 @@ module RSpec::Core
217
217
  c.after(:each, :one => 1, :two => 2, :three => 3, :four => 4) { filters << "after each in config"}
218
218
  c.after(:all, :one => 1, :three => 3, :four => 4) { filters << "after all in config"}
219
219
  end
220
- group = ExampleGroup.describe(:one => 1, :two => 2, :three => 3)
220
+ group = ExampleGroup.describe("group", :one => 1, :two => 2, :three => 3)
221
221
  group.example("example") {}
222
222
  group.run
223
223
  expect(filters).to eq([])
@@ -37,6 +37,44 @@ module RSpec::Core
37
37
  end
38
38
  end
39
39
 
40
+ describe "with a symbol" do
41
+ it "returns the string form and issues a deprecation warning" do
42
+ the_subject = :unset
43
+ deprecations = []
44
+ allow(RSpec).to receive(:warn_deprecation) { |msg| deprecations << msg }
45
+
46
+ line = __LINE__ + 1
47
+ ExampleGroup.describe :symbol do
48
+ example { the_subject = subject }
49
+ end.run
50
+
51
+ expect(the_subject).to eq("symbol")
52
+ expect(deprecations.size).to eq(1)
53
+ deprecation = deprecations.first
54
+ expect(deprecation).to match(/describe <a Symbol>/)
55
+ expect(deprecation).to include("#{__FILE__}:#{line}")
56
+ end
57
+ end
58
+
59
+ describe "with a hash" do
60
+ it "returns a blank string and issues a deprecation warning" do
61
+ the_subject = :unset
62
+ deprecations = []
63
+ allow(RSpec).to receive(:warn_deprecation) { |msg| deprecations << msg }
64
+
65
+ line = __LINE__ + 1
66
+ ExampleGroup.describe :foo => 3 do
67
+ example { the_subject = subject }
68
+ end.run
69
+
70
+ expect(the_subject).to eq("")
71
+ expect(deprecations.size).to eq(1)
72
+ deprecation = deprecations.first
73
+ expect(deprecation).to match(/describe <a Hash>/)
74
+ expect(deprecation).to include("#{__FILE__}:#{line}")
75
+ end
76
+ end
77
+
40
78
  it "can be overriden and super'd to from a nested group" do
41
79
  outer_subject_value = inner_subject_value = nil
42
80
 
@@ -115,6 +115,29 @@ module RSpec
115
115
  it_has_behavior "matching by line number"
116
116
  end
117
117
 
118
+ context "with a :line_numbers filter" do
119
+ before(:each) { Metadata.line_number_filter_deprecation_issued = false }
120
+ after(:all) { Metadata.line_number_filter_deprecation_issued = false }
121
+ let(:metadata) { Metadata.new.process("group") }
122
+
123
+ context "when a line number filter is applied manually (e.g. not from the command line)" do
124
+ it 'issues a deprecation warning' do
125
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /:line_numbers/)
126
+ metadata.filter_applies?(:line_numbers, [2])
127
+ end
128
+ end
129
+
130
+ context "when a line number filter is applied from the command line" do
131
+ it "does not issue an additional deprecation" do
132
+ allow_deprecation
133
+ Parser.parse!(["--line-number", "3"])
134
+
135
+ expect_no_deprecation
136
+ metadata.filter_applies?(:line_numbers, [2])
137
+ end
138
+ end
139
+ end
140
+
118
141
  context "with locations" do
119
142
  let(:condition_key){ :locations }
120
143
  let(:parent_group_condition) do
@@ -261,7 +284,7 @@ module RSpec
261
284
  end
262
285
 
263
286
  [:described_class, :describes].each do |key|
264
- describe key do
287
+ describe key.inspect do
265
288
  context "with a String" do
266
289
  it "returns nil" do
267
290
  m = Metadata.new
@@ -27,7 +27,7 @@ module RSpec::Core
27
27
 
28
28
  describe "--formatter" do
29
29
  it "is deprecated" do
30
- RSpec.should_receive(:deprecate)
30
+ expect_deprecation_with_no_call_site(%r{`--formatter`})
31
31
  Parser.parse!(%w[--formatter doc])
32
32
  end
33
33
 
@@ -38,6 +38,11 @@ module RSpec::Core
38
38
  end
39
39
 
40
40
  describe "--default_path" do
41
+ it "is deprecated" do
42
+ expect_deprecation_with_no_call_site(%r{`--default_path`})
43
+ Parser.parse!(%w[--default_path foo])
44
+ end
45
+
41
46
  it "gets converted to --default-path" do
42
47
  options = Parser.parse!(%w[--default_path foo])
43
48
  expect(options[:default_path]).to eq "foo"
@@ -45,13 +50,17 @@ module RSpec::Core
45
50
  end
46
51
 
47
52
  describe "--line_number" do
53
+ it "is deprecated" do
54
+ expect_deprecation_with_no_call_site(%r{`--line-number`/`-l`})
55
+ Parser.parse!(%w[--line_number 3])
56
+ end
57
+
48
58
  it "gets converted to --line-number" do
49
59
  options = Parser.parse!(%w[--line_number 3])
50
60
  expect(options[:line_numbers]).to eq ["3"]
51
61
  end
52
62
  end
53
63
 
54
-
55
64
  describe "--default-path" do
56
65
  it "sets the default path where RSpec looks for examples" do
57
66
  options = Parser.parse!(%w[--default-path foo])
@@ -65,6 +74,11 @@ module RSpec::Core
65
74
  options = Parser.parse!([option, "3"])
66
75
  expect(options[:line_numbers]).to eq ["3"]
67
76
  end
77
+
78
+ it "is deprecated" do
79
+ expect_deprecation_with_no_call_site(%r{`--line-number`/`-l`})
80
+ Parser.parse!([option, "3"])
81
+ end
68
82
  end
69
83
  end
70
84
 
@@ -77,6 +91,29 @@ module RSpec::Core
77
91
  end
78
92
  end
79
93
 
94
+ describe "--deprecation-out" do
95
+ it 'configures the deprecation stream' do
96
+ expect {
97
+ Parser.parse!(['--deprecation-out', 'path/to/file.log'])
98
+ }.to change { RSpec.configuration.deprecation_stream }.to('path/to/file.log')
99
+ end
100
+
101
+ it 'sets the deprecation stream before processing other options that issue deprecations' do
102
+ expect(RSpec).to receive(:deprecate) do
103
+ expect(RSpec.configuration.deprecation_stream).to eq('path/to/file.log')
104
+ end
105
+
106
+ Parser.parse!(['--line-number', '3', '--deprecation-out', 'path/to/file.log'])
107
+ end
108
+
109
+ it 'issues an appropriate error when no file arg is provided' do
110
+ out_error = Parser.parse!(['--out']) rescue $!
111
+ expect {
112
+ Parser.parse!(['--deprecation-out'])
113
+ }.to raise_error(out_error.class, out_error.message.gsub('--out', '--deprecation-out'))
114
+ end
115
+ end
116
+
80
117
  %w[--out -o].each do |option|
81
118
  describe option do
82
119
  let(:options) { Parser.parse!([option, 'out.txt']) }