From 7417a5c94ada468d3a037ded4b1bb72a1b22e172 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Wed, 28 Jun 2017 10:41:56 +1000 Subject: [PATCH 1/5] Updates for frozen-string-literal compatibility. --- lib/rspec/core/drb.rb | 2 +- lib/rspec/core/example.rb | 2 +- lib/rspec/core/example_group.rb | 2 +- lib/rspec/core/notifications.rb | 8 ++++---- spec/rspec/core/formatters/base_text_formatter_spec.rb | 2 +- spec/rspec/core/formatters/html_snippet_extractor_spec.rb | 2 +- spec/rspec/core/notifications_spec.rb | 2 +- spec/rspec/core_spec.rb | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/rspec/core/drb.rb b/lib/rspec/core/drb.rb index 7d1294544d..c0e59291c9 100644 --- a/lib/rspec/core/drb.rb +++ b/lib/rspec/core/drb.rb @@ -84,7 +84,7 @@ def add_full_description(argv) def add_filter(argv, name, hash) hash.each_pair do |k, v| next if CONDITIONAL_FILTERS.include?(k) - tag = name == :inclusion ? k.to_s : "~#{k}" + tag = name == :inclusion ? k.to_s : "~#{k}".dup tag << ":#{v}" if v.is_a?(String) argv << "--tag" << tag end unless hash.empty? diff --git a/lib/rspec/core/example.rb b/lib/rspec/core/example.rb index ff223866ed..5c0e2ff25d 100644 --- a/lib/rspec/core/example.rb +++ b/lib/rspec/core/example.rb @@ -523,7 +523,7 @@ def mocks_need_verification? def assign_generated_description if metadata[:description].empty? && (description = generate_description) metadata[:description] = description - metadata[:full_description] << description + metadata[:full_description] += description end ensure RSpec::Matchers.clear_generated_description diff --git a/lib/rspec/core/example_group.rb b/lib/rspec/core/example_group.rb index 1d5ec5ada1..a9b415bbb4 100644 --- a/lib/rspec/core/example_group.rb +++ b/lib/rspec/core/example_group.rb @@ -838,7 +838,7 @@ def self.remove_all_constants end def self.base_name_for(group) - return "Anonymous" if group.description.empty? + return "Anonymous".dup if group.description.empty? # Convert to CamelCase. name = ' ' + group.description diff --git a/lib/rspec/core/notifications.rb b/lib/rspec/core/notifications.rb index 1b9871d26b..bfc4b33b50 100644 --- a/lib/rspec/core/notifications.rb +++ b/lib/rspec/core/notifications.rb @@ -120,7 +120,7 @@ def fully_formatted_failed_examples(colorizer=::RSpec::Core::Formatters::Console # @return [String] The list of pending examples, fully formatted in the # way that RSpec's built-in formatters emit. def fully_formatted_pending_examples(colorizer=::RSpec::Core::Formatters::ConsoleCodes) - formatted = "\nPending: (Failures listed here are expected and do not affect your suite's status)\n" + formatted = "\nPending: (Failures listed here are expected and do not affect your suite's status)\n".dup pending_notifications.each_with_index do |notification, index| formatted << notification.fully_formatted(index.next, colorizer) @@ -232,9 +232,9 @@ class SkippedExampleNotification < ExampleNotification # RSpec's built-in formatters emit. def fully_formatted(pending_number, colorizer=::RSpec::Core::Formatters::ConsoleCodes) formatted_caller = RSpec.configuration.backtrace_formatter.backtrace_line(example.location) - colorizer.wrap("\n #{pending_number}) #{example.full_description}", :pending) << "\n " << - Formatters::ExceptionPresenter::PENDING_DETAIL_FORMATTER.call(example, colorizer) << - "\n" << colorizer.wrap(" # #{formatted_caller}\n", :detail) + colorizer.wrap("\n #{pending_number}) #{example.full_description}", :pending) + "\n " + + Formatters::ExceptionPresenter::PENDING_DETAIL_FORMATTER.call(example, colorizer) + + "\n" + colorizer.wrap(" # #{formatted_caller}\n", :detail) end end diff --git a/spec/rspec/core/formatters/base_text_formatter_spec.rb b/spec/rspec/core/formatters/base_text_formatter_spec.rb index 565425c33c..bb52318f0d 100644 --- a/spec/rspec/core/formatters/base_text_formatter_spec.rb +++ b/spec/rspec/core/formatters/base_text_formatter_spec.rb @@ -190,7 +190,7 @@ def run_all_and_dump_failures if String.method_defined?(:encoding) context "with an exception that has a differently encoded message" do it "runs without encountering an encoding exception" do - group.example("Mixing encodings, e.g. UTF-8: © and Binary") { raise "Error: \xC2\xA9".force_encoding("ASCII-8BIT") } + group.example("Mixing encodings, e.g. UTF-8: © and Binary") { raise "Error: \xC2\xA9".dup.force_encoding("ASCII-8BIT") } run_all_and_dump_failures expect(formatter_output.string).to match(/RuntimeError:\n\s+Error: \?\?/m) # ?? because the characters dont encode properly end diff --git a/spec/rspec/core/formatters/html_snippet_extractor_spec.rb b/spec/rspec/core/formatters/html_snippet_extractor_spec.rb index 68acdcf2cb..59b3c640ce 100644 --- a/spec/rspec/core/formatters/html_snippet_extractor_spec.rb +++ b/spec/rspec/core/formatters/html_snippet_extractor_spec.rb @@ -14,7 +14,7 @@ module Formatters it "falls back on a default message when it gets a security error" do message = with_safe_set_to_level_that_triggers_security_errors do - RSpec::Core::Formatters::HtmlSnippetExtractor.new.lines_around("blech".taint, 8) + RSpec::Core::Formatters::HtmlSnippetExtractor.new.lines_around("blech".dup.taint, 8) end expect(message).to eq("# Couldn't get snippet for blech") end diff --git a/spec/rspec/core/notifications_spec.rb b/spec/rspec/core/notifications_spec.rb index 1039ac449e..f8748c2f56 100644 --- a/spec/rspec/core/notifications_spec.rb +++ b/spec/rspec/core/notifications_spec.rb @@ -325,7 +325,7 @@ def normalize_one_backtrace(exception) if String.method_defined?(:encoding) it "returns failures_lines with invalid bytes replace by '?'" do message_with_invalid_byte_sequence = - "\xEF \255 \xAD I have bad bytes".force_encoding(Encoding::UTF_8) + "\xEF \255 \xAD I have bad bytes".dup.force_encoding(Encoding::UTF_8) allow(exception).to receive(:message). and_return(message_with_invalid_byte_sequence) diff --git a/spec/rspec/core_spec.rb b/spec/rspec/core_spec.rb index 18ec3a67ef..e107fc255d 100644 --- a/spec/rspec/core_spec.rb +++ b/spec/rspec/core_spec.rb @@ -241,7 +241,7 @@ def reporter RSpec.clear_examples - RSpec.configuration.deprecation_stream = StringIO.new(deprecations = "") + RSpec.configuration.deprecation_stream = StringIO.new(deprecations = "".dup) group = RSpec.describe do example { RSpec.deprecate("second deprecation") } From 7fa6b890aafc737436d6dba192db9ca0ad325703 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Wed, 28 Jun 2017 10:46:06 +1000 Subject: [PATCH 2/5] Updates for Coderay's colour changes. --- spec/rspec/core/formatters/syntax_highlighter_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/rspec/core/formatters/syntax_highlighter_spec.rb b/spec/rspec/core/formatters/syntax_highlighter_spec.rb index 392d7f4a02..4a793b7e48 100644 --- a/spec/rspec/core/formatters/syntax_highlighter_spec.rb +++ b/spec/rspec/core/formatters/syntax_highlighter_spec.rb @@ -83,7 +83,7 @@ def find_highlighted_terms_in(code_snippet) highlighted = highlighter.highlight(lines) highlighted_terms = [] - highlighted.join("\n").scan(/\e\[1;[1-9]\dm(\w+)\e\[0m/) do |first_capture, _| + highlighted.join("\n").scan(/\e\[[1-9]\dm(\w+)\e\[0m/) do |first_capture, _| highlighted_terms << first_capture end @@ -124,7 +124,7 @@ def find_highlighted_terms_in(code_snippet) end def be_highlighted - include("\e[32m") + include("\e[31m") end end From 86ea607bcd54fd9c5f24b8198617199e9561bc52 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Wed, 28 Jun 2017 20:36:03 +1000 Subject: [PATCH 3/5] One frozen-string-literal fix when running cucumber. --- features/configuration/pattern.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/configuration/pattern.feature b/features/configuration/pattern.feature index 7720c4f172..7b922eae48 100644 --- a/features/configuration/pattern.feature +++ b/features/configuration/pattern.feature @@ -45,7 +45,7 @@ Feature: pattern Given a file named "spec/spec_helper.rb" with: """ruby RSpec.configure do |config| - config.pattern << ',**/*.spec' + config.pattern += ',**/*.spec' end """ And a file named "spec/two_examples.spec" with: From 01292fcf40ec7ddfbbdd9e4f2def1d00d72253e0 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Wed, 28 Jun 2017 21:10:29 +1000 Subject: [PATCH 4/5] Limiting string allocations in skipped example notifications. --- lib/rspec/core/notifications.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/rspec/core/notifications.rb b/lib/rspec/core/notifications.rb index bfc4b33b50..16a3255cce 100644 --- a/lib/rspec/core/notifications.rb +++ b/lib/rspec/core/notifications.rb @@ -232,9 +232,14 @@ class SkippedExampleNotification < ExampleNotification # RSpec's built-in formatters emit. def fully_formatted(pending_number, colorizer=::RSpec::Core::Formatters::ConsoleCodes) formatted_caller = RSpec.configuration.backtrace_formatter.backtrace_line(example.location) - colorizer.wrap("\n #{pending_number}) #{example.full_description}", :pending) + "\n " + - Formatters::ExceptionPresenter::PENDING_DETAIL_FORMATTER.call(example, colorizer) + - "\n" + colorizer.wrap(" # #{formatted_caller}\n", :detail) + + [ + colorizer.wrap("\n #{pending_number}) #{example.full_description}", :pending), + "\n ", + Formatters::ExceptionPresenter::PENDING_DETAIL_FORMATTER.call(example, colorizer), + "\n", + colorizer.wrap(" # #{formatted_caller}\n", :detail) + ].join("") end end From 917bcd820b76f4d8d8afc698d8289067555bd8bd Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Thu, 29 Jun 2017 10:13:27 +1000 Subject: [PATCH 5/5] Update coderay dependency. Using the latest released version, which will at least pass with mutable string literals. --- rspec-core.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rspec-core.gemspec b/rspec-core.gemspec index 476a9cc07c..f4a44789ad 100644 --- a/rspec-core.gemspec +++ b/rspec-core.gemspec @@ -41,7 +41,7 @@ Gem::Specification.new do |s| s.add_development_dependency "minitest", "~> 5.3" s.add_development_dependency "aruba", "~> 0.6.2" # 0.7 is broken on ruby 1.8.7 - s.add_development_dependency "coderay", "~> 1.0.9" + s.add_development_dependency "coderay", "~> 1.1.1" s.add_development_dependency "mocha", "~> 0.13.0" s.add_development_dependency "rr", "~> 1.0.4"