From fc3370e024f7fb0125bf60d83ebc9576f62d3d94 Mon Sep 17 00:00:00 2001 From: Mike Linksvayer Date: Sun, 19 Nov 2017 12:11:14 -0800 Subject: [PATCH] basic test for line length <= 78 --- spec/license_wrap_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/license_wrap_spec.rb diff --git a/spec/license_wrap_spec.rb b/spec/license_wrap_spec.rb new file mode 100644 index 0000000..cac82bf --- /dev/null +++ b/spec/license_wrap_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'word wrapping' do + Dir["#{licenses_path}/*.txt"].each do |file| + context "the #{File.basename(file, '.txt')} license" do + it 'does not wrap at line length 78' do + file_content = File.read(file, encoding: 'utf-8') + license_text = file_content.match(/\A(?:---\n.*\n---\n+)?(.*)/m)[1] + max_line_length = 0 + max_line = "" + license_text.lines.each do |line| + if line.length > max_line_length + max_line_length = line.length + max_line = line + end + end + msg = "Longest line is #{max_line_length} characters: #{max_line}" + skip msg if max_line_length > 78 && max_line_length < 81 + expect(max_line_length).to be <= 78, msg + end + end + end +end