# encoding: UTF-8 require 'spec_helper' describe 'common_helper' do describe '#get_equal_string' do after :each do output = get_equal_string_end(@input) expect(output).to eq @expected end it 'returns an empty string' do @input = %w() @expected = '' end it 'returns an empty string' do @input = [] @expected = '' end it 'returns an empty string' do @input = ['asdf', nil] @expected = '' end it 'returns an empty string' do @input = [nil, 'asdf'] @expected = '' end it 'returns asdf' do @input = [nil, 'a asdf', nil, 'b asdf'] @expected = ' asdf' end it 'returns asdf' do @input = ['kjh asdf', 'oijr asdf'] @expected = ' asdf' end it 'returns « BlogName' do @input = ['user1 « BlogName', 'user2 « BlogName', 'user3 « BlogName', 'user4 « BlogName'] @expected = ' « BlogName' end it 'returns an empty string' do @input = %w{user1 user2 user3 user4} @expected = '' end it 'returns an empty string' do @input = ['user1 « BlogName', 'user2 « BlogName', 'user3 « BlogName', 'user4 « BlogNamea'] @expected = '' end it 'returns an empty string' do @input = %w{ user1 } @expected = '' end it 'returns | test' do @input = ['admin | test', 'test | test'] @expected = ' | test' end end describe '#remove_base64_images_from_html' do after :each do output = remove_base64_images_from_html(@html) expect(output).to eq @expected end it 'removes the valid base64 image' do @html = '' @expected = '' end it 'ignores invalid base64 content' do @html = '' @expected = @html end end describe '#truncate' do after :each do output = truncate(@input, @length, @trailing) expect(output).to eq @expected end it 'returns nil on no input' do @input = nil @length = 1 @expected = nil @trailing = '...' end it 'returns input when length > input' do @input = '1234567890' @length = 13 @expected = @input @trailing = '...' end it 'truncates the input' do @input = '1234567890' @length = 6 @expected = '123...' @trailing = '...' end it 'adds own trailing' do @input = '1234567890' @length = 7 @expected = '123xxxx' @trailing = 'xxxx' end it 'accepts strings as length' do @input = '1234567890' @length = '6' @expected = '123...' @trailing = '...' end it 'checks if trailing is longer than input' do @input = '1234567890' @length = 1 @expected = @input @trailing = 'A' * 20 end it 'returns input on negative length' do @input = '1234567890' @length = -1 @expected = @input @trailing = '...' end it 'returns input on length == input.length' do @input = '1234567890' @length = '10' @expected = @input @trailing = '...' end it 'returns cut string on nil trailing' do @input = '1234567890' @length = 9 @expected = '123456789' @trailing = nil end it 'trailing.length > length' do @input = '1234567890' @length = 1 @expected = @input @trailing = 'A' * 20 end end end