diff --git a/Changelog.md b/Changelog.md index af2bdfac51..9fa6513959 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,15 @@ +### 3.0.3 / 2014-07-21 +[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.0.2...v3.0.3) + +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) +* 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) 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: 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 diff --git a/lib/rspec/core/backtrace_formatter.rb b/lib/rspec/core/backtrace_formatter.rb index aeac62265b..83a1874df7 100644 --- a/lib/rspec/core/backtrace_formatter.rb +++ b/lib/rspec/core/backtrace_formatter.rb @@ -44,27 +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) - @exclusion_patterns.any? { |p| line =~ p } + def matches?(patterns, line) + patterns.any? { |p| line =~ p } end - - def doesnt_match_inclusion_pattern_unless_system_exclusion?(line) - @system_exclusion_patterns.any? { |p| line =~ p } || @inclusion_patterns.none? { |p| p =~ line } - end - end end end 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/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/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 diff --git a/spec/rspec/core/backtrace_formatter_spec.rb b/spec/rspec/core/backtrace_formatter_spec.rb index d6b776253f..1638556c5c 100644 --- a/spec/rspec/core/backtrace_formatter_spec.rb +++ b/spec/rspec/core/backtrace_formatter_spec.rb @@ -39,6 +39,29 @@ def make_backtrace_formatter(exclusion_patterns=nil, inclusion_patterns=nil) formatter = make_backtrace_formatter([/foo/]) 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| + 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 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("") 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)