rspec-core 2.13.1 → 2.14.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/Changelog.md +80 -0
  2. data/exe/autospec +1 -1
  3. data/features/README.md +2 -2
  4. data/features/command_line/format_option.feature +8 -14
  5. data/features/command_line/line_number_appended_to_path.feature +4 -4
  6. data/features/command_line/line_number_option.feature +1 -1
  7. data/features/command_line/rake_task.feature +2 -2
  8. data/features/command_line/require_option.feature +43 -0
  9. data/features/command_line/ruby.feature +2 -2
  10. data/features/command_line/warnings_option.feature +27 -0
  11. data/features/configuration/backtrace_clean_patterns.feature +2 -2
  12. data/features/configuration/deprecation_stream.feature +58 -0
  13. data/features/configuration/pattern.feature +8 -0
  14. data/features/configuration/profile.feature +59 -2
  15. data/features/configuration/read_options_from_file.feature +8 -5
  16. data/features/configuration/run_all_when_everything_filtered.feature +20 -4
  17. data/features/example_groups/basic_structure.feature +1 -1
  18. data/features/example_groups/shared_context.feature +1 -1
  19. data/features/example_groups/shared_examples.feature +72 -0
  20. data/features/filtering/exclusion_filters.feature +10 -10
  21. data/features/formatters/custom_formatter.feature +1 -1
  22. data/features/hooks/before_and_after_hooks.feature +19 -19
  23. data/features/mock_framework_integration/use_any_framework.feature +6 -6
  24. data/features/mock_framework_integration/use_flexmock.feature +3 -3
  25. data/features/mock_framework_integration/use_mocha.feature +3 -3
  26. data/features/mock_framework_integration/use_rr.feature +3 -3
  27. data/features/mock_framework_integration/use_rspec.feature +3 -3
  28. data/features/subject/implicit_subject.feature +1 -1
  29. data/lib/rspec/core.rb +20 -3
  30. data/lib/rspec/core/backtrace_cleaner.rb +46 -0
  31. data/lib/rspec/core/backward_compatibility.rb +3 -13
  32. data/lib/rspec/core/configuration.rb +136 -49
  33. data/lib/rspec/core/configuration_options.rb +19 -8
  34. data/lib/rspec/core/deprecation.rb +18 -30
  35. data/lib/rspec/core/example.rb +3 -3
  36. data/lib/rspec/core/example_group.rb +4 -3
  37. data/lib/rspec/core/extensions/kernel.rb +1 -1
  38. data/lib/rspec/core/filter_manager.rb +1 -1
  39. data/lib/rspec/core/formatters.rb +1 -1
  40. data/lib/rspec/core/formatters/base_formatter.rb +10 -1
  41. data/lib/rspec/core/formatters/base_text_formatter.rb +47 -10
  42. data/lib/rspec/core/formatters/deprecation_formatter.rb +35 -0
  43. data/lib/rspec/core/formatters/helpers.rb +12 -5
  44. data/lib/rspec/core/formatters/html_formatter.rb +7 -6
  45. data/lib/rspec/core/formatters/html_printer.rb +13 -12
  46. data/lib/rspec/core/formatters/json_formatter.rb +1 -2
  47. data/lib/rspec/core/formatters/text_mate_formatter.rb +1 -1
  48. data/lib/rspec/core/hooks.rb +9 -0
  49. data/lib/rspec/core/memoized_helpers.rb +19 -8
  50. data/lib/rspec/core/metadata.rb +3 -1
  51. data/lib/rspec/core/mocking/with_flexmock.rb +1 -1
  52. data/lib/rspec/core/mocking/with_rr.rb +1 -1
  53. data/lib/rspec/core/option_parser.rb +6 -2
  54. data/lib/rspec/core/pending.rb +1 -0
  55. data/lib/rspec/core/rake_task.rb +11 -19
  56. data/lib/rspec/core/reporter.rb +33 -4
  57. data/lib/rspec/core/shared_example_group.rb +56 -16
  58. data/lib/rspec/core/shared_example_group/collection.rb +42 -0
  59. data/lib/rspec/core/version.rb +1 -1
  60. data/lib/rspec/core/world.rb +2 -3
  61. data/spec/autotest/rspec_spec.rb +2 -2
  62. data/spec/rspec/core/backtrace_cleaner_spec.rb +68 -0
  63. data/spec/rspec/core/configuration_options_spec.rb +15 -4
  64. data/spec/rspec/core/configuration_spec.rb +202 -19
  65. data/spec/rspec/core/deprecation_spec.rb +41 -0
  66. data/spec/rspec/core/deprecations_spec.rb +10 -12
  67. data/spec/rspec/core/drb_command_line_spec.rb +1 -1
  68. data/spec/rspec/core/example_group_spec.rb +37 -36
  69. data/spec/rspec/core/example_spec.rb +25 -4
  70. data/spec/rspec/core/filter_manager_spec.rb +6 -6
  71. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +101 -36
  72. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +78 -0
  73. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +2 -2
  74. data/spec/rspec/core/formatters/helpers_spec.rb +23 -7
  75. data/spec/rspec/core/formatters/html_formatted-1.8.7-jruby.html +20 -14
  76. data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +69 -169
  77. data/spec/rspec/core/formatters/html_formatted-1.8.7.html +28 -23
  78. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +42 -33
  79. data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +17 -23
  80. data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +57 -157
  81. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +42 -33
  82. data/spec/rspec/core/formatters/html_formatted-2.0.0.html +42 -33
  83. data/spec/rspec/core/formatters/html_formatter_spec.rb +1 -0
  84. data/spec/rspec/core/formatters/progress_formatter_spec.rb +3 -3
  85. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-jruby.html +11 -14
  86. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7-rbx.html +103 -203
  87. data/spec/rspec/core/formatters/text_mate_formatted-1.8.7.html +30 -25
  88. data/spec/rspec/core/formatters/text_mate_formatted-1.9.2.html +42 -33
  89. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3-jruby.html +20 -14
  90. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3-rbx.html +103 -203
  91. data/spec/rspec/core/formatters/text_mate_formatted-1.9.3.html +42 -33
  92. data/spec/rspec/core/formatters/text_mate_formatted-2.0.0.html +42 -33
  93. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -0
  94. data/spec/rspec/core/memoized_helpers_spec.rb +28 -0
  95. data/spec/rspec/core/metadata_spec.rb +8 -3
  96. data/spec/rspec/core/option_parser_spec.rb +8 -0
  97. data/spec/rspec/core/project_initializer_spec.rb +2 -2
  98. data/spec/rspec/core/rake_task_spec.rb +8 -8
  99. data/spec/rspec/core/reporter_spec.rb +26 -6
  100. data/spec/rspec/core/resources/formatter_specs.rb +3 -3
  101. data/spec/rspec/core/shared_context_spec.rb +20 -0
  102. data/spec/rspec/core/shared_example_group/collection_spec.rb +70 -0
  103. data/spec/rspec/core/shared_example_group_spec.rb +4 -4
  104. data/spec/rspec/core/world_spec.rb +1 -3
  105. data/spec/rspec/core_spec.rb +20 -0
  106. data/spec/spec_helper.rb +29 -29
  107. data/spec/support/helper_methods.rb +9 -1
  108. data/spec/support/isolate_load_path_mutation.rb +6 -0
  109. data/spec/support/sandboxed_mock_space.rb +100 -0
  110. metadata +28 -13
  111. data/features/filtering/run_all_when_everything_filtered.feature +0 -46
  112. data/lib/rspec/core/load_path.rb +0 -3
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe RSpec::Core::Deprecation do
4
+ describe "#deprecate" do
5
+ context "old API with individual args" do
6
+ it "includes the method to deprecate" do
7
+ expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method")
8
+ RSpec.deprecate("deprecated_method")
9
+ end
10
+
11
+ it "includes the replacement when provided" do
12
+ expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method", :replacement => "replacement")
13
+ RSpec.deprecate("deprecated_method", "replacement")
14
+ end
15
+
16
+ it "adds the call site" do
17
+ expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :call_site => caller(0)[1])
18
+ RSpec.deprecate("deprecated_method")
19
+ end
20
+ end
21
+
22
+ context "new API with a hash after the first arg" do
23
+ it "passes the hash to the reporter" do
24
+ expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :deprecated => "deprecated_method", :replacement => "replacement")
25
+ RSpec.deprecate("deprecated_method", :replacement => "replacement")
26
+ end
27
+
28
+ it "adds the call site" do
29
+ expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :call_site => caller(0)[1])
30
+ RSpec.deprecate("deprecated_method")
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#warn_deprecation" do
36
+ it "puts message in a hash" do
37
+ expect(RSpec.configuration.reporter).to receive(:deprecation).with(hash_including :message => "this is the message")
38
+ RSpec.warn_deprecation("this is the message")
39
+ end
40
+ end
41
+ end
@@ -1,19 +1,19 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "deprecations" do
3
+ describe "deprecated methods" do
4
4
  describe "Spec" do
5
5
  it "is deprecated" do
6
- RSpec.should_receive(:warn_deprecation).with(/Spec .* RSpec/i)
6
+ RSpec.should_receive(:deprecate)
7
7
  Spec
8
8
  end
9
9
 
10
10
  it "returns RSpec" do
11
- RSpec.stub(:warn_deprecation)
11
+ RSpec.stub(:deprecate)
12
12
  expect(Spec).to eq(RSpec)
13
13
  end
14
14
 
15
15
  it "doesn't include backward compatibility in const_missing backtrace" do
16
- RSpec.stub(:warn_deprecation)
16
+ RSpec.stub(:deprecate)
17
17
  exception = nil
18
18
  begin
19
19
  ConstantThatDoesNotExist
@@ -26,12 +26,12 @@ describe "deprecations" do
26
26
  describe RSpec::Core::ExampleGroup do
27
27
  describe 'running_example' do
28
28
  it 'is deprecated' do
29
- RSpec.should_receive(:warn_deprecation)
29
+ RSpec.should_receive(:deprecate).at_least(:once)
30
30
  self.running_example
31
31
  end
32
32
 
33
33
  it "delegates to example" do
34
- RSpec.stub(:warn_deprecation)
34
+ RSpec.stub(:deprecate)
35
35
  expect(running_example).to eq(example)
36
36
  end
37
37
  end
@@ -40,7 +40,7 @@ describe "deprecations" do
40
40
  describe RSpec::Core::SharedExampleGroup do
41
41
  describe 'share_as' do
42
42
  it 'is deprecated' do
43
- RSpec.should_receive(:warn_deprecation)
43
+ RSpec.should_receive(:deprecate).at_least(:once)
44
44
  RSpec::Core::SharedExampleGroup.share_as(:DeprecatedSharedConst) {}
45
45
  end
46
46
  end
@@ -48,21 +48,19 @@ describe "deprecations" do
48
48
 
49
49
  describe "Spec::Runner.configure" do
50
50
  it "is deprecated" do
51
- RSpec.stub(:warn_deprecation)
52
- RSpec.should_receive(:deprecate)
51
+ RSpec.should_receive(:deprecate).at_least(:once)
53
52
  Spec::Runner.configure
54
53
  end
55
54
  end
56
55
 
57
56
  describe "Spec::Rake::SpecTask" do
58
57
  it "is deprecated" do
59
- RSpec.stub(:warn_deprecation)
60
- RSpec.should_receive(:deprecate)
58
+ RSpec.should_receive(:deprecate).at_least(:once)
61
59
  Spec::Rake::SpecTask
62
60
  end
63
61
 
64
62
  it "doesn't include backward compatibility in const_missing backtrace" do
65
- RSpec.stub(:warn_deprecation)
63
+ RSpec.stub(:deprecate)
66
64
  exception = nil
67
65
  begin
68
66
  Spec::Rake::ConstantThatDoesNotExist
@@ -96,7 +96,7 @@ describe "::DRbCommandLine", :type => :drb, :unless => RUBY_PLATFORM == 'java' d
96
96
  pending "figure out a way to tell the output to say it's tty"
97
97
  command_line(failing_spec_filename, "--color", "--drb-port", @drb_port).run(err, out)
98
98
  out.rewind
99
- expect(out.read).to match /\e\[31m/m
99
+ expect(out.read).to match(/\e\[31m/m)
100
100
  end
101
101
  end
102
102
  end
@@ -906,7 +906,7 @@ module RSpec::Core
906
906
 
907
907
  it "sets RSpec.wants_to_quit flag if encountering an exception in before(:all)" do
908
908
  group.before(:all) { raise "error in before all" }
909
- example = group.example("equality") { expect(1).to eq(2) }
909
+ group.example("equality") { expect(1).to eq(2) }
910
910
  expect(group.run).to be_false
911
911
  expect(RSpec.wants_to_quit).to be_true
912
912
  end
@@ -995,20 +995,19 @@ module RSpec::Core
995
995
 
996
996
  %w[include_examples include_context].each do |name|
997
997
  describe "##{name}" do
998
+ let(:group) { ExampleGroup.describe }
998
999
  before do
999
- shared_examples "named this" do
1000
+ group.shared_examples "named this" do
1000
1001
  example("does something") {}
1001
1002
  end
1002
1003
  end
1003
1004
 
1004
1005
  it "includes the named examples" do
1005
- group = ExampleGroup.describe
1006
1006
  group.send(name, "named this")
1007
1007
  expect(group.examples.first.description).to eq("does something")
1008
1008
  end
1009
1009
 
1010
1010
  it "raises a helpful error message when shared content is not found" do
1011
- group = ExampleGroup.describe
1012
1011
  expect do
1013
1012
  group.send(name, "shared stuff")
1014
1013
  end.to raise_error(ArgumentError, /Could not find .* "shared stuff"/)
@@ -1016,15 +1015,15 @@ module RSpec::Core
1016
1015
 
1017
1016
  it "passes parameters to the shared content" do
1018
1017
  passed_params = {}
1018
+ group = ExampleGroup.describe
1019
1019
 
1020
- shared_examples "named this with params" do |param1, param2|
1020
+ group.shared_examples "named this with params" do |param1, param2|
1021
1021
  it("has access to the given parameters") do
1022
1022
  passed_params[:param1] = param1
1023
1023
  passed_params[:param2] = param2
1024
1024
  end
1025
1025
  end
1026
1026
 
1027
- group = ExampleGroup.describe
1028
1027
  group.send(name, "named this with params", :value1, :value2)
1029
1028
  group.run
1030
1029
 
@@ -1032,30 +1031,31 @@ module RSpec::Core
1032
1031
  end
1033
1032
 
1034
1033
  it "adds shared instance methods to the group" do
1035
- shared_examples "named this with params" do |param1|
1034
+ group = ExampleGroup.describe('fake group')
1035
+ group.shared_examples "named this with params" do |param1|
1036
1036
  def foo; end
1037
1037
  end
1038
- group = ExampleGroup.describe('fake group')
1039
1038
  group.send(name, "named this with params", :a)
1040
1039
  expect(group.public_instance_methods.map{|m| m.to_s}).to include("foo")
1041
1040
  end
1042
1041
 
1043
1042
  it "evals the shared example group only once" do
1044
1043
  eval_count = 0
1045
- shared_examples("named this with params") { |p| eval_count += 1 }
1046
1044
  group = ExampleGroup.describe('fake group')
1045
+ group.shared_examples("named this with params") { |p| eval_count += 1 }
1047
1046
  group.send(name, "named this with params", :a)
1048
1047
  expect(eval_count).to eq(1)
1049
1048
  end
1050
1049
 
1051
1050
  it "evals the block when given" do
1052
1051
  key = "#{__FILE__}:#{__LINE__}"
1053
- shared_examples(key) do
1054
- it("does something") do
1055
- expect(foo).to eq("bar")
1056
- end
1057
- end
1058
1052
  group = ExampleGroup.describe do
1053
+ shared_examples(key) do
1054
+ it("does something") do
1055
+ expect(foo).to eq("bar")
1056
+ end
1057
+ end
1058
+
1059
1059
  send name, key do
1060
1060
  def foo; "bar"; end
1061
1061
  end
@@ -1067,43 +1067,43 @@ module RSpec::Core
1067
1067
 
1068
1068
  describe "#it_should_behave_like" do
1069
1069
  it "creates a nested group" do
1070
- shared_examples_for("thing") {}
1071
1070
  group = ExampleGroup.describe('fake group')
1071
+ group.shared_examples_for("thing") {}
1072
1072
  group.it_should_behave_like("thing")
1073
1073
  expect(group).to have(1).children
1074
1074
  end
1075
1075
 
1076
1076
  it "creates a nested group for a class" do
1077
1077
  klass = Class.new
1078
- shared_examples_for(klass) {}
1079
1078
  group = ExampleGroup.describe('fake group')
1079
+ group.shared_examples_for(klass) {}
1080
1080
  group.it_should_behave_like(klass)
1081
1081
  expect(group).to have(1).children
1082
1082
  end
1083
1083
 
1084
1084
  it "adds shared examples to nested group" do
1085
- shared_examples_for("thing") do
1085
+ group = ExampleGroup.describe('fake group')
1086
+ group.shared_examples_for("thing") do
1086
1087
  it("does something")
1087
1088
  end
1088
- group = ExampleGroup.describe('fake group')
1089
1089
  shared_group = group.it_should_behave_like("thing")
1090
1090
  expect(shared_group).to have(1).examples
1091
1091
  end
1092
1092
 
1093
1093
  it "adds shared instance methods to nested group" do
1094
- shared_examples_for("thing") do
1094
+ group = ExampleGroup.describe('fake group')
1095
+ group.shared_examples_for("thing") do
1095
1096
  def foo; end
1096
1097
  end
1097
- group = ExampleGroup.describe('fake group')
1098
1098
  shared_group = group.it_should_behave_like("thing")
1099
1099
  expect(shared_group.public_instance_methods.map{|m| m.to_s}).to include("foo")
1100
1100
  end
1101
1101
 
1102
1102
  it "adds shared class methods to nested group" do
1103
- shared_examples_for("thing") do
1103
+ group = ExampleGroup.describe('fake group')
1104
+ group.shared_examples_for("thing") do
1104
1105
  def self.foo; end
1105
1106
  end
1106
- group = ExampleGroup.describe('fake group')
1107
1107
  shared_group = group.it_should_behave_like("thing")
1108
1108
  expect(shared_group.methods.map{|m| m.to_s}).to include("foo")
1109
1109
  end
@@ -1111,34 +1111,35 @@ module RSpec::Core
1111
1111
  it "passes parameters to the shared example group" do
1112
1112
  passed_params = {}
1113
1113
 
1114
- shared_examples_for("thing") do |param1, param2|
1115
- it("has access to the given parameters") do
1116
- passed_params[:param1] = param1
1117
- passed_params[:param2] = param2
1114
+ group = ExampleGroup.describe("group") do
1115
+ shared_examples_for("thing") do |param1, param2|
1116
+ it("has access to the given parameters") do
1117
+ passed_params[:param1] = param1
1118
+ passed_params[:param2] = param2
1119
+ end
1118
1120
  end
1119
- end
1120
1121
 
1121
- group = ExampleGroup.describe("group") do
1122
1122
  it_should_behave_like "thing", :value1, :value2
1123
1123
  end
1124
+
1124
1125
  group.run
1125
1126
 
1126
1127
  expect(passed_params).to eq({ :param1 => :value1, :param2 => :value2 })
1127
1128
  end
1128
1129
 
1129
1130
  it "adds shared instance methods to nested group" do
1130
- shared_examples_for("thing") do |param1|
1131
+ group = ExampleGroup.describe('fake group')
1132
+ group.shared_examples_for("thing") do |param1|
1131
1133
  def foo; end
1132
1134
  end
1133
- group = ExampleGroup.describe('fake group')
1134
1135
  shared_group = group.it_should_behave_like("thing", :a)
1135
1136
  expect(shared_group.public_instance_methods.map{|m| m.to_s}).to include("foo")
1136
1137
  end
1137
1138
 
1138
1139
  it "evals the shared example group only once" do
1139
1140
  eval_count = 0
1140
- shared_examples_for("thing") { |p| eval_count += 1 }
1141
1141
  group = ExampleGroup.describe('fake group')
1142
+ group.shared_examples_for("thing") { |p| eval_count += 1 }
1142
1143
  group.it_should_behave_like("thing", :a)
1143
1144
  expect(eval_count).to eq(1)
1144
1145
  end
@@ -1146,12 +1147,12 @@ module RSpec::Core
1146
1147
  context "given a block" do
1147
1148
  it "evaluates the block in nested group" do
1148
1149
  scopes = []
1149
- shared_examples_for("thing") do
1150
- it("gets run in the nested group") do
1151
- scopes << self.class
1152
- end
1153
- end
1154
1150
  group = ExampleGroup.describe("group") do
1151
+ shared_examples_for("thing") do
1152
+ it("gets run in the nested group") do
1153
+ scopes << self.class
1154
+ end
1155
+ end
1155
1156
  it_should_behave_like "thing" do
1156
1157
  it("gets run in the same nested group") do
1157
1158
  scopes << self.class
@@ -8,7 +8,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
8
8
  end
9
9
 
10
10
  let(:example_instance) do
11
- example_group.example('example description')
11
+ example_group.example('example description') { }
12
12
  end
13
13
 
14
14
  it_behaves_like "metadata hash builder" do
@@ -28,7 +28,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
28
28
  end
29
29
 
30
30
  it 'can be pretty printed' do
31
- output = capture_stdout { pp example_instance }
31
+ output = ignoring_warnings { capture_stdout { pp example_instance } }
32
32
  expect(output).to include("RSpec::Core::Example")
33
33
  end
34
34
 
@@ -104,6 +104,12 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
104
104
  expect(example_group.examples.first.description).to eq("should eq 5")
105
105
  end
106
106
 
107
+ it "uses the matcher-generated description in the full description" do
108
+ example_group.example { expect(5).to eq(5) }
109
+ example_group.run
110
+ expect(example_group.examples.first.full_description).to eq("group description should eq 5")
111
+ end
112
+
107
113
  it "uses the file and line number if there is no matcher-generated description" do
108
114
  example = example_group.example {}
109
115
  example_group.run
@@ -314,7 +320,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
314
320
  end
315
321
 
316
322
  message = run_and_capture_reported_message(group)
317
- expect(message).to match /An error occurred in an around.* hook/i
323
+ expect(message).to match(/An error occurred in an around.* hook/i)
318
324
  end
319
325
 
320
326
  it "prints any after hook errors rather than silencing them" do
@@ -324,7 +330,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
324
330
  end
325
331
 
326
332
  message = run_and_capture_reported_message(group)
327
- expect(message).to match /An error occurred in an after.* hook/i
333
+ expect(message).to match(/An error occurred in an after.* hook/i)
328
334
  end
329
335
 
330
336
  it 'does not print mock expectation errors' do
@@ -415,4 +421,19 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
415
421
  expect(example.metadata[:execution_result][:run_time]).to be < 0.2
416
422
  end
417
423
  end
424
+
425
+ it 'does not interfere with per-example randomness when running examples in a random order' do
426
+ values = []
427
+
428
+ RSpec.configuration.order = :random
429
+
430
+ RSpec::Core::ExampleGroup.describe do
431
+ # The bug was only triggered when the examples
432
+ # were in nested contexts; see https://github.com/rspec/rspec-core/pull/837
433
+ context { example { values << rand } }
434
+ context { example { values << rand } }
435
+ end.run
436
+
437
+ expect(values.uniq).to have(2).values
438
+ end
418
439
  end
@@ -205,38 +205,38 @@ module RSpec::Core
205
205
  end
206
206
 
207
207
  it 'deprecates an overridden :if filter' do
208
- RSpec.should_receive(:warn_deprecation).with(/exclude\(:if.*is deprecated/)
208
+ expect(RSpec).to receive(:deprecate).with(/exclude\(:if/)
209
209
  filter_manager = FilterManager.new
210
210
  filter_manager.exclude :if => :custom_filter
211
211
  end
212
212
 
213
213
  it 'deprecates an :if filter overridden with low priority' do
214
- RSpec.should_receive(:warn_deprecation).with(/exclude\(:if.*is deprecated/)
214
+ expect(RSpec).to receive(:deprecate).with(/exclude\(:if/)
215
215
  filter_manager = FilterManager.new
216
216
  filter_manager.exclude_with_low_priority :if => :custom_filter
217
217
  end
218
218
 
219
219
  it 'deprecates an overridden :unless filter' do
220
- RSpec.should_receive(:warn_deprecation).with(/exclude\(:unless.*is deprecated/)
220
+ expect(RSpec).to receive(:deprecate).with(/exclude\(:unless/)
221
221
  filter_manager = FilterManager.new
222
222
  filter_manager.exclude :unless => :custom_filter
223
223
  end
224
224
 
225
225
  it 'deprecates an :unless filter overridden with low priority' do
226
- RSpec.should_receive(:warn_deprecation).with(/exclude\(:unless.*is deprecated/)
226
+ expect(RSpec).to receive(:deprecate).with(/exclude\(:unless/)
227
227
  filter_manager = FilterManager.new
228
228
  filter_manager.exclude_with_low_priority :unless => :custom_filter
229
229
  end
230
230
 
231
231
  it 'includes an overriden :if filter' do
232
- RSpec.stub(:warn_deprecation)
232
+ allow(RSpec).to receive(:deprecate)
233
233
  filter_manager = FilterManager.new
234
234
  filter_manager.exclude :if => :custom_filter
235
235
  expect(filter_manager.exclusions.description).to eq({ :if => :custom_filter }.inspect)
236
236
  end
237
237
 
238
238
  it 'includes an overriden :unless filter' do
239
- RSpec.stub(:warn_deprecation)
239
+ allow(RSpec).to receive(:deprecate)
240
240
  filter_manager = FilterManager.new
241
241
  filter_manager.exclude :unless => :custom_filter
242
242
  expect(filter_manager.exclusions.description).to eq({ :unless => :custom_filter }.inspect)
@@ -46,8 +46,8 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
46
46
 
47
47
  run_all_and_dump_failures
48
48
 
49
- expect(output.string).to match /group name example name/m
50
- expect(output.string).to match /(\s+)expected: \"that\"\n\1 got: \"this\"/m
49
+ expect(output.string).to match(/group name example name/m)
50
+ expect(output.string).to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
51
51
  end
52
52
 
53
53
  context "with an exception without a message" do
@@ -55,7 +55,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
55
55
  exception_without_message = Exception.new()
56
56
  exception_without_message.stub(:message) { nil }
57
57
  group.example("example name") { raise exception_without_message }
58
- expect { run_all_and_dump_failures }.not_to raise_error(NoMethodError)
58
+ expect { run_all_and_dump_failures }.not_to raise_error
59
59
  end
60
60
 
61
61
  it "preserves ancestry" do
@@ -70,7 +70,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
70
70
  gonzo_exception = RuntimeError.new
71
71
  gonzo_exception.stub(:message) { gonzo_exception }
72
72
  group.example("example name") { raise gonzo_exception }
73
- expect { run_all_and_dump_failures }.not_to raise_error(NoMethodError)
73
+ expect { run_all_and_dump_failures }.not_to raise_error
74
74
  end
75
75
  end
76
76
 
@@ -87,7 +87,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
87
87
  it "does not show the error class" do
88
88
  group.example("example name") { raise NameError.new('foo') }
89
89
  run_all_and_dump_failures
90
- expect(output.string).to match /NameError/m
90
+ expect(output.string).to match(/NameError/m)
91
91
  end
92
92
  end
93
93
 
@@ -95,7 +95,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
95
95
  it "does not show the error class" do
96
96
  group.example("example name") { expect("this").to eq("that") }
97
97
  run_all_and_dump_failures
98
- expect(output.string).not_to match /RSpec/m
98
+ expect(output.string).not_to match(/RSpec/m)
99
99
  end
100
100
  end
101
101
 
@@ -103,14 +103,14 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
103
103
  it "does not show the error class" do
104
104
  group.example("example name") { "this".should_receive("that") }
105
105
  run_all_and_dump_failures
106
- expect(output.string).not_to match /RSpec/m
106
+ expect(output.string).not_to match(/RSpec/m)
107
107
  end
108
108
  end
109
109
 
110
110
  context 'for #share_examples_for' do
111
111
  it 'outputs the name and location' do
112
112
 
113
- share_examples_for 'foo bar' do
113
+ group.share_examples_for 'foo bar' do
114
114
  it("example name") { expect("this").to eq("that") }
115
115
  end
116
116
 
@@ -127,7 +127,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
127
127
 
128
128
  context 'that contains nested example groups' do
129
129
  it 'outputs the name and location' do
130
- share_examples_for 'foo bar' do
130
+ group.share_examples_for 'foo bar' do
131
131
  describe 'nested group' do
132
132
  it("example name") { expect("this").to eq("that") }
133
133
  end
@@ -147,11 +147,11 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
147
147
  end
148
148
 
149
149
  context 'for #share_as' do
150
- before { RSpec.stub(:warn) }
150
+ before { allow(RSpec).to receive(:deprecate) }
151
151
 
152
152
  it 'outputs the name and location' do
153
153
 
154
- share_as :FooBar do
154
+ group.share_as :FooBar do
155
155
  it("example name") { expect("this").to eq("that") }
156
156
  end
157
157
 
@@ -169,7 +169,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
169
169
  context 'that contains nested example groups' do
170
170
  it 'outputs the name and location' do
171
171
 
172
- share_as :NestedFoo do
172
+ group.share_as :NestedFoo do
173
173
  describe 'nested group' do
174
174
  describe 'hell' do
175
175
  it("example name") { expect("this").to eq("that") }
@@ -209,8 +209,8 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
209
209
 
210
210
  run_all_and_dump_pending
211
211
 
212
- expect(output.string).to match /group name example name/m
213
- expect(output.string).to match /(\s+)expected: \"that\"\n\1 got: \"this\"/m
212
+ expect(output.string).to match(/group name example name/m)
213
+ expect(output.string).to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
214
214
  end
215
215
 
216
216
  context "with an exception without a message" do
@@ -218,7 +218,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
218
218
  exception_without_message = Exception.new()
219
219
  exception_without_message.stub(:message) { nil }
220
220
  group.example("example name") { pending { raise exception_without_message } }
221
- expect { run_all_and_dump_pending }.not_to raise_error(NoMethodError)
221
+ expect { run_all_and_dump_pending }.not_to raise_error
222
222
  end
223
223
  end
224
224
 
@@ -226,7 +226,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
226
226
  it "does not show the error class" do
227
227
  group.example("example name") { pending { raise NameError.new('foo') } }
228
228
  run_all_and_dump_pending
229
- expect(output.string).to match /NameError/m
229
+ expect(output.string).to match(/NameError/m)
230
230
  end
231
231
  end
232
232
 
@@ -234,7 +234,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
234
234
  it "does not show the error class" do
235
235
  group.example("example name") { pending { expect("this").to eq("that") } }
236
236
  run_all_and_dump_pending
237
- expect(output.string).not_to match /RSpec/m
237
+ expect(output.string).not_to match(/RSpec/m)
238
238
  end
239
239
  end
240
240
 
@@ -242,14 +242,14 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
242
242
  it "does not show the error class" do
243
243
  group.example("example name") { pending { "this".should_receive("that") } }
244
244
  run_all_and_dump_pending
245
- expect(output.string).not_to match /RSpec/m
245
+ expect(output.string).not_to match(/RSpec/m)
246
246
  end
247
247
  end
248
248
 
249
249
  context 'for #share_examples_for' do
250
250
  it 'outputs the name and location' do
251
251
 
252
- share_examples_for 'foo bar' do
252
+ group.share_examples_for 'foo bar' do
253
253
  it("example name") { pending { expect("this").to eq("that") } }
254
254
  end
255
255
 
@@ -266,7 +266,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
266
266
 
267
267
  context 'that contains nested example groups' do
268
268
  it 'outputs the name and location' do
269
- share_examples_for 'foo bar' do
269
+ group.share_examples_for 'foo bar' do
270
270
  describe 'nested group' do
271
271
  it("example name") { pending { expect("this").to eq("that") } }
272
272
  end
@@ -286,11 +286,11 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
286
286
  end
287
287
 
288
288
  context 'for #share_as' do
289
- before { RSpec.stub(:warn) }
289
+ before { allow(RSpec).to receive(:deprecate) }
290
290
 
291
291
  it 'outputs the name and location' do
292
292
 
293
- share_as :FooBar2 do
293
+ group.share_as :FooBar2 do
294
294
  it("example name") { pending { expect("this").to eq("that") } }
295
295
  end
296
296
 
@@ -308,7 +308,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
308
308
  context 'that contains nested example groups' do
309
309
  it 'outputs the name and location' do
310
310
 
311
- share_as :NestedFoo2 do
311
+ group.share_as :NestedFoo2 do
312
312
  describe 'nested group' do
313
313
  describe 'hell' do
314
314
  it("example name") { pending { expect("this").to eq("that") } }
@@ -336,12 +336,12 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
336
336
  it "does not output the failure information" do
337
337
  group.example("example name") { pending { expect("this").to eq("that") } }
338
338
  run_all_and_dump_pending
339
- expect(output.string).not_to match /(\s+)expected: \"that\"\n\1 got: \"this\"/m
339
+ expect(output.string).not_to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
340
340
  end
341
341
  end
342
342
  end
343
343
 
344
- describe "#dump_profile" do
344
+ describe "#dump_profile_slowest_examples" do
345
345
  example_line_number = nil
346
346
 
347
347
  before do
@@ -358,25 +358,88 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
358
358
  end
359
359
 
360
360
  it "names the example" do
361
- formatter.dump_profile
362
- expect(output.string).to match /group example/m
361
+ formatter.dump_profile_slowest_examples
362
+ expect(output.string).to match(/group example/m)
363
363
  end
364
364
 
365
365
  it "prints the time" do
366
- formatter.dump_profile
367
- expect(output.string).to match /0(\.\d+)? seconds/
366
+ formatter.dump_profile_slowest_examples
367
+ expect(output.string).to match(/0(\.\d+)? seconds/)
368
368
  end
369
369
 
370
370
  it "prints the path" do
371
- formatter.dump_profile
371
+ formatter.dump_profile_slowest_examples
372
372
  filename = __FILE__.split(File::SEPARATOR).last
373
373
 
374
- expect(output.string).to match /#{filename}\:#{example_line_number}/
374
+ expect(output.string).to match(/#{filename}\:#{example_line_number}/)
375
375
  end
376
376
 
377
377
  it "prints the percentage taken from the total runtime" do
378
- formatter.dump_profile
379
- expect(output.string).to match /, 100.0% of total time\):/
378
+ formatter.dump_profile_slowest_examples
379
+ expect(output.string).to match(/, 100.0% of total time\):/)
380
+ end
381
+ end
382
+
383
+ describe "#dump_profile_slowest_example_groups" do
384
+ let(:group) do
385
+ RSpec::Core::ExampleGroup.describe("slow group") do
386
+ # Use a sleep so there is some measurable time, to ensure
387
+ # the reported percent is 100%, not 0%.
388
+ example("example") { sleep 0.01 }
389
+ end
390
+ end
391
+ let(:rpt) { double('reporter').as_null_object }
392
+
393
+ before do
394
+ group.run(rpt)
395
+ RSpec.configuration.stub(:profile_examples) { 10 }
396
+ end
397
+
398
+ context "with one example group" do
399
+ before { formatter.stub(:examples) { group.examples } }
400
+
401
+ it "doesn't profile a single example group" do
402
+ formatter.dump_profile_slowest_example_groups
403
+ expect(output.string).not_to match(/slowest example groups/)
404
+ end
405
+ end
406
+
407
+ context "with multiple example groups" do
408
+ before do
409
+ group2 = RSpec::Core::ExampleGroup.describe("fast group") do
410
+ example("example 1") { sleep 0.004 }
411
+ example("example 2") { sleep 0.007 }
412
+ end
413
+ group2.run(rpt)
414
+
415
+ formatter.stub(:examples) { group.examples + group2.examples }
416
+ end
417
+
418
+ it "prints the slowest example groups" do
419
+ formatter.dump_profile_slowest_example_groups
420
+ expect(output.string).to match(/slowest example groups/)
421
+ end
422
+
423
+ it "prints the time" do
424
+ formatter.dump_profile_slowest_example_groups
425
+ expect(output.string).to match(/0(\.\d+)? seconds/)
426
+ end
427
+
428
+ it "ranks the example groups by average time" do
429
+ formatter.dump_profile_slowest_example_groups
430
+ expect(output.string).to match(/slow group(.*)fast group/m)
431
+ end
432
+ end
433
+
434
+ it "depends on parent_groups to get the top level example group" do
435
+ ex = ""
436
+ group.describe("group 2") do
437
+ describe "group 3" do
438
+ ex = example("nested example 1")
439
+ end
440
+ end
441
+
442
+ expect(ex.example_group.parent_groups.last).to eq(group)
380
443
  end
381
444
  end
382
445
 
@@ -411,8 +474,8 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
411
474
 
412
475
  describe "##{name}" do
413
476
  before do
414
- RSpec.configuration.stub(:color_enabled?) { true }
415
- RSpec.stub(:warn)
477
+ allow(RSpec.configuration).to receive(:color_enabled?) { true }
478
+ allow(RSpec).to receive(:deprecate)
416
479
  end
417
480
 
418
481
  it "prints the text using the color code for #{name}" do
@@ -420,7 +483,9 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
420
483
  end
421
484
 
422
485
  it "prints a deprecation warning" do
423
- RSpec.should_receive(:warn).with(/#{name}/)
486
+ expect(RSpec).to receive(:deprecate) {|*args|
487
+ expect(args.first).to match(/#{name}/)
488
+ }
424
489
  formatter.send(name, "text")
425
490
  end
426
491
  end