aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-07-22 23:13:42 +0200
committerXavier Noria <fxn@hashref.com>2016-07-22 23:13:49 +0200
commitcfc91c31aa989826e992be29b6d5b181f654f853 (patch)
treeb5ec5569b22f8c796de89335c5ecc7de047130bc /activesupport/test
parentaea0e5cd709e0fc53e1ba4e87235b8ee3f4bc155 (diff)
downloadrails-cfc91c31aa989826e992be29b6d5b181f654f853.tar.gz
rails-cfc91c31aa989826e992be29b6d5b181f654f853.tar.bz2
rails-cfc91c31aa989826e992be29b6d5b181f654f853.zip
systematic revision of =~ usage in AS
Where appropriate prefer the more concise Regexp#match?, String#include?, String#start_with?, and String#end_with?
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/clean_backtrace_test.rb8
-rw-r--r--activesupport/test/json/encoding_test.rb14
-rw-r--r--activesupport/test/multibyte_conformance_test.rb2
-rw-r--r--activesupport/test/multibyte_grapheme_break_conformance_test.rb2
-rw-r--r--activesupport/test/multibyte_normalization_conformance_test.rb2
-rw-r--r--activesupport/test/xml_mini/jdom_engine_test.rb2
6 files changed, 18 insertions, 12 deletions
diff --git a/activesupport/test/clean_backtrace_test.rb b/activesupport/test/clean_backtrace_test.rb
index 05580352a9..14cf65ef2d 100644
--- a/activesupport/test/clean_backtrace_test.rb
+++ b/activesupport/test/clean_backtrace_test.rb
@@ -26,7 +26,7 @@ end
class BacktraceCleanerSilencerTest < ActiveSupport::TestCase
def setup
@bc = ActiveSupport::BacktraceCleaner.new
- @bc.add_silencer { |line| line =~ /mongrel/ }
+ @bc.add_silencer { |line| line.include?('mongrel') }
end
test "backtrace should not contain lines that match the silencer" do
@@ -44,8 +44,8 @@ end
class BacktraceCleanerMultipleSilencersTest < ActiveSupport::TestCase
def setup
@bc = ActiveSupport::BacktraceCleaner.new
- @bc.add_silencer { |line| line =~ /mongrel/ }
- @bc.add_silencer { |line| line =~ /yolo/ }
+ @bc.add_silencer { |line| line.include?('mongrel') }
+ @bc.add_silencer { |line| line.include?('yolo') }
end
test "backtrace should not contain lines that match the silencers" do
@@ -66,7 +66,7 @@ class BacktraceCleanerFilterAndSilencerTest < ActiveSupport::TestCase
def setup
@bc = ActiveSupport::BacktraceCleaner.new
@bc.add_filter { |line| line.gsub("/mongrel", "") }
- @bc.add_silencer { |line| line =~ /mongrel/ }
+ @bc.add_silencer { |line| line.include?('mongrel') }
end
test "backtrace should not silence lines that has first had their silence hook filtered out" do
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 5fc2e16336..8cb3b1a9bb 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -1,6 +1,7 @@
require 'securerandom'
require 'abstract_unit'
require 'active_support/core_ext/string/inflections'
+require 'active_support/core_ext/regexp'
require 'active_support/json'
require 'active_support/time'
require 'time_zone_test_helpers'
@@ -10,8 +11,11 @@ class TestJSONEncoding < ActiveSupport::TestCase
include TimeZoneTestHelpers
def sorted_json(json)
- return json unless json =~ /^\{.*\}$/
- '{' + json[1..-2].split(',').sort.join(',') + '}'
+ if json.start_with?('{') && json.end_with?('}')
+ '{' + json[1..-2].split(',').sort.join(',') + '}'
+ else
+ json
+ end
end
JSONTest::EncodingTestCases.constants.each do |class_tests|
@@ -19,8 +23,10 @@ class TestJSONEncoding < ActiveSupport::TestCase
begin
prev = ActiveSupport.use_standard_json_time_format
- ActiveSupport.escape_html_entities_in_json = class_tests !~ /^Standard/
- ActiveSupport.use_standard_json_time_format = class_tests =~ /^Standard/
+ standard_class_tests = /Standard/.match?(class_tests)
+
+ ActiveSupport.escape_html_entities_in_json = !standard_class_tests
+ ActiveSupport.use_standard_json_time_format = standard_class_tests
JSONTest::EncodingTestCases.const_get(class_tests).each do |pair|
assert_equal pair.last, sorted_json(ActiveSupport::JSON.encode(pair.first))
end
diff --git a/activesupport/test/multibyte_conformance_test.rb b/activesupport/test/multibyte_conformance_test.rb
index c10133a7a6..50ec6442ff 100644
--- a/activesupport/test/multibyte_conformance_test.rb
+++ b/activesupport/test/multibyte_conformance_test.rb
@@ -87,7 +87,7 @@ class MultibyteConformanceTest < ActiveSupport::TestCase
File.open(File.join(CACHE_DIR, UNIDATA_FILE), 'r') do | f |
until f.eof?
line = f.gets.chomp!
- next if (line.empty? || line =~ /^\#/)
+ next if line.empty? || line.start_with?('#')
cols, comment = line.split("#")
cols = cols.split(";").map(&:strip).reject(&:empty?)
diff --git a/activesupport/test/multibyte_grapheme_break_conformance_test.rb b/activesupport/test/multibyte_grapheme_break_conformance_test.rb
index 61943b1ab3..1d52a56971 100644
--- a/activesupport/test/multibyte_grapheme_break_conformance_test.rb
+++ b/activesupport/test/multibyte_grapheme_break_conformance_test.rb
@@ -36,7 +36,7 @@ class MultibyteGraphemeBreakConformanceTest < ActiveSupport::TestCase
until f.eof? || (max_test_lines > 21 and lines > max_test_lines)
lines += 1
line = f.gets.chomp!
- next if (line.empty? || line =~ /^\#/)
+ next if line.empty? || line.start_with?('#')
cols, comment = line.split("#")
# Cluster breaks are represented by รท
diff --git a/activesupport/test/multibyte_normalization_conformance_test.rb b/activesupport/test/multibyte_normalization_conformance_test.rb
index 77ed0ce6de..4b940a2054 100644
--- a/activesupport/test/multibyte_normalization_conformance_test.rb
+++ b/activesupport/test/multibyte_normalization_conformance_test.rb
@@ -91,7 +91,7 @@ class MultibyteNormalizationConformanceTest < ActiveSupport::TestCase
until f.eof? || (max_test_lines > 38 and lines > max_test_lines)
lines += 1
line = f.gets.chomp!
- next if (line.empty? || line =~ /^\#/)
+ next if line.empty? || line.start_with?('#')
cols, comment = line.split("#")
cols = cols.split(";").map{|e| e.strip}.reject{|e| e.empty? }
diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb
index ed4de8aba2..34e213b718 100644
--- a/activesupport/test/xml_mini/jdom_engine_test.rb
+++ b/activesupport/test/xml_mini/jdom_engine_test.rb
@@ -1,4 +1,4 @@
-if RUBY_PLATFORM =~ /java/
+if RUBY_PLATFORM.include?('java')
require 'abstract_unit'
require 'active_support/xml_mini'
require 'active_support/core_ext/hash/conversions'