Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit cdb6381

Browse files
committed
Make order be random by default
1 parent 137a9af commit cdb6381

File tree

11 files changed

+54
-16
lines changed

11 files changed

+54
-16
lines changed

lib/rspec/core/ordering.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ def initialize(configuration)
8585
@configuration = configuration
8686
@strategies = {}
8787

88-
register(:random, Random.new(configuration))
88+
random = Random.new(configuration)
89+
register(:random, random)
8990
register(:recently_modified, RecentlyModified.new)
91+
register(:defined, Identity.new)
9092

91-
identity = Identity.new
92-
register(:defined, identity)
93-
94-
# The default global ordering is --defined.
95-
register(:global, identity)
93+
# The default global ordering is --random.
94+
register(:global, random)
9695
end
9796

9897
def fetch(name, &fallback)

lib/rspec/core/project_initializer/spec/spec_helper.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@
6666
# particularly slow.
6767
config.profile_examples = 10
6868
69-
# Run specs in random order to surface order dependencies. If you find an
70-
# order dependency and want to debug it, you can fix the order by providing
71-
# the seed, which is printed after each run.
72-
# --seed 1234
73-
config.order = :random
74-
7569
# Seed global randomization in this process using the `--seed` CLI option.
7670
# Setting this allows you to use `--seed` to deterministically reproduce
7771
# test failures related to randomization by passing the same `--seed` value

spec/integration/bisect_runners_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def with_runner(&block)
3939

4040
with_runner do |runner|
4141
expect(runner.original_results).to have_attributes(
42-
:all_example_ids => %w[ ./spec/a_spec.rb[1:1] ./spec/a_spec.rb[1:2] ],
42+
:all_example_ids => match_array(%w[ ./spec/a_spec.rb[1:1] ./spec/a_spec.rb[1:2] ]),
4343
:failed_example_ids => %w[ ./spec/a_spec.rb[1:2] ]
4444
)
4545

spec/integration/suite_hooks_errors_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
c.backtrace_exclusion_patterns << %r{/rspec-core/spec/} << %r{rspec_with_simplecov}
2626
c.failure_exit_code = failure_exit_code
2727
c.error_exit_code = error_exit_code
28+
c.seed = 123
2829
end
2930
end
3031

@@ -50,6 +51,8 @@ def run_spec_expecting_non_zero(before_or_after)
5051
output = run_spec_expecting_non_zero(:before)
5152
expect(output).to eq unindent(<<-EOS)
5253
54+
Randomized with seed 123
55+
5356
An error occurred in a `before(:suite)` hook.
5457
Failure/Error: raise 'boom'
5558
@@ -61,12 +64,16 @@ def run_spec_expecting_non_zero(before_or_after)
6164
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
6265
0 examples, 0 failures, 1 error occurred outside of examples
6366
67+
Randomized with seed 123
68+
6469
EOS
6570
end
6671

6772
it 'nicely formats errors in `after(:suite)` hooks and exits with non-zero' do
6873
output = run_spec_expecting_non_zero(:after)
6974
expect(output).to eq unindent(<<-EOS)
75+
76+
Randomized with seed 123
7077
.
7178
An error occurred in an `after(:suite)` hook.
7279
Failure/Error: raise 'boom'
@@ -79,6 +86,8 @@ def run_spec_expecting_non_zero(before_or_after)
7986
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
8087
1 example, 0 failures, 1 error occurred outside of examples
8188
89+
Randomized with seed 123
90+
8291
EOS
8392
end
8493

@@ -115,6 +124,8 @@ def run_spec_expecting_non_zero(before_or_after)
115124

116125
expect(output).to eq unindent(<<-EOS)
117126
127+
Randomized with seed 123
128+
118129
An error occurred in a `before(:suite)` hook.
119130
Failure/Error: c.before(:suite) { raise 'before 1' }
120131
@@ -140,6 +151,8 @@ def run_spec_expecting_non_zero(before_or_after)
140151
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
141152
0 examples, 0 failures, 3 errors occurred outside of examples
142153
154+
Randomized with seed 123
155+
143156
EOS
144157
end
145158
end

spec/rspec/core/example_group_spec.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ def define_and_run_group(define_outer_example = false)
823823
end
824824

825825
it "runs before_all_defined_in_config, before all, before each, example, after each, after all, after_all_defined_in_config in that order" do
826+
RSpec.configuration.order = :defined
827+
826828
order = []
827829

828830
RSpec.configure do |c|
@@ -1442,7 +1444,11 @@ def extract_execution_results(group)
14421444
end
14431445

14441446
context "with fail_fast enabled" do
1445-
before { RSpec.configuration.fail_fast = true }
1447+
before do
1448+
RSpec.configuration.fail_fast = true
1449+
RSpec.configuration.order = :defined
1450+
end
1451+
14461452
let(:group) { RSpec.describe }
14471453
let(:reporter) { Reporter.new(RSpec.configuration) }
14481454

@@ -1466,7 +1472,11 @@ def extract_execution_results(group)
14661472
end
14671473

14681474
context "with fail_fast set to 3" do
1469-
before { RSpec.configuration.fail_fast = 3 }
1475+
before do
1476+
RSpec.configuration.fail_fast = 3
1477+
RSpec.configuration.order = :defined
1478+
end
1479+
14701480
let(:group) { RSpec.describe }
14711481
let(:reporter) { Reporter.new(RSpec.configuration) }
14721482

@@ -1628,6 +1638,8 @@ def extract_execution_results(group)
16281638
end
16291639

16301640
it "applies new metadata-based config items based on the update" do
1641+
RSpec.configuration.order = :defined
1642+
16311643
extension = Module.new do
16321644
def extension_method; 17; end
16331645
end
@@ -1674,6 +1686,8 @@ def extension_method; 17; end
16741686
end
16751687

16761688
it "does not cause duplicate hooks to be added when re-configuring the group" do
1689+
RSpec.configuration.order = :defined
1690+
16771691
sequence = []
16781692
RSpec.configure do |c|
16791693
c.before(:example, :foo => true) { sequence << :global_before_hook }

spec/rspec/core/example_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ def expect_pending_result(example)
913913
example2 = group.example("example 2") { current_examples << RSpec.current_example }
914914

915915
group.run
916-
expect(current_examples).to eq([example1, example2])
916+
expect(current_examples).to match_array([example1, example2])
917917
end
918918
end
919919

spec/rspec/core/formatters/documentation_formatter_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def execution_result(values)
5252
end
5353

5454
it "represents nested group using hierarchy tree" do
55+
RSpec.configuration.order = :defined
56+
5557
group = RSpec.describe("root")
5658
context1 = group.describe("context 1")
5759
context1.example("nested example 1.1"){}
@@ -112,6 +114,8 @@ def execution_result(values)
112114
end
113115

114116
it "strips whitespace for each row" do
117+
RSpec.configuration.order = :defined
118+
115119
group = RSpec.describe(" root ")
116120
context1 = group.describe(" nested ")
117121
context1.example(" example 1 ") {}

spec/rspec/core/formatters/json_formatter_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
end
2121

2222
it "outputs expected json (brittle high level functional test)" do
23+
RSpec.configuration.order = :defined
24+
2325
its = []
2426
group = RSpec.describe("one apiece") do
2527
its.push it("succeeds") { expect(1).to eq 1 }

spec/rspec/core/hooks_filtering_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
module RSpec::Core
22
RSpec.describe "config block hook filtering" do
33
context "when hooks are defined after a group has been defined" do
4+
before do
5+
RSpec.configuration.order = :defined
6+
end
7+
48
it "still applies" do
59
sequence = []
610

@@ -444,6 +448,8 @@ def filters
444448
end
445449

446450
it "does not run if some hook filters don't match the group's filters" do
451+
RSpec.configuration.order = :defined
452+
447453
sequence = []
448454

449455
RSpec.configure do |c|
@@ -471,6 +477,8 @@ def filters
471477
end
472478

473479
it "does not run for examples that do not match, even if their group matches" do
480+
RSpec.configuration.order = :defined
481+
474482
filters = []
475483

476484
RSpec.configure do |c|

spec/rspec/core/reporter_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ module RSpec::Core
8484
end
8585

8686
it "passes messages to the formatter in the correct order" do
87+
RSpec.configuration.order = :defined
88+
8789
order = []
8890

8991
formatter = double("formatter")

spec/rspec/core/shared_example_group_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ def self.bar; 'bar'; end
298298

299299
describe "hooks for individual examples that have matching metadata" do
300300
it 'runs them' do
301+
RSpec.configuration.order = :defined
302+
301303
sequence = []
302304

303305
define_top_level_shared_group("name") do

0 commit comments

Comments
 (0)