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

Commit 561cce6

Browse files
committed
Merge pull request #2032 from rspec/2029-followups
2029 followups
2 parents 8ec2c99 + 16888f9 commit 561cce6

9 files changed

+27
-34
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ Enhancements:
1717
the number of runs necessary to determine that an example set cannot be
1818
minimized further. (Simon Coffey, #1997)
1919

20+
Bug Fixes:
21+
22+
* Lock `example_status_persistence_file` when reading from and writing
23+
to it to prevent race conditions when multiple processes try to use
24+
it. (Ben Woosley, #2029)
25+
2026
### 3.3.2 / 2015-07-15
2127
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.3.1...v3.3.2)
2228

lib/rspec/core/example_status_persister.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,22 @@ def persist
2727
# condition where parallel or unrelated spec runs race to
2828
# update the same file
2929
f.flock(File::LOCK_EX)
30-
@previous_runs = f.read
30+
unparsed_previous_runs = f.read
3131
f.rewind
32-
f.write(dumped_statuses)
32+
f.write(dump_statuses(unparsed_previous_runs))
3333
f.flush
3434
f.truncate(f.pos)
3535
end
3636
end
3737

3838
private
3939

40-
def dumped_statuses
40+
def dump_statuses(unparsed_previous_runs)
41+
statuses_from_previous_runs = ExampleStatusParser.parse(unparsed_previous_runs)
42+
merged_statuses = ExampleStatusMerger.merge(statuses_from_this_run, statuses_from_previous_runs)
4143
ExampleStatusDumper.dump(merged_statuses)
4244
end
4345

44-
def merged_statuses
45-
ExampleStatusMerger.merge(statuses_from_this_run, statuses_from_previous_runs)
46-
end
47-
4846
def statuses_from_this_run
4947
@examples.map do |ex|
5048
result = ex.execution_result
@@ -56,10 +54,6 @@ def statuses_from_this_run
5654
}
5755
end
5856
end
59-
60-
def statuses_from_previous_runs
61-
ExampleStatusParser.parse(@previous_runs)
62-
end
6357
end
6458

6559
# Merges together a list of example statuses from this run

spec/rspec/core/configuration_spec.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,14 @@ def absolute_path_to(dir)
164164

165165
shared_examples "a configurable framework adapter" do |m|
166166
it "yields a config object if the framework_module supports it" do
167-
custom_config = Struct.new(:custom_setting).new
168167
mod = Module.new
169-
allow(mod).to receive_messages(:configuration => custom_config)
168+
def mod.configuration; @config ||= Struct.new(:custom_setting).new; end
170169

171170
config.send m, mod do |mod_config|
172171
mod_config.custom_setting = true
173172
end
174173

175-
expect(custom_config.custom_setting).to be_truthy
174+
expect(mod.configuration.custom_setting).to be_truthy
176175
end
177176

178177
it "raises if framework module doesn't support configuration" do
@@ -236,8 +235,7 @@ def absolute_path_to(dir)
236235

237236
it 'raises an error since this setting must be applied before any groups are defined' do
238237
allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object])
239-
mocha = stub_const("RSpec::Core::MockingAdapters::Mocha", Module.new)
240-
allow(mocha).to receive_messages(:framework_name => :mocha)
238+
class_double("RSpec::Core::MockingAdapters::Mocha", :framework_name => :mocha).as_stubbed_const
241239

242240
expect {
243241
config.mock_with :mocha
@@ -251,8 +249,7 @@ def absolute_path_to(dir)
251249
end
252250

253251
it 'does not raise an error if re-setting the same config' do
254-
mocha = stub_const("RSpec::Core::MockingAdapters::Mocha", Module.new)
255-
allow(mocha).to receive_messages(:framework_name => :mocha)
252+
class_double("RSpec::Core::MockingAdapters::Mocha", :framework_name => :mocha).as_stubbed_const
256253

257254
groups = []
258255
allow(RSpec.world).to receive_messages(:example_groups => groups)

spec/rspec/core/example_group_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ def ascending_numbers
494494
context "with no filters" do
495495
it "returns all" do
496496
group = RSpec.describe
497-
allow(group).to receive(:world) { self.world }
498497
example = group.example("does something")
499498
expect(group.filtered_examples).to eq([example])
500499
end
@@ -506,7 +505,6 @@ def ascending_numbers
506505
filter_manager.include :awesome => false
507506
allow(self.world).to receive_messages(:filter_manager => filter_manager)
508507
group = RSpec.describe
509-
allow(group).to receive(:world) { self.world }
510508
group.example("does something")
511509
expect(group.filtered_examples).to eq([])
512510
end

spec/rspec/core/example_status_persister_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def new_example(id, metadata = {})
7373

7474
# dumped_statuses is called after the file is locked but
7575
# before the output is written
76-
allow(persister_1).to receive(:dumped_statuses).and_wrap_original do |m, *args|
76+
allow(persister_1).to receive(:dump_statuses).and_wrap_original do |m, *args|
7777
persister_2_thread = Thread.new { persister_2.persist }
7878
m.call(*args)
7979
end

spec/rspec/core/formatters/documentation_formatter_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module RSpec::Core::Formatters
66

77
before do
88
send_notification :start, start_notification(2)
9-
allow(formatter).to receive(:color_enabled?).and_return(false)
109
end
1110

1211
def execution_result(values)

spec/rspec/core/formatters/progress_formatter_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
before do
77
send_notification :start, start_notification(2)
8-
allow(formatter).to receive(:color_enabled?).and_return(false)
98
end
109

1110
it 'prints a . on example_passed' do

spec/rspec/core/memoized_helpers_spec.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,14 @@ def working_with?(double)
113113
[false, nil].each do |falsy_value|
114114
context "with a value of #{falsy_value.inspect}" do
115115
it "is evaluated once per example" do
116-
example_group = RSpec.describe(Array)
117-
example_group.before do
118-
expect(Object).to receive(:this_question?).once.and_return(falsy_value)
119-
end
120-
example_group.subject do
121-
Object.this_question?
122-
end
123-
example_group.example do
124-
subject
125-
subject
116+
subject_calls = 0
117+
118+
describe_successfully do
119+
subject { subject_calls += 1; falsy_value }
120+
example { subject; subject }
126121
end
127-
expect(example_group.run).to be_truthy, "expected subject block to be evaluated only once"
122+
123+
expect(subject_calls).to eq(1)
128124
end
129125
end
130126
end

spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def handle_current_dir_change
9595
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9696
end
9797

98+
c.mock_with :rspec do |mocks|
99+
mocks.verify_partial_doubles = true
100+
end
101+
98102
c.around(:example, :simulate_shell_allowing_unquoted_ids) do |ex|
99103
with_env_vars('SHELL' => '/usr/local/bin/bash', &ex)
100104
end

0 commit comments

Comments
 (0)