diff --git a/spec/helpers/truncate_html_helper_spec.rb b/spec/helpers/truncate_html_helper_spec.rb index 805bbc7..a438122 100644 --- a/spec/helpers/truncate_html_helper_spec.rb +++ b/spec/helpers/truncate_html_helper_spec.rb @@ -13,31 +13,31 @@ def truncator end it 'is included in ActionView::Base' do - ActionView::Base.included_modules.should include(TruncateHtmlHelper) + expect(ActionView::Base.included_modules).to include(TruncateHtmlHelper) end before(:each) do @original_html = '
foo
' - @original_html.stub(:html_safe).and_return(@original_html) + allow(@original_html).to receive(:html_safe).and_return(@original_html) end it 'creates an instance of HtmlTruncator and calls truncate on it' do truncator = double(truncate: @original_html) - TruncateHtml::HtmlTruncator.should_receive(:new).and_return(truncator) + expect(TruncateHtml::HtmlTruncator).to receive(:new).and_return(truncator) truncator.truncate_html(@original_html) end it 'calls truncate on the HtmlTruncator object' do truncator = double(truncate: @original_html) - TruncateHtml::HtmlTruncator.stub(:new).and_return(truncator) - truncator.should_receive(:truncate).and_return(@original_html) + allow(TruncateHtml::HtmlTruncator).to receive(:new).and_return(truncator) + expect(truncator).to receive(:truncate).and_return(@original_html) truncator.truncate_html('foo') end context 'the input html is nil' do it 'returns an empty string' do - truncator.truncate_html(nil).should be_empty - truncator.truncate_html(nil).should be_kind_of(String) + expect(truncator.truncate_html(nil)).to be_empty + expect(truncator.truncate_html(nil)).to be_kind_of(String) end end diff --git a/spec/truncate_html/configuration_spec.rb b/spec/truncate_html/configuration_spec.rb index 7c503bb..cb982d7 100644 --- a/spec/truncate_html/configuration_spec.rb +++ b/spec/truncate_html/configuration_spec.rb @@ -5,12 +5,12 @@ describe 'self.configure' do it 'yields the configuration object' do - lambda do + expect do TruncateHtml.configure do |config| - config.should be_kind_of(TruncateHtml::Configuration) + expect(config).to be_kind_of(TruncateHtml::Configuration) throw :yay_it_yielded end - end.should throw_symbol(:yay_it_yielded) + end.to throw_symbol(:yay_it_yielded) end end diff --git a/spec/truncate_html/html_string_spec.rb b/spec/truncate_html/html_string_spec.rb index 064f87b..bf2945c 100644 --- a/spec/truncate_html/html_string_spec.rb +++ b/spec/truncate_html/html_string_spec.rb @@ -10,51 +10,53 @@ def html_string(original_string) describe '#html_tokens' do it 'returns each token in the string as an array element removing any consecutive whitespace from the string' do html = 'This is sweet!
squaremeter m²
' - html_string(html).html_tokens.should == ['', 'This', ' ', 'is', ' ', 'sweet!', '
', - ' ', '', ' ', 'squaremeter', ' ', 'm²', ' ', '
'] + expect(html_string(html).html_tokens). + to eq ['', 'This', ' ', + 'is', ' ', 'sweet!', '
', ' ', '', ' ', 'squaremeter', ' ', + 'm²', ' ', '
'] end end describe '#html_tag?' do it 'returns false when the string parameter is not an html tag' do - html_string('no tags').should_not be_html_tag + expect(html_string('no tags')).not_to be_html_tag end it 'returns true when the string parameter is an html tag' do - html_string('').should be_html_tag - html_string('').should be_html_tag + expect(html_string('')).to be_html_tag + expect(html_string('')).to be_html_tag end it 'is false for html comments' do - html_string('').should_not be_html_tag + expect(html_string('')).not_to be_html_tag end end describe '#open_tag?' do it 'returns true if the tag is an open tag' do - html_string('').should be_open_tag + expect(html_string('')).to be_open_tag end context 'the tag is an open tag, and has whitespace and html properties' do it 'returns true if it has single quotes' do - html_string(" ").should be_open_tag + expect(html_string(" ")).to be_open_tag end it 'returns true if it has double quotes' do - html_string(' ').should be_open_tag + expect(html_string(' ')).to be_open_tag end end it 'returns false if the tag is a close tag' do - html_string('').should_not be_open_tag + expect(html_string('')).not_to be_open_tag end it 'returns false if the string is not an html tag' do - html_string('foo bar').should_not be_open_tag + expect(html_string('foo bar')).not_to be_open_tag end it 'returns false if it is a and more text" expected_out = "I have a script and...
" - truncate(input_html, :length => 23).should == expected_out + expect(truncate(input_html, length: 23)).to eq expected_out end it 'in the middle of a link, truncates and closes the , and closes any remaining open tags' do html = 'Look at this#{char} More words here
" expected = "Look at this#{char}...
" - truncate(html, :length => 19).should == expected + expect(truncate(html, length: 19)).to eq expected end end end @@ -92,13 +105,13 @@ def truncate(html, opts = {}) it 'leaves a whitespace between the closing tag and the following word character' do html = 'Look at this link for randomness
' expected = 'Look at this link...
' - truncate(html, :length => 21).should == expected + expect(truncate(html, length: 21)).to eq expected end end it 'handles multibyte characters and leaves them in the result' do html = 'Look at our multibyte characters ā ž this link for randomness ā ž
' - truncate(html, :length => html.length).should == html + expect(truncate(html, length: html.length)).to eq html end #unusual, but just covering my ass @@ -109,7 +122,7 @@ def truncate(html, opts = {}) This is ugly html. END_HTML - truncate(html, :length => 12).should == ' ' + expect(truncate(html, length: 12)).to eq ' ' end %w(br hr img).each do |unpaired_tag| @@ -119,8 +132,8 @@ def truncate(html, opts = {}) it "does not close the #{unpaired_tag} tag" do html = "“我现在使用的是中文的拼音。”
"
+ expect(truncate(html, omission: "", length: 50)).
+ to include "
“我现在使用的是中文的拼音。”
"
end
context 'when the break_token option is set as ' do
it 'does not truncate abnormally if the break_token is not present' do
- truncate('This is line one. This is line two.', :length => 30, :break_token => '').should == 'This is line one. This is...'
+ expect(truncate('This is line one. This is line two.',
+ length: 30, break_token: '')).
+ to eq 'This is line one. This is...'
end
it 'does not truncate abnormally if the break_token is present, but beyond the length param' do
- truncate('This is line one. This is line two.', :length => 30, :break_token => '').should == 'This is line one. This is...'
+ expect(truncate('This is line one. This is line two.',
+ length: 30, break_token: '')).
+ to eq 'This is line one. This is...'
end
it 'truncates before the length param if the break_token is before the token at "length"' do
- truncate('This is line one. This is line two.', :length => 30, :break_token => '').should == 'This is line one.'
+ expect(truncate('This is line one. This is line two.',
+ length: 30, break_token: '')).
+ to eq 'This is line one.'
end
end
context 'when the break_token option is customized as a comment' do
it 'does not truncate abnormally if the break_token is not present' do
- truncate('This is line one. This is line two.', :length => 30, :break_token => '').should == 'This is line one. This is...'
+ expect(truncate('This is line one. This is line two.',
+ length: 30, break_token: '')).
+ to eq 'This is line one. This is...'
end
it 'does not truncate abnormally if the break_token is present, but beyond the length param' do
- truncate('This is line one. This is line two.', :length => 30, :break_token => '').should == 'This is line one. This is...'
+ expect(truncate('This is line one. This is line two.',
+ length: 30, break_token: '')).
+ to eq 'This is line one. This is...'
end
it 'truncates before the length param if the break_token is before the token at "length"' do
- truncate('This is line one. This is line two.', :length => 30, :break_token => '').should == 'This is line one.'
+ expect(truncate('This is line one. This is line two.',
+ length: 30, break_token: '')).
+ to eq 'This is line one.'
end
end
context 'when the break_token option is customized as an html tag' do
it 'does not truncate abnormally if the break_token is not present' do
- truncate('This is line one. This is line two.', :length => 30, :break_token => '