Sha256: 1cc09a680192a32d9858d2b4ab9479bbbed90251c2fe7f26d4c2ffbaae5aa4b9
Contents?: true
Size: 1.87 KB
Versions: 3
Compression:
Stored size: 1.87 KB
Contents
require 'test_helper' describe Prawn::Emoji::Drawer do let(:document) { Prawn::Document.new } let(:drawer) { Prawn::Emoji::Drawer.new document: document } let(:sushi) { '🍣' } let(:sushi_image) { Prawn::Emoji::Image.new(sushi) } before do document.font Prawn::Emoji.root.join 'test', 'fonts', 'DejaVuSans.ttf' end describe '#draw' do subject { drawer.draw(text, {}) } describe 'when text encoding is not utf-8' do let(:text) { "\xe8\x8a\xb1".force_encoding('ascii-8bit') } it 'skip' do mock(drawer).draw_emoji(text, {}).never subject end end describe 'when text encoding is utf-8' do let(:text) { "\xe8\x8a\xb1" } it 'performs' do mock(drawer).draw_emoji(text, {}).once subject end end end describe '#draw_emoji' do subject { drawer.send :draw_emoji, text, text_options } let(:text_options) { { at: [100, 100], font_size: 12 } } describe 'when not includes emoji' do let(:text) { 'abc' } it 'returns original text' do subject.must_be_same_as text end end describe 'when includes emoji' do let(:text) { "aaa#{sushi}bbb"} it 'draws image for included emoji' do image_width = 12 image_at = [100 + document.width_of('aaa', text_options), 100 + 12] mock(drawer).draw_emoji_image(sushi_image, at: image_at, width: image_width).once subject end it 'returns text that all emoji has substituted' do subject.must_equal "aaa#{Prawn::Emoji::Substitution.new(document)}bbb" end end end describe '#draw_emoji_image' do subject { drawer.send :draw_emoji_image, sushi_image, at: [100, 100], width: 12 } it 'calls Prawn::Document#image with valid arguments' do mock(document).image(sushi_image.path, at: [100, 100], width: 12).once subject end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
prawn-emoji-2.0.0 | test/prawn/emoji/drawer_test.rb |
prawn-emoji-1.0.2 | test/prawn/emoji/drawer_spec.rb |
prawn-emoji-1.0.1 | test/prawn/emoji/drawer_spec.rb |