From 3aa6448448da29d3d9c75c785ed719d5eb4bbf00 Mon Sep 17 00:00:00 2001
From: Xenofon Deligiannis
Date: Mon, 22 Apr 2019 11:34:53 +0300
Subject: [PATCH] Fix rubucop warnings for html_truncator_spec
---
spec/truncate_html/html_truncator_spec.rb | 38 ++++++++++-------------
1 file changed, 17 insertions(+), 21 deletions(-)
diff --git a/spec/truncate_html/html_truncator_spec.rb b/spec/truncate_html/html_truncator_spec.rb
index 2daffe9..0dedbf1 100644
--- a/spec/truncate_html/html_truncator_spec.rb
+++ b/spec/truncate_html/html_truncator_spec.rb
@@ -1,8 +1,6 @@
-# Encoding: UTF-8
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
describe TruncateHtml::HtmlTruncator do
-
def truncate(html, opts = {})
html_string = TruncateHtml::HtmlString.new(html)
TruncateHtml::HtmlTruncator.new(html_string, opts).truncate
@@ -24,13 +22,13 @@ def truncate(html, opts = {})
context 'and a custom omission value is passed' do
it 'retains the omission text' do
expect(
- truncate("testtest", length: 10, omission: '..', word_boundary: false)
+ truncate('testtest', length: 10, omission: '..', word_boundary: false)
).to eq 'testtest..'
end
it 'handles multibyte characters' do
expect(
- truncate("prüfenprüfen", length: 8, omission: '..', word_boundary: false)
+ truncate('prüfenprüfen', length: 8, omission: '..', word_boundary: false)
).to eq 'prüfen..'
end
end
@@ -54,7 +52,7 @@ def truncate(html, opts = {})
it 'is respectful of closing tags' do
expect(truncate('hmmm this should be okay. I think...
',
length: 28, omission: '', word_boundary: /\S[\.\?\!]/)).
- to eq "hmmm this should be okay.
"
+ to eq 'hmmm this should be okay.
'
end
end
@@ -62,17 +60,17 @@ def truncate(html, opts = {})
expect(truncate('a b c', length: 4, omission: '...')).to eq 'a...'
end
- it "includes omission even on the edge (issue #18)" do
+ it 'includes omission even on the edge (issue #18)' do
opts = { word_boundary: false, length: 12 }
expect(truncate('One two three', opts)).to eq 'One two t...'
end
- it "never returns a string longer than :length" do
- expect(truncate("test this shit", length: 10)).to eq 'test...'
+ it 'never returns a string longer than :length' do
+ expect(truncate('test this shit', length: 10)).to eq 'test...'
end
it 'supports omissions longer than the maximum length' do
- expect{ truncate('', length: 1, omission: '...') }.to_not raise_error
+ expect { truncate('', length: 1, omission: '...') }.to_not raise_error
end
it 'returns the omission when the specified length is smaller than the omission' do
@@ -110,24 +108,23 @@ def truncate(html, opts = {})
end
it 'handles multibyte characters and leaves them in the result' do
- html = 'Look at our multibyte characters ā ž this link for randomness ā ž
'
+ html = 'Look at our multibyte characters ā ž this link for randomness ā ž
'
expect(truncate(html, length: html.length)).to eq html
end
- #unusual, but just covering my ass
+ # unusual, but just covering my ass
it 'recognizes the multiline html properly' do
- html = <<-END_HTML
-
-This is ugly html.
-
+ html = <<~END_HTML
+
+ This is ugly html.
+
END_HTML
expect(truncate(html, length: 12)).to eq ' This is...
'
end
- %w(br hr img).each do |unpaired_tag|
+ %w[br hr img].each do |unpaired_tag|
context "when the html contains a #{unpaired_tag} tag" do
-
context "and the #{unpaired_tag} does not have the closing slash" do
it "does not close the #{unpaired_tag} tag" do
html = "Some before. <#{unpaired_tag}>and some after
"
@@ -145,7 +142,6 @@ def truncate(html, opts = {})
expect(truncate(html_caps, length: 19)).to eq "Some before. <#{unpaired_tag.capitalize} />and...
"
end
end
-
end
end
@@ -159,8 +155,8 @@ def truncate(html, opts = {})
“我现在使用的是中文的拼音。”
测试一下具体的truncatehtml功能。
"
- expect(truncate(html, omission: "", length: 50)).
- to include "“我现在使用的是中文的拼音。”
"
+ expect(truncate(html, omission: '', length: 50)).
+ to include '
“我现在使用的是中文的拼音。”
'
end
context 'when the break_token option is set as ' do