diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-06-27 13:01:30 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-08-03 09:29:57 +0900 |
commit | 812dfa44f0b35b6ee6446417e0e72f04270bdf85 (patch) | |
tree | a8efe0b30889acf1af556d76cbae0a52d0b9cdf0 /spec | |
parent | 6cbe818c668c07c0700b1281d629b92a9101c976 (diff) | |
download | ruby-812dfa44f0b35b6ee6446417e0e72f04270bdf85.tar.gz |
[bundler/bundler] Refactor setting the encoding in quality specs
Instead of setting the encoding globally, set it when reading the files.
https://github.com/bundler/bundler/commit/e2a5c45e4d
Diffstat (limited to 'spec')
-rw-r--r-- | spec/bundler/quality_spec.rb | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/spec/bundler/quality_spec.rb b/spec/bundler/quality_spec.rb index f3ff284770..1b53d067c2 100644 --- a/spec/bundler/quality_spec.rb +++ b/spec/bundler/quality_spec.rb @@ -2,11 +2,6 @@ require "set" -if defined?(Encoding) && Encoding.default_external.name != "UTF-8" - # An approximation of ruby -E UTF-8, since it works on 1.8.7 - Encoding.default_external = Encoding.find("UTF-8") -end - RSpec.describe "The library itself" do def check_for_debugging_mechanisms(filename) debugging_mechanisms_regex = / @@ -17,7 +12,7 @@ RSpec.describe "The library itself" do /x failing_lines = [] - File.readlines(filename).each_with_index do |line, number| + each_line(filename) do |line, number| if line =~ debugging_mechanisms_regex && !line.end_with?("# ignore quality_spec\n") failing_lines << number + 1 end @@ -35,7 +30,7 @@ RSpec.describe "The library itself" do /x failing_lines = [] - File.readlines(filename).each_with_index do |line, number| + each_line(filename) do |line, number| failing_lines << number + 1 if line =~ merge_conflicts_regex end @@ -45,7 +40,7 @@ RSpec.describe "The library itself" do def check_for_tab_characters(filename) failing_lines = [] - File.readlines(filename).each_with_index do |line, number| + each_line(filename) do |line, number| failing_lines << number + 1 if line =~ /\t/ end @@ -55,7 +50,7 @@ RSpec.describe "The library itself" do def check_for_extra_spaces(filename) failing_lines = [] - File.readlines(filename).each_with_index do |line, number| + each_line(filename) do |line, number| next if line =~ /^\s+#.*\s+\n$/ next if %w[LICENCE.md].include?(line) failing_lines << number + 1 if line =~ /\s+\n$/ @@ -78,7 +73,7 @@ RSpec.describe "The library itself" do ] pattern = /\b#{Regexp.union(useless_words)}\b/i - File.readlines(filename).each_with_index do |line, number| + each_line(filename) do |line, number| next unless word_found = pattern.match(line) failing_line_message << "#{filename}:#{number.succ} has '#{word_found}'. Avoid using these kinds of weak modifiers." end @@ -90,7 +85,7 @@ RSpec.describe "The library itself" do failing_line_message = [] specific_pronouns = /\b(he|she|his|hers|him|her|himself|herself)\b/i - File.readlines(filename).each_with_index do |line, number| + each_line(filename) do |line, number| next unless word_found = specific_pronouns.match(line) failing_line_message << "#{filename}:#{number.succ} has '#{word_found}'. Use more generic pronouns in documentation." end @@ -188,7 +183,7 @@ RSpec.describe "The library itself" do key_pattern = /([a-z\._-]+)/i lib_files = ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb` : `git ls-files -z -- lib` lib_files.split("\x0").each do |filename| - File.readlines(filename).each_with_index do |line, number| + each_line(filename) do |line, number| line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" } end end @@ -279,7 +274,7 @@ RSpec.describe "The library itself" do lib_files = ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb` : `git ls-files -z -- lib` lib_files.split("\x0").each do |filename| next if filename =~ exempt - File.readlines(filename).each_with_index do |line, number| + each_line(filename) do |line, number| line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" } end end @@ -287,4 +282,10 @@ RSpec.describe "The library itself" do expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}" end end + +private + + def each_line(filename, &block) + File.readlines(filename, :encoding => "UTF-8").each_with_index(&block) + end end |