From 8b2af9351fcfdd9c4e7d9554c00b4fcf748ce7a6 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Wed, 13 Jul 2016 08:05:42 -0700 Subject: [PATCH 1/5] Fill in execution_status before reporting example_finished. Fixes #2290. --- Changelog.md | 8 +++++ lib/rspec/core/example.rb | 6 ++-- spec/rspec/core/example_spec.rb | 64 +++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index feee618fac..f5b8b8c035 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,11 @@ +### 3.5.2 Development +[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.5.1...3-5-maintenance) + +Bug Fixes: + +* Wait to report `example_finished` until the example's `execution_result` + has been completely filled in. (Myron Marston, #2291) + ### 3.5.1 / 2016-07-06 [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.5.0...v3.5.1) diff --git a/lib/rspec/core/example.rb b/lib/rspec/core/example.rb index ec8a30d0ed..f0d4b76b36 100644 --- a/lib/rspec/core/example.rb +++ b/lib/rspec/core/example.rb @@ -461,15 +461,14 @@ def start(reporter) def finish(reporter) pending_message = execution_result.pending_message - reporter.example_finished(self) if @exception - record_finished :failed execution_result.exception = @exception + record_finished :failed reporter.example_failed self false elsif pending_message - record_finished :pending execution_result.pending_message = pending_message + record_finished :pending reporter.example_pending self true else @@ -481,6 +480,7 @@ def finish(reporter) def record_finished(status) execution_result.record_finished(status, clock.now) + reporter.example_finished(self) end def run_before_example diff --git a/spec/rspec/core/example_spec.rb b/spec/rspec/core/example_spec.rb index cc08c6c53e..41ff5d4372 100644 --- a/spec/rspec/core/example_spec.rb +++ b/spec/rspec/core/example_spec.rb @@ -555,6 +555,70 @@ def expect_gc(opts) end end + describe "reporting example_finished" do + let(:reporter) { RSpec::Core::Reporter.new(RSpec::Core::Configuration.new) } + + def capture_reported_execution_result_for_example(&block) + reporter = RSpec::Core::Reporter.new(RSpec::Core::Configuration.new) + + reported_execution_result = nil + + listener = double("Listener") + allow(listener).to receive(:example_finished) do |notification| + reported_execution_result = notification.example.execution_result.dup + end + + reporter.register_listener(listener, :example_finished) + + RSpec.describe do + it(&block) + end.run(reporter) + + reported_execution_result + end + + it "fills in the execution result details before reporting a passed example as finished" do + execution_result = capture_reported_execution_result_for_example do + expect(1).to eq 1 + end + + expect(execution_result).to have_attributes( + :status => :passed, + :exception => nil, + :finished_at => a_value_within(1).of(Time.now), + :run_time => a_value >= 0 + ) + end + + it "fills in the execution result details before reporting a failed example as finished" do + execution_result = capture_reported_execution_result_for_example do + expect(1).to eq 2 + end + + expect(execution_result).to have_attributes( + :status => :failed, + :exception => RSpec::Expectations::ExpectationNotMetError, + :finished_at => a_value_within(1).of(Time.now), + :run_time => a_value >= 0 + ) + end + + it "fills in the execution result details before reporting a pending example as finished" do + execution_result = capture_reported_execution_result_for_example do + pending "because" + expect(1).to eq 2 + end + + expect(execution_result).to have_attributes( + :status => :pending, + :pending_message => "because", + :pending_exception => RSpec::Expectations::ExpectationNotMetError, + :finished_at => a_value_within(1).of(Time.now), + :run_time => a_value >= 0 + ) + end + end + describe "#pending" do def expect_pending_result(example) expect(example).to be_pending From a42be5cabfd5a61dffb8cfcdf901b5f3d0dc1c5c Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 27 Jul 2016 21:35:24 +1000 Subject: [PATCH 2/5] dont double include pattern, let user override our default if necessary --- Changelog.md | 2 ++ lib/rspec/core/rake_task.rb | 1 + spec/rspec/core/rake_task_spec.rb | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/Changelog.md b/Changelog.md index f5b8b8c035..c230694156 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,8 @@ Bug Fixes: * Wait to report `example_finished` until the example's `execution_result` has been completely filled in. (Myron Marston, #2291) +* Don't include the default `--pattern` in the Rake task when + `rspec_opts` specifies its own. (Jon Rowe, #2305) ### 3.5.1 / 2016-07-06 [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.5.0...v3.5.1) diff --git a/lib/rspec/core/rake_task.rb b/lib/rspec/core/rake_task.rb index 16297f1820..ad321a9ac3 100644 --- a/lib/rspec/core/rake_task.rb +++ b/lib/rspec/core/rake_task.rb @@ -102,6 +102,7 @@ def file_inclusion_specification if ENV['SPEC'] FileList[ENV['SPEC']].sort elsif String === pattern && !File.exist?(pattern) + return if rspec_opts =~ /--pattern/ "--pattern #{escape pattern}" else # Before RSpec 3.1, we used `FileList` to get the list of matched diff --git a/spec/rspec/core/rake_task_spec.rb b/spec/rspec/core/rake_task_spec.rb index 1ed6d04dc2..5261aad0f8 100644 --- a/spec/rspec/core/rake_task_spec.rb +++ b/spec/rspec/core/rake_task_spec.rb @@ -66,6 +66,13 @@ def spec_command task.rspec_opts = "-Ifoo" expect(spec_command).to match(/#{task.rspec_path}.*-Ifoo/) end + + it 'correctly excludes the default pattern if rspec_opts includes --pattern' do + task.rspec_opts = "--pattern some_specs" + expect(spec_command).to include("--pattern some_specs").and( + exclude(RSpec::Core::RakeTask::DEFAULT_PATTERN) + ) + end end context "with pattern" do From 17052cbdb3c79c929636b77dc696ba1346be64be Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 20 Jul 2016 13:04:23 +1000 Subject: [PATCH 3/5] remove old jruby workaround --- spec/spec_helper.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d02f369fa6..40db61b80f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,13 +2,6 @@ require 'rspec/support/spec' -if RUBY_PLATFORM == 'java' - # Works around https://jira.codehaus.org/browse/JRUBY-5678 - require 'fileutils' - ENV['TMPDIR'] = File.expand_path('../../tmp', __FILE__) - FileUtils.mkdir_p(ENV['TMPDIR']) -end - $rspec_core_without_stderr_monkey_patch = RSpec::Core::Configuration.new class RSpec::Core::Configuration From 946479a9677bb85155eceb1a4943b08fc2d79502 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Tue, 19 Jul 2016 14:36:32 -0400 Subject: [PATCH 4/5] Fix block support in example.duplicate_with Update spec to verify block exists in cloned example --- Changelog.md | 2 ++ lib/rspec/core/example.rb | 4 +++- spec/rspec/core/example_spec.rb | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index c230694156..959d4a7252 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,8 @@ Bug Fixes: * Wait to report `example_finished` until the example's `execution_result` has been completely filled in. (Myron Marston, #2291) +* Make sure example block is still available when using `duplicate_with` + to clone examples. (bootstraponline, #2298) * Don't include the default `--pattern` in the Rake task when `rspec_opts` specifies its own. (Jon Rowe, #2305) diff --git a/lib/rspec/core/example.rb b/lib/rspec/core/example.rb index f0d4b76b36..9cf6827a17 100644 --- a/lib/rspec/core/example.rb +++ b/lib/rspec/core/example.rb @@ -138,8 +138,10 @@ def duplicate_with(metadata_overrides={}) # don't clone the example group because the new example # must belong to the same example group (not a clone). + # + # block is nil in new_metadata so we have to get it from metadata. Example.new(example_group, description.clone, - new_metadata, new_metadata[:block]) + new_metadata, metadata[:block]) end # @private diff --git a/spec/rspec/core/example_spec.rb b/spec/rspec/core/example_spec.rb index 41ff5d4372..d5f618b9b4 100644 --- a/spec/rspec/core/example_spec.rb +++ b/spec/rspec/core/example_spec.rb @@ -84,13 +84,17 @@ def metadata_hash(*args) describe '#duplicate_with' do it 'successfully duplicates an example' do - example = example_group.example { raise 'first' } + error_string = 'first' + example = example_group.example { raise error_string } example2 = example.duplicate_with({ :custom_key => :custom_value }) # ensure metadata is unique for each example expect(example.metadata.object_id).to_not eq(example2.metadata.object_id) expect(example.metadata[:custom_key]).to eq(nil) + expect(&example.metadata[:block]).to raise_error(error_string) + expect(example2.metadata[:custom_key]).to eq(:custom_value) + expect(&example2.metadata[:block]).to raise_error(error_string) # cloned examples must have unique ids expect(example.id).to_not eq(example2.id) From 347fc7f08c4f41297047b5fd7394c0a431ccea17 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Thu, 28 Jul 2016 07:26:45 -0700 Subject: [PATCH 5/5] Release 3.5.2. --- Changelog.md | 4 ++-- lib/rspec/core/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 959d4a7252..6ee762882f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,5 @@ -### 3.5.2 Development -[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.5.1...3-5-maintenance) +### 3.5.2 / 2016-07-28 +[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.5.1...v3.5.2) Bug Fixes: diff --git a/lib/rspec/core/version.rb b/lib/rspec/core/version.rb index a73c9c70dd..f4369ce547 100644 --- a/lib/rspec/core/version.rb +++ b/lib/rspec/core/version.rb @@ -3,7 +3,7 @@ module Core # Version information for RSpec Core. module Version # Current version of RSpec Core, in semantic versioning format. - STRING = '3.5.1' + STRING = '3.5.2' end end end