1 # frozen_string_literal: true
5 RSpec.describe "The library itself" do
6 def check_for_git_merge_conflicts(filename)
7 merge_conflicts_regex = /
14 each_line(filename) do |line, number|
15 failing_lines << number + 1 if line&.match?(merge_conflicts_regex)
18 return if failing_lines.empty?
19 "#{filename} has unresolved git merge conflicts on lines #{failing_lines.join(", ")}"
22 def check_for_tab_characters(filename)
24 each_line(filename) do |line, number|
25 failing_lines << number + 1 if line.include?("\t")
28 return if failing_lines.empty?
29 "#{filename} has tab characters on lines #{failing_lines.join(", ")}"
32 def check_for_extra_spaces(filename)
34 each_line(filename) do |line, number|
35 next if /^\s+#.*\s+\n$/.match?(line)
36 failing_lines << number + 1 if /\s+\n$/.match?(line)
39 return if failing_lines.empty?
40 "#{filename} has spaces on the EOL on lines #{failing_lines.join(", ")}"
43 def check_for_extraneous_quotes(filename)
45 each_line(filename) do |line, number|
46 failing_lines << number + 1 if /\u{2019}/.match?(line)
49 return if failing_lines.empty?
50 "#{filename} has an extraneous quote on lines #{failing_lines.join(", ")}"
53 def check_for_expendable_words(filename)
54 failing_line_message = []
64 pattern = /\b#{Regexp.union(useless_words)}\b/i
66 each_line(filename) do |line, number|
67 next unless word_found = pattern.match(line)
68 failing_line_message << "#{filename}:#{number.succ} has '#{word_found}'. Avoid using these kinds of weak modifiers."
71 failing_line_message unless failing_line_message.empty?
74 def check_for_specific_pronouns(filename)
75 failing_line_message = []
76 specific_pronouns = /\b(he|she|his|hers|him|her|himself|herself)\b/i
78 each_line(filename) do |line, number|
79 next unless word_found = specific_pronouns.match(line)
80 failing_line_message << "#{filename}:#{number.succ} has '#{word_found}'. Use more generic pronouns in documentation."
83 failing_line_message unless failing_line_message.empty?
86 it "has no malformed whitespace" do
87 exempt = /\.gitmodules|fixtures|vendor|LICENSE|vcr_cassettes|rbreadline\.diff|index\.txt$/
89 tracked_files.each do |filename|
90 next if filename&.match?(exempt)
91 error_messages << check_for_tab_characters(filename)
92 error_messages << check_for_extra_spaces(filename)
94 expect(error_messages.compact).to be_well_formed
97 it "has no extraneous quotes" do
98 exempt = /vendor|vcr_cassettes|LICENSE|rbreadline\.diff/
100 tracked_files.each do |filename|
101 next if filename&.match?(exempt)
102 error_messages << check_for_extraneous_quotes(filename)
104 expect(error_messages.compact).to be_well_formed
107 it "does not include any unresolved merge conflicts" do
109 exempt = %r{lock/lockfile_spec|quality_spec|vcr_cassettes|\.ronn|lockfile_parser\.rb}
110 tracked_files.each do |filename|
111 next if filename&.match?(exempt)
112 error_messages << check_for_git_merge_conflicts(filename)
114 expect(error_messages.compact).to be_well_formed
117 it "maintains language quality of the documentation" do
120 man_tracked_files.each do |filename|
121 next unless filename&.match?(included)
122 error_messages << check_for_expendable_words(filename)
123 error_messages << check_for_specific_pronouns(filename)
125 expect(error_messages.compact).to be_well_formed
128 it "maintains language quality of sentences used in source code" do
130 exempt = /vendor|vcr_cassettes|CODE_OF_CONDUCT/
131 lib_tracked_files.each do |filename|
132 next if filename&.match?(exempt)
133 error_messages << check_for_expendable_words(filename)
134 error_messages << check_for_specific_pronouns(filename)
136 expect(error_messages.compact).to be_well_formed
139 it "documents all used settings" do
154 all_settings = Hash.new {|h, k| h[k] = [] }
155 documented_settings = []
157 Bundler::Settings::BOOL_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::BOOL_KEYS" }
158 Bundler::Settings::NUMBER_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::NUMBER_KEYS" }
159 Bundler::Settings::ARRAY_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::ARRAY_KEYS" }
160 Bundler::Settings::STRING_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::STRING_KEYS" }
162 key_pattern = /([a-z\._-]+)/i
163 lib_tracked_files.each do |filename|
164 each_line(filename) do |line, number|
165 line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" }
168 documented_settings = File.read("lib/bundler/man/bundle-config.1.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten
170 documented_settings.each do |s|
171 all_settings.delete(s)
172 expect(exemptions.delete(s)).to be_nil, "setting #{s} was exempted but was actually documented"
175 exemptions.each do |s|
176 expect(all_settings.delete(s)).to be_truthy, "setting #{s} was exempted but unused"
178 error_messages = all_settings.map do |setting, refs|
179 "The `#{setting}` setting is undocumented\n\t- #{refs.join("\n\t- ")}\n"
182 expect(error_messages.sort).to be_well_formed
184 expect(documented_settings).to be_sorted
187 it "can still be built" do
188 with_built_bundler do |_gem_path|
189 expect(err).to be_empty, "bundler should build as a gem without warnings, but\n#{err}"
193 it "ships the correct set of files" do
194 git_list = tracked_files.reject {|f| f.start_with?("spec/") }
196 gem_list = loaded_gemspec.files
197 gem_list.map! {|f| f.sub(%r{\Aexe/}, "libexec/") } if ruby_core?
199 expect(git_list).to match_array(gem_list)
202 it "does not contain any warnings" do
204 lib/bundler/capistrano.rb
205 lib/bundler/deployment.rb
206 lib/bundler/gem_tasks.rb
209 files_to_require = lib_tracked_files.grep(/\.rb$/) - exclusions
210 files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") }
211 files_to_require.map! {|f| File.expand_path(f, source_root) }
212 files_to_require.sort!
213 sys_exec("ruby -w") do |input, _, _|
214 files_to_require.each do |f|
215 input.puts "require '#{f}'"
219 warnings = last_command.stdboth.split("\n")
220 # ignore warnings around deprecated Object#=~ method in RubyGems
221 warnings.reject! {|w| w =~ %r{rubygems\/version.rb.*deprecated\ Object#=~} }
223 expect(warnings).to be_well_formed
226 it "does not use require internally, but require_relative" do
227 exempt = %r{templates/|\.5|\.1|vendor/}
228 all_bad_requires = []
229 lib_tracked_files.each do |filename|
230 next if filename&.match?(exempt)
231 each_line(filename) do |line, number|
232 line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" }
236 expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}"
241 def each_line(filename, &block)
242 File.readlines(filename, encoding: "UTF-8").each_with_index(&block)