From ed1d7c64ba284fff59bec87af072db231bfd2eb8 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 24 Jun 2014 11:46:15 +1000 Subject: [PATCH 01/12] ensure that working directory is not included as an excluded folder name --- lib/rspec/core/backtrace_formatter.rb | 11 ++++++++--- spec/rspec/core/backtrace_formatter_spec.rb | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/rspec/core/backtrace_formatter.rb b/lib/rspec/core/backtrace_formatter.rb index aeac62265b..3ebb1df79e 100644 --- a/lib/rspec/core/backtrace_formatter.rb +++ b/lib/rspec/core/backtrace_formatter.rb @@ -52,17 +52,22 @@ def backtrace_line(line) def exclude?(line) return false if @full_backtrace matches_an_exclusion_pattern?(line) && - doesnt_match_inclusion_pattern_unless_system_exclusion?(line) + doesnt_match_inclusion_pattern_unless_system_exclusion?(line) end private def matches_an_exclusion_pattern?(line) - @exclusion_patterns.any? { |p| line =~ p } + matches_unless_working_directory? @exclusion_patterns, line end def doesnt_match_inclusion_pattern_unless_system_exclusion?(line) - @system_exclusion_patterns.any? { |p| line =~ p } || @inclusion_patterns.none? { |p| p =~ line } + matches_unless_working_directory?(@system_exclusion_patterns, line) || + @inclusion_patterns.none? { |p| p =~ line } + end + + def matches_unless_working_directory?(patterns, line) + patterns.any? { |p| line.gsub(Dir.getwd,'') =~ p } end end diff --git a/spec/rspec/core/backtrace_formatter_spec.rb b/spec/rspec/core/backtrace_formatter_spec.rb index d6b776253f..1f2fb87af5 100644 --- a/spec/rspec/core/backtrace_formatter_spec.rb +++ b/spec/rspec/core/backtrace_formatter_spec.rb @@ -35,6 +35,11 @@ def make_backtrace_formatter(exclusion_patterns=nil, inclusion_patterns=nil) expect(make_backtrace_formatter.exclude?("#{Dir.getwd}/arbitrary")).to be false end + it "includes something in the current working directory when that name includes gems" do + allow(Dir).to receive(:getwd).and_return("/Code/gems/") + expect(make_backtrace_formatter.exclude?("#{Dir.getwd}/arbitrary")).to be false + end + it "includes something in the current working directory even with a matching exclusion pattern" do formatter = make_backtrace_formatter([/foo/]) expect(formatter.exclude? "#{Dir.getwd}/foo").to be false From 64696d1b51d42347641e448d48c6473534ad2237 Mon Sep 17 00:00:00 2001 From: Christian Treppo Date: Sun, 29 Jun 2014 11:35:42 +0200 Subject: [PATCH 02/12] Backport pull request #1623 from treppo/master Removing code duplication in feature test The verification on the expectors was run twice in the feature test for the integration of mocking frameworks. Tests still pass, maybe a millisecond faster. --- features/mock_framework_integration/use_any_framework.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/mock_framework_integration/use_any_framework.feature b/features/mock_framework_integration/use_any_framework.feature index be76165cb8..ce88e1002b 100644 --- a/features/mock_framework_integration/use_any_framework.feature +++ b/features/mock_framework_integration/use_any_framework.feature @@ -69,7 +69,7 @@ Feature: mock with an alternative framework end def verify_mocks_for_rspec - Expector.verify_expectors.each {|d| d.verify} + Expector.verify_expectors end def teardown_mocks_for_rspec From 5c288434044b0fd26b82a35747144d9c75ea72cd Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Tue, 15 Jul 2014 09:51:50 -0700 Subject: [PATCH 03/12] Improve spec. - The original spec had a double-slashed path like '/Code/gems//arbitrary'. - Stubbing `Dir.getwd` forced the implementation to use that, but we'd like to reuse `RSpec::Metadata.relative_path` which does not use `Dir.getwd` internally. --- spec/rspec/core/backtrace_formatter_spec.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/spec/rspec/core/backtrace_formatter_spec.rb b/spec/rspec/core/backtrace_formatter_spec.rb index 1f2fb87af5..90e3a28191 100644 --- a/spec/rspec/core/backtrace_formatter_spec.rb +++ b/spec/rspec/core/backtrace_formatter_spec.rb @@ -35,15 +35,24 @@ def make_backtrace_formatter(exclusion_patterns=nil, inclusion_patterns=nil) expect(make_backtrace_formatter.exclude?("#{Dir.getwd}/arbitrary")).to be false end - it "includes something in the current working directory when that name includes gems" do - allow(Dir).to receive(:getwd).and_return("/Code/gems/") - expect(make_backtrace_formatter.exclude?("#{Dir.getwd}/arbitrary")).to be false - end - it "includes something in the current working directory even with a matching exclusion pattern" do formatter = make_backtrace_formatter([/foo/]) expect(formatter.exclude? "#{Dir.getwd}/foo").to be false end + + context "when the current working directory includes `gems` in the name" do + around(:example) do |ex| + Dir.mktmpdir do |tmp_dir| + dir = File.join(tmp_dir, "gems") + Dir.mkdir(dir) + Dir.chdir(dir, &ex) + end + end + + it "includes something in the current working directory" do + expect(make_backtrace_formatter.exclude?("#{Dir.getwd}/arbitrary")).to be false + end + end end describe "#format_backtrace" do From 0dee3eed39e5692ccb9fcd98475b4eae8e2670bf Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Tue, 15 Jul 2014 09:59:58 -0700 Subject: [PATCH 04/12] Refactor backtrace formatter implementation. - doesnt_match_inclusion_pattern_unless_system_exclusion? has a double negative and was being used in a compound conditional, which made my head explode. I couldn't understand it at all. - Reuse `Metadata.relative_path` rather than having our own logic to do that. - It'll perform better to get the relative path once rather than doing it once per pattern in the `patterns.any?` block. - Add spec for case that is covered by a cucumber scenario but not by an existing spec (an earlier version of this commit broke that cucumber scenario but no specs failed, revealing the missing spec coverage). --- lib/rspec/core/backtrace_formatter.rb | 21 ++++++--------------- spec/rspec/core/backtrace_formatter_spec.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/rspec/core/backtrace_formatter.rb b/lib/rspec/core/backtrace_formatter.rb index 3ebb1df79e..83a1874df7 100644 --- a/lib/rspec/core/backtrace_formatter.rb +++ b/lib/rspec/core/backtrace_formatter.rb @@ -44,32 +44,23 @@ def format_backtrace(backtrace, options = {}) end def backtrace_line(line) - RSpec::Core::Metadata::relative_path(line) unless exclude?(line) + Metadata.relative_path(line) unless exclude?(line) rescue SecurityError nil end def exclude?(line) return false if @full_backtrace - matches_an_exclusion_pattern?(line) && - doesnt_match_inclusion_pattern_unless_system_exclusion?(line) + relative_line = Metadata.relative_path(line) + return false unless matches?(@exclusion_patterns, relative_line) + matches?(@system_exclusion_patterns, relative_line) || !matches?(@inclusion_patterns, line) end private - def matches_an_exclusion_pattern?(line) - matches_unless_working_directory? @exclusion_patterns, line + def matches?(patterns, line) + patterns.any? { |p| line =~ p } end - - def doesnt_match_inclusion_pattern_unless_system_exclusion?(line) - matches_unless_working_directory?(@system_exclusion_patterns, line) || - @inclusion_patterns.none? { |p| p =~ line } - end - - def matches_unless_working_directory?(patterns, line) - patterns.any? { |p| line.gsub(Dir.getwd,'') =~ p } - end - end end end diff --git a/spec/rspec/core/backtrace_formatter_spec.rb b/spec/rspec/core/backtrace_formatter_spec.rb index 90e3a28191..1638556c5c 100644 --- a/spec/rspec/core/backtrace_formatter_spec.rb +++ b/spec/rspec/core/backtrace_formatter_spec.rb @@ -40,6 +40,15 @@ def make_backtrace_formatter(exclusion_patterns=nil, inclusion_patterns=nil) expect(formatter.exclude? "#{Dir.getwd}/foo").to be false end + context "when the exclusion list has been replaced" do + it "includes a line that the default patterns exclude" do + formatter = make_backtrace_formatter + expect { + formatter = make_backtrace_formatter([/spec_helper/]) + }.to change { formatter.exclude? "/path/to/lib/rspec/expectations/foo.rb" }.from(true).to(false) + end + end + context "when the current working directory includes `gems` in the name" do around(:example) do |ex| Dir.mktmpdir do |tmp_dir| From 21f2a8b68974023af98479fb0fffbe63bfa3b642 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 16 Jul 2014 13:23:59 +1000 Subject: [PATCH 05/12] Merge pull request #1636 from nicklink483/fix_metadata_build_description_from describe parameters can now be classes without error --- lib/rspec/core/metadata.rb | 2 +- spec/rspec/core/metadata_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rspec/core/metadata.rb b/lib/rspec/core/metadata.rb index 57aeb8b557..a5fc706b18 100644 --- a/lib/rspec/core/metadata.rb +++ b/lib/rspec/core/metadata.rb @@ -126,7 +126,7 @@ def description_separator(parent_part, child_part) def build_description_from(parent_description=nil, my_description=nil) return parent_description.to_s unless my_description separator = description_separator(parent_description, my_description) - parent_description.to_s + separator + my_description + parent_description.to_s + separator + my_description.to_s end def ensure_valid_user_keys diff --git a/spec/rspec/core/metadata_spec.rb b/spec/rspec/core/metadata_spec.rb index 03ab603981..1a29691480 100644 --- a/spec/rspec/core/metadata_spec.rb +++ b/spec/rspec/core/metadata_spec.rb @@ -285,6 +285,12 @@ def group_value_for(*args) end end + context "with a string and a non-string" do + it "concats the args" do + expect(group_value_for 'group', Object).to eq("group Object") + end + end + context "with empty args" do it "returns empty string for [:description]" do expect(group_value_for()).to eq("") From ca6d4ecb635108d7c0f3a3818ebe136506dbc4f1 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 16 Jul 2014 13:28:13 +1000 Subject: [PATCH 06/12] changelog for #1636 Conflicts: Changelog.md --- Changelog.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Changelog.md b/Changelog.md index af2bdfac51..f418afc690 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,12 @@ +### Development +[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.2...master) + + +Bug Fixes: + +* Properly convert both parts of a description into strings before + concatenation. (@nicklink483, #1636) + ### 3.0.2 / 2014-06-19 [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.1...v3.0.2) From 00370abdbb64e4d705650bf2891f2188d9a552ac Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 16 Jul 2014 13:40:22 +1000 Subject: [PATCH 07/12] changelog for #1616 --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index f418afc690..16e8d66d19 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,8 @@ Bug Fixes: * Properly convert both parts of a description into strings before concatenation. (@nicklink483, #1636) +* Exclude the working directory when figuring out folders to ignore. + (Jon Rowe, Myron Marston, #1616) ### 3.0.2 / 2014-06-19 [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.1...v3.0.2) From 1d051f221fc636d10dee36450d9b837984ba2046 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 17 Jul 2014 09:30:35 +1000 Subject: [PATCH 08/12] Merge pull request #1642 from rspec/update_rake_task_docs Update rake task docs with note about LoadError --- features/command_line/rake_task.feature | 69 ++++++++++++++++++------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/features/command_line/rake_task.feature b/features/command_line/rake_task.feature index 470cc321ce..caa986e039 100644 --- a/features/command_line/rake_task.feature +++ b/features/command_line/rake_task.feature @@ -1,15 +1,32 @@ Feature: rake task - RSpec ships with a rake task with a number of useful options + RSpec ships with a rake task with a number of useful options. + + We recommend you wrap this in a `rescue` clause so that you can + use your `Rakefile` in an environment where RSpec is unavailable + (for example on a production server). e.g: + + ```ruby + begin + require 'rspec/core/rake_task' + RSpec::Core::RakeTask.new(:spec) + rescue LoadError + end + ``` Scenario: Default options with passing spec (prints command and exit status is 0) Given a file named "Rakefile" with: """ruby - require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec) + begin + require 'rspec/core/rake_task' + + RSpec::Core::RakeTask.new(:spec) - task :default => :spec + task :default => :spec + rescue LoadError + # no rspec available + end """ And a file named "spec/thing_spec.rb" with: """ruby @@ -29,11 +46,15 @@ Feature: rake task Scenario: Default options with failing spec (exit status is 1) Given a file named "Rakefile" with: """ruby - require 'rspec/core/rake_task' + begin + require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec) + RSpec::Core::RakeTask.new(:spec) - task :default => :spec + task :default => :spec + rescue LoadError + # no rspec available + end """ And a file named "spec/thing_spec.rb" with: """ruby @@ -49,13 +70,17 @@ Feature: rake task Scenario: Setting `fail_on_error = false` with failing spec (exit status is 0) Given a file named "Rakefile" with: """ruby - require 'rspec/core/rake_task' + begin + require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec) do |t| - t.fail_on_error = false - end + RSpec::Core::RakeTask.new(:spec) do |t| + t.fail_on_error = false + end - task :default => :spec + task :default => :spec + rescue LoadError + # no rspec available + end """ And a file named "spec/thing_spec.rb" with: """ruby @@ -71,10 +96,14 @@ Feature: rake task Scenario: Passing arguments to the `rspec` command using `rspec_opts` Given a file named "Rakefile" with: """ruby - require 'rspec/core/rake_task' + begin + require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec) do |t| - t.rspec_opts = "--tag fast" + RSpec::Core::RakeTask.new(:spec) do |t| + t.rspec_opts = "--tag fast" + end + rescue LoadError + # no rspec available end """ And a file named "spec/thing_spec.rb" with: @@ -99,10 +128,14 @@ Feature: rake task Scenario: Passing rake task arguments to the `rspec` command via `rspec_opts` Given a file named "Rakefile" with: """ruby - require 'rspec/core/rake_task' + begin + require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec, :tag) do |t, task_args| - t.rspec_opts = "--tag #{task_args[:tag]}" + RSpec::Core::RakeTask.new(:spec, :tag) do |t, task_args| + t.rspec_opts = "--tag #{task_args[:tag]}" + end + rescue LoadError + # no rspec available end """ And a file named "spec/thing_spec.rb" with: From dfaac705371c2b25d4e9a826be3c6c354c78519f Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Fri, 18 Jul 2014 09:53:25 -0700 Subject: [PATCH 09/12] Fix full changelog link. [ci skip] --- Changelog.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 16e8d66d19..22d05bd0b6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,5 @@ ### Development -[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.2...master) - +[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.2...3-0-maintenance) Bug Fixes: From ba9da8513a01a79da5b9f523a5b23e15f04a0e4b Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Sat, 19 Jul 2014 11:46:31 +1000 Subject: [PATCH 10/12] Merge pull request #1637 from tomykaira/fix_wrap_args Add placeholder for code_or_symbol to NullColorizer --- lib/rspec/core/notifications.rb | 2 +- spec/rspec/core/notifications_spec.rb | 29 ++++++++++++++++++++------- spec/support/formatter_support.rb | 29 ++++++++++++++++++--------- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/lib/rspec/core/notifications.rb b/lib/rspec/core/notifications.rb index fc24c2183e..66a4799136 100644 --- a/lib/rspec/core/notifications.rb +++ b/lib/rspec/core/notifications.rb @@ -7,7 +7,7 @@ module Notifications # @private class NullColorizer - def wrap(line) + def wrap(line, _code_or_symbol) line end end diff --git a/spec/rspec/core/notifications_spec.rb b/spec/rspec/core/notifications_spec.rb index 22d6866348..ae159e980e 100644 --- a/spec/rspec/core/notifications_spec.rb +++ b/spec/rspec/core/notifications_spec.rb @@ -2,15 +2,16 @@ require 'rspec/core/notifications' RSpec.describe "FailedExampleNotification" do + include FormatterSupport + + let(:notification) { ::RSpec::Core::Notifications::FailedExampleNotification.new(example) } + + before do + allow(example).to receive(:file_path) { __FILE__ } + end + # ported from `base_formatter_spec` should be refactored by final describe "#read_failed_line" do - let(:example) do - instance_double(RSpec::Core::Example, - :file_path => __FILE__, - :execution_result => double(:exception => exception)) - end - let(:notification) { ::RSpec::Core::Notifications::FailedExampleNotification.new(example) } - context "when backtrace is a heterogeneous language stack trace" do let(:exception) do instance_double(Exception, :backtrace => [ @@ -66,4 +67,18 @@ end end + + describe '#message_lines' do + let(:exception) { instance_double(Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"], :message => 'Test exception') } + + before do + allow(example).to receive(:example_group) { class_double(RSpec::Core::ExampleGroup, :metadata => {}, :parent_groups => []) } + end + + it 'should return failure_lines without color' do + lines = notification.message_lines + expect(lines[0]).to match %r{\AFailure\/Error} + expect(lines[1]).to match %r{\A\s*Test exception\z} + end + end end diff --git a/spec/support/formatter_support.rb b/spec/support/formatter_support.rb index f0a303cf4c..88b1d8c076 100644 --- a/spec/support/formatter_support.rb +++ b/spec/support/formatter_support.rb @@ -189,16 +189,25 @@ def formatter end def example - result = { :exception => Exception.new } - allow(result).to receive(:pending_fixed?) { false } - allow(result).to receive(:status) { :passed } - instance_double(RSpec::Core::Example, - :description => "Example", - :full_description => "Example", - :execution_result => result, - :location => "", - :metadata => {} - ) + @example ||= + begin + result = instance_double(RSpec::Core::Example::ExecutionResult, + :pending_fixed? => false, + :status => :passed + ) + allow(result).to receive(:exception) { exception } + instance_double(RSpec::Core::Example, + :description => "Example", + :full_description => "Example", + :execution_result => result, + :location => "", + :metadata => {} + ) + end + end + + def exception + Exception.new end def examples(n) From af7f121f505b7bbbb84361820bb67744d964db16 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Sat, 19 Jul 2014 11:50:30 +1000 Subject: [PATCH 11/12] changelog for #1637 --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index 22d05bd0b6..768278bccb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,8 @@ Bug Fixes: concatenation. (@nicklink483, #1636) * Exclude the working directory when figuring out folders to ignore. (Jon Rowe, Myron Marston, #1616) +* Allow `::RSpec::Core::Notifications::FailedExampleNotification#message_lines` + to be accessed without a colouriser. (@tomykaira , #1637) ### 3.0.2 / 2014-06-19 [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.1...v3.0.2) From 527d829d10aa7f836509cc4d53ca05aad5198a52 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Mon, 21 Jul 2014 16:18:57 -0700 Subject: [PATCH 12/12] Release 3.0.3. --- Changelog.md | 6 +++--- lib/rspec/core/version.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 768278bccb..9fa6513959 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,5 @@ -### Development -[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.2...3-0-maintenance) +### 3.0.3 / 2014-07-21 +[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.2...v3.0.3) Bug Fixes: @@ -8,7 +8,7 @@ Bug Fixes: * Exclude the working directory when figuring out folders to ignore. (Jon Rowe, Myron Marston, #1616) * Allow `::RSpec::Core::Notifications::FailedExampleNotification#message_lines` - to be accessed without a colouriser. (@tomykaira , #1637) + to be accessed without a colouriser. (@tomykaira, #1637) ### 3.0.2 / 2014-06-19 [Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.1...v3.0.2) diff --git a/lib/rspec/core/version.rb b/lib/rspec/core/version.rb index 50a89311f6..7af0fc27ec 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.0.2' + STRING = '3.0.3' end end end