prawn-icon 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('fontawesome.pdf') do
7
7
  deja_path = File.join \
8
- Prawn::Icon::FONTDIR, 'DejaVuSans.ttf'
8
+ Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
9
9
 
10
10
  font_families.update({
11
11
  'deja' => { normal: deja_path }
@@ -5,7 +5,7 @@ require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('foundation_icons.pdf') do
7
7
  deja_path = File.join \
8
- Prawn::Icon::FONTDIR, 'DejaVuSans.ttf'
8
+ Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
9
9
 
10
10
  font_families.update({
11
11
  'deja' => { normal: deja_path }
@@ -5,7 +5,7 @@ require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('octicons.pdf') do
7
7
  deja_path = File.join \
8
- Prawn::Icon::FONTDIR, 'DejaVuSans.ttf'
8
+ Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
9
9
 
10
10
  font_families.update({
11
11
  'deja' => { normal: deja_path }
@@ -5,7 +5,7 @@ require_relative 'example_helper'
5
5
 
6
6
  Prawn::Document.generate('paymentfont.pdf') do
7
7
  deja_path = File.join \
8
- Prawn::Icon::FONTDIR, 'DejaVuSans.ttf'
8
+ Prawn::Icon::Base::FONTDIR, 'DejaVuSans.ttf'
9
9
 
10
10
  font_families.update({
11
11
  'deja' => { normal: deja_path }
@@ -6,21 +6,11 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- require 'prawn'
9
+ require_relative 'icon/base'
10
10
  require_relative 'icon/font_data'
11
11
  require_relative 'icon/parser'
12
12
 
13
13
  module Prawn
14
- module Errors
15
- # Error raised when an icon glyph is not found
16
- #
17
- IconNotFound = Class.new(StandardError)
18
-
19
- # Error raised when an icon key is not provided
20
- #
21
- IconKeyEmpty = Class.new(StandardError)
22
- end
23
-
24
14
  # Easy icon font usage within Prawn. Currently
25
15
  # supported icon fonts include: FontAwesome,
26
16
  # Zurb Foundicons, GitHub Octicons, as well as
@@ -34,7 +24,7 @@ module Prawn
34
24
  # rule, included icon keys should match the keys from
35
25
  # the font provider. The icon key mapping is specified
36
26
  # in the font's +legend_file+, which is a +YAML+ file
37
- # located in Prawn::Icon::FONTDIR/font/font.yml.
27
+ # located in Prawn::Icon::Base::FONTDIR/font/font.yml.
38
28
  #
39
29
  # Prawn::Icon::
40
30
  # Houses the methods and interfaces necessary for
@@ -53,8 +43,7 @@ module Prawn
53
43
  # to Prawn's internal formatted text parser.
54
44
  #
55
45
  class Icon
56
- FONTDIR = File.join \
57
- File.expand_path('../../..', __FILE__), 'data/fonts'
46
+ FONTDIR = Icon::Base::FONTDIR
58
47
 
59
48
  module Interface
60
49
  # Set up and draw an icon on this document. This
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ #
3
+ # base.rb - Base configuration for Prawn::Icon.
4
+ #
5
+ # Copyright September 2016, Jesse Doyle. All rights reserved.
6
+ #
7
+ # This is free software. Please see the LICENSE and COPYING files for details.
8
+
9
+ require 'prawn'
10
+ require_relative 'errors'
11
+
12
+ module Prawn
13
+ class Icon
14
+ module Base
15
+ FONTDIR = File.join \
16
+ File.expand_path('../../../..', __FILE__), 'data/fonts'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Prawn
2
+ class Icon
3
+ module Errors
4
+ # Error raised when an icon glyph is not found
5
+ #
6
+ IconNotFound = Class.new(StandardError)
7
+
8
+ # Error raised when an icon key is not provided
9
+ #
10
+ IconKeyEmpty = Class.new(StandardError)
11
+ end
12
+ end
13
+ end
@@ -34,7 +34,7 @@ module Prawn
34
34
 
35
35
  def specifier_from_key(key)
36
36
  if key.nil? || key == ''
37
- raise Prawn::Errors::IconKeyEmpty,
37
+ raise Errors::IconKeyEmpty,
38
38
  'Icon key provided was nil.'
39
39
  end
40
40
 
@@ -63,15 +63,15 @@ module Prawn
63
63
  end
64
64
 
65
65
  def path
66
- ttf = File.join(Icon::FONTDIR, @set.to_s, '*.ttf')
67
- fonts = Dir[ttf]
66
+ ttf = File.join(Icon::Base::FONTDIR, @set.to_s, '*.ttf')
67
+ font = Dir[ttf].first
68
68
 
69
- if fonts.empty?
69
+ if font.nil?
70
70
  raise Prawn::Errors::UnknownFont,
71
71
  "Icon font not found for set: #{@set}"
72
72
  end
73
73
 
74
- @path ||= fonts.first
74
+ @path ||= font
75
75
  end
76
76
 
77
77
  def specifier
@@ -81,7 +81,7 @@ module Prawn
81
81
  def unicode(key)
82
82
  yaml[specifier][key].tap do |char|
83
83
  unless char
84
- raise Prawn::Errors::IconNotFound,
84
+ raise Errors::IconNotFound,
85
85
  "Key: #{specifier}-#{key} not found"
86
86
  end
87
87
  end
@@ -8,6 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Icon
11
- VERSION = '1.1.1'.freeze
11
+ VERSION = '1.2.0'.freeze
12
12
  end
13
13
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency('prawn', '>= 1.1.0', '< 3.0.0')
26
26
 
27
27
  spec.add_development_dependency('pdf-inspector', '~> 1.2.1')
28
- spec.add_development_dependency('rspec', '~> 3.4.0')
28
+ spec.add_development_dependency('rspec', '~> 3.5.0')
29
29
  spec.add_development_dependency('rubocop', '~> 0.38.0')
30
30
  spec.add_development_dependency('rake')
31
31
  spec.add_development_dependency('pdf-reader', '~> 1.4')
@@ -7,11 +7,12 @@
7
7
  require 'spec_helper'
8
8
 
9
9
  describe Prawn::Icon::Interface do
10
+ let(:pdf) { create_pdf }
11
+
10
12
  describe '::icon' do
11
13
  context 'valid icon key' do
12
14
  context 'with options' do
13
15
  it 'should handle text options (size)' do
14
- pdf = create_pdf
15
16
  pdf.icon 'fa-arrows', size: 60
16
17
  text = PDF::Inspector::Text.analyze(pdf.render)
17
18
 
@@ -21,7 +22,6 @@ describe Prawn::Icon::Interface do
21
22
 
22
23
  context 'inline_format: true' do
23
24
  it 'should handle text options (size)' do
24
- pdf = create_pdf
25
25
  pdf.icon '<icon size="60">fa-arrows</icon>', inline_format: true
26
26
  text = PDF::Inspector::Text.analyze(pdf.render)
27
27
 
@@ -43,7 +43,6 @@ describe Prawn::Icon::Interface do
43
43
 
44
44
  it 'renders the icon at the proper cursor position (#24)' do
45
45
  icon_text = '<icon>fa-info-circle</icon> icon here!'
46
- pdf = create_pdf
47
46
  pdf.text 'Start'
48
47
  pdf.move_down 10
49
48
  pdf.text 'More'
@@ -55,11 +54,19 @@ describe Prawn::Icon::Interface do
55
54
  expect(icon.at.first).to eq(0)
56
55
  expect(icon.at.last.round).to eq(734)
57
56
  end
57
+
58
+ context 'with final_gap: false' do
59
+ it 'renders the icon without a final gap' do
60
+ icon = pdf.icon '<icon size="60">fa-arrows</icon>',
61
+ inline_format: true,
62
+ final_gap: false
63
+ expect(icon.at.last.round).to eq(792)
64
+ end
65
+ end
58
66
  end
59
67
 
60
68
  context 'without options' do
61
69
  it 'should render an icon to document' do
62
- pdf = create_pdf
63
70
  pdf.icon 'fa-arrows'
64
71
  text = PDF::Inspector::Text.analyze(pdf.render)
65
72
 
@@ -70,16 +77,14 @@ describe Prawn::Icon::Interface do
70
77
 
71
78
  context 'invalid icon key' do
72
79
  it 'should raise IconNotFound' do
73
- pdf = create_pdf
74
80
  proc = Proc.new { pdf.icon 'fa-__INVALID' }
75
81
 
76
- expect(proc).to raise_error(Prawn::Errors::IconNotFound)
82
+ expect(proc).to raise_error(Prawn::Icon::Errors::IconNotFound)
77
83
  end
78
84
  end
79
85
 
80
86
  context 'invalid specifier' do
81
87
  it 'should raise UnknownFont' do
82
- pdf = create_pdf
83
88
  proc = Proc.new { pdf.icon '__INVALID__' }
84
89
 
85
90
  expect(proc).to raise_error(Prawn::Errors::UnknownFont)
@@ -90,39 +95,35 @@ describe Prawn::Icon::Interface do
90
95
  describe '::make_icon' do
91
96
  context ':inline_format => false (default)' do
92
97
  it 'should return a Prawn::Icon instance' do
93
- pdf = create_pdf
94
98
  icon = pdf.make_icon 'fa-arrows'
95
99
 
96
- expect(icon.class).to eq(Prawn::Icon)
100
+ expect(icon).to be_a(Prawn::Icon)
97
101
  end
98
102
  end
99
103
 
100
104
  context ':inline_format => true' do
101
105
  it 'should return a Prawn::::Text::Formatted::Box instance' do
102
- pdf = create_pdf
103
106
  icon = pdf.make_icon '<icon>fa-arrows</icon>', inline_format: true
104
107
 
105
- expect(icon.class).to eq(Prawn::Text::Formatted::Box)
108
+ expect(icon).to be_a(Prawn::Text::Formatted::Box)
106
109
  end
107
110
  end
108
111
  end
109
112
 
110
113
  describe '::inline_icon' do
111
114
  it 'should return a Prawn::Text::Formatted::Box instance' do
112
- pdf = create_pdf
113
115
  icon = pdf.inline_icon '<icon>fa-arrows</icon>'
114
116
 
115
- expect(icon.class).to eq(Prawn::Text::Formatted::Box)
117
+ expect(icon).to be_a(Prawn::Text::Formatted::Box)
116
118
  end
117
119
  end
118
120
 
119
121
  describe '::table_icon' do
120
122
  context 'inline_format: false (default)' do
121
123
  it 'should return a hash with font and content keys' do
122
- pdf = create_pdf
123
124
  icon = pdf.table_icon 'fa-arrows'
124
125
 
125
- expect(icon.class).to eq(Hash)
126
+ expect(icon).to be_a(Hash)
126
127
  expect(icon[:font]).to eq('fa')
127
128
  expect(icon[:content]).to eq("\uf047")
128
129
  end
@@ -130,32 +131,29 @@ describe Prawn::Icon::Interface do
130
131
 
131
132
  context 'inline_format: true' do
132
133
  it 'should convert <icon> to <font> tags' do
133
- pdf = create_pdf
134
134
  icon = pdf.table_icon '<icon>fa-user</icon>', inline_format: true
135
135
 
136
- expect(icon.class).to eq(Hash)
136
+ expect(icon).to be_a(Hash)
137
137
  expect(icon[:content]).to eq('<font name="fa"></font>')
138
138
  expect(icon[:inline_format]).to be true
139
139
  end
140
140
 
141
141
  it 'should ignore all other tags' do
142
- pdf = create_pdf
143
142
  a = ['<b>BOLD</b> <color rgb="0099FF">BLUE</color>', inline_format: true]
144
143
  icon = pdf.table_icon(*a)
145
144
 
146
- expect(icon.class).to eq(Hash)
145
+ expect(icon).to be_a(Hash)
147
146
  expect(icon[:content]).to eq(a[0])
148
147
  expect(icon[:inline_format]).to be true
149
148
  end
150
149
 
151
150
  context 'multiple icons' do
152
151
  it 'should ignore any text not in an icon tag' do
153
- pdf = create_pdf
154
152
  a = ['<icon>fa-user</icon> Some Text <icon>fi-laptop</icon>', inline_format: true]
155
153
  out = '<font name="fa"></font> Some Text <font name="fi"></font>'
156
154
  icon = pdf.table_icon(*a)
157
155
 
158
- expect(icon.class).to eq(Hash)
156
+ expect(icon).to be_a(Hash)
159
157
  expect(icon[:content]).to eq(out)
160
158
  expect(icon[:inline_format]).to be true
161
159
  end
@@ -165,9 +163,10 @@ describe Prawn::Icon::Interface do
165
163
  end
166
164
 
167
165
  describe Prawn::Icon do
166
+ let(:pdf) { create_pdf }
167
+
168
168
  context 'FontAwesome' do
169
169
  it 'should render FontAwesome glyphs' do
170
- pdf = create_pdf
171
170
  pdf.icon 'fa-user'
172
171
  text = PDF::Inspector::Text.analyze(pdf.render)
173
172
 
@@ -177,7 +176,6 @@ describe Prawn::Icon do
177
176
 
178
177
  context 'Foundation Icons' do
179
178
  it 'should render Foundation glyphs' do
180
- pdf = create_pdf
181
179
  pdf.icon 'fi-laptop'
182
180
  text = PDF::Inspector::Text.analyze(pdf.render)
183
181
 
@@ -187,7 +185,6 @@ describe Prawn::Icon do
187
185
 
188
186
  context 'GitHub Octicons' do
189
187
  it 'should render GitHub Octicon glyphs' do
190
- pdf = create_pdf
191
188
  pdf.icon 'octicon-logo-github'
192
189
  text = PDF::Inspector::Text.analyze(pdf.render)
193
190
 
@@ -197,7 +194,6 @@ describe Prawn::Icon do
197
194
 
198
195
  context 'PaymentFont' do
199
196
  it 'should render PaymentFont glyphs' do
200
- pdf = create_pdf
201
197
  pdf.icon 'pf-amazon'
202
198
  text = PDF::Inspector::Text.analyze(pdf.render)
203
199
 
@@ -14,4 +14,4 @@ module ParserHelper
14
14
  regex = Prawn::Icon::Parser::CONTENT_REGEX
15
15
  string.scan(regex).flatten
16
16
  end
17
- end
17
+ end
@@ -12,4 +12,4 @@ module PDFHelper
12
12
  def valid_unicode?(string)
13
13
  string.force_encoding('UTF-8').valid_encoding?
14
14
  end
15
- end
15
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright September 2016, Jesse Doyle. All rights reserved.
4
+ #
5
+ # This is free software. Please see the LICENSE and COPYING files for details.
6
+
7
+ describe Prawn::Icon::Base do
8
+ describe 'FONTDIR' do
9
+ it 'returns the data/fonts directory' do
10
+ path = File.expand_path '../../..', __FILE__
11
+ path = File.join path, 'data/fonts'
12
+ expect(Prawn::Icon::Base::FONTDIR).to eq(path)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright September 2016, Jesse Doyle. All rights reserved.
4
+ #
5
+ # This is free software. Please see the LICENSE and COPYING files for details.
6
+
7
+ describe Prawn::Icon::Errors::IconKeyEmpty do
8
+ let(:pdf) { create_pdf }
9
+
10
+ it 'is a StandardError' do
11
+ expect(subject).to be_a(StandardError)
12
+ end
13
+
14
+ it 'is thrown on a missing icon key' do
15
+ proc = Proc.new { pdf.icon '' }
16
+
17
+ expect(proc).to raise_error(described_class)
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright September 2016, Jesse Doyle. All rights reserved.
4
+ #
5
+ # This is free software. Please see the LICENSE and COPYING files for details.
6
+
7
+ describe Prawn::Icon::Errors::IconNotFound do
8
+ let(:pdf) { create_pdf }
9
+
10
+ it 'is a StandardError' do
11
+ expect(subject).to be_a(StandardError)
12
+ end
13
+
14
+ it 'is thrown on an invalid icon key' do
15
+ proc = Proc.new { pdf.icon 'fa-an invalid key' }
16
+
17
+ expect(proc).to raise_error(described_class)
18
+ end
19
+ end
@@ -7,44 +7,47 @@
7
7
  require 'spec_helper'
8
8
 
9
9
  describe Prawn::Icon::FontData do
10
+ let(:pdf) { create_pdf }
11
+ let(:fontawesome) { Prawn::Icon::FontData.new(pdf, set: :fa) }
12
+
13
+ before { Prawn::Icon::FontData.release_data }
14
+
10
15
  describe '#initialize' do
11
- it 'should update font_families on initialization' do
12
- pdf = create_pdf
13
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
16
+ before { Prawn::Icon::FontData.new(pdf, set: :fa) }
14
17
 
18
+ it 'should update font_families on initialization' do
15
19
  expect(pdf.font_families['fa']).not_to be_nil
16
20
  end
17
21
  end
18
22
 
19
23
  describe '::load' do
20
- it 'should only load a single object for multiple documents' do
21
- pdf = create_pdf
22
- data = Prawn::Icon::FontData.load(pdf, 'fa')
23
- obj_id_1 = data.__id__
24
- data = Prawn::Icon::FontData.load(pdf, 'fa')
25
- obj_id_2 = data.__id__
24
+ context 'specifier is a string' do
25
+ let(:data) { Prawn::Icon::FontData.load(pdf, 'fa') }
26
26
 
27
- expect(obj_id_1).to eq(obj_id_2)
28
- end
27
+ it 'should load the font' do
28
+ expect(data).not_to be_nil
29
+ end
29
30
 
30
- it 'should accept a string as a specifier' do
31
- pdf = create_pdf
32
- data = Prawn::Icon::FontData.load(pdf, 'fa')
31
+ it 'should only load a single object for multiple documents' do
32
+ obj_id_1 = data.object_id
33
+ second = Prawn::Icon::FontData.load(pdf, 'fa')
34
+ obj_id_2 = second.object_id
33
35
 
34
- expect(data).not_to be_nil
36
+ expect(obj_id_1).to eq(obj_id_2)
37
+ end
35
38
  end
36
39
 
37
- it 'should accept a symbol as a specifer' do
38
- pdf = create_pdf
39
- data = Prawn::Icon::FontData.load(pdf, :fa)
40
+ context 'specifier is a symbol' do
41
+ let(:data) { Prawn::Icon::FontData.load(pdf, :fa) }
40
42
 
41
- expect(data).not_to be_nil
43
+ it 'should load the font' do
44
+ expect(data).not_to be_nil
45
+ end
42
46
  end
43
47
  end
44
48
 
45
49
  describe '::release_data' do
46
50
  it 'should remove all data references if requested' do
47
- pdf = create_pdf
48
51
  Prawn::Icon::FontData.load(pdf, :fa)
49
52
  Prawn::Icon::FontData.load(pdf, :fi)
50
53
  Prawn::Icon::FontData.load(pdf, :octicon)
@@ -56,7 +59,6 @@ describe Prawn::Icon::FontData do
56
59
 
57
60
  describe '::unicode_from_key' do
58
61
  it 'should provide a UTF-8 string for a valid key' do
59
- pdf = create_pdf
60
62
  unicode = Prawn::Icon::FontData.unicode_from_key(pdf, 'fa-arrows')
61
63
  valid = unicode.force_encoding('UTF-8').valid_encoding?
62
64
 
@@ -73,13 +75,13 @@ describe Prawn::Icon::FontData do
73
75
  it 'should error when key is nil' do
74
76
  proc = Proc.new { Prawn::Icon::FontData.specifier_from_key nil }
75
77
 
76
- expect(proc).to raise_error(Prawn::Errors::IconKeyEmpty)
78
+ expect(proc).to raise_error(Prawn::Icon::Errors::IconKeyEmpty)
77
79
  end
78
80
 
79
81
  it 'should error when key is an empty string' do
80
82
  proc = Proc.new { Prawn::Icon::FontData.specifier_from_key '' }
81
83
 
82
- expect(proc).to raise_error(Prawn::Errors::IconKeyEmpty)
84
+ expect(proc).to raise_error(Prawn::Icon::Errors::IconKeyEmpty)
83
85
  end
84
86
 
85
87
  it 'should handle strings without any dashes properly' do
@@ -91,19 +93,15 @@ describe Prawn::Icon::FontData do
91
93
 
92
94
  describe '#font_version' do
93
95
  it 'should have a font version as a string' do
94
- pdf = create_pdf
95
- data = Prawn::Icon::FontData.new(pdf)
96
- version = data.font_version
96
+ version = fontawesome.font_version
97
97
 
98
- expect(version.is_a? String).to be true
98
+ expect(version).to be_a(String)
99
99
  end
100
100
  end
101
101
 
102
102
  describe '#legend_path' do
103
103
  it 'should have a valid path to a yml file for legend' do
104
- pdf = create_pdf
105
- data = Prawn::Icon::FontData.new(pdf)
106
- path = data.legend_path
104
+ path = fontawesome.legend_path
107
105
  extname = File.extname(path)
108
106
 
109
107
  expect(extname).to eq('.yml')
@@ -112,19 +110,15 @@ describe Prawn::Icon::FontData do
112
110
 
113
111
  describe '#load_fonts' do
114
112
  it 'should return a FontData object' do
115
- pdf = create_pdf
116
- data = Prawn::Icon::FontData.new(pdf)
117
- ret_val = data.load_fonts(pdf)
113
+ ret_val = fontawesome.load_fonts(pdf)
118
114
 
119
- expect(ret_val.is_a? Prawn::Icon::FontData).to be true
115
+ expect(ret_val).to be_a(Prawn::Icon::FontData)
120
116
  end
121
117
  end
122
118
 
123
119
  describe '#path' do
124
120
  it 'should have a valid path to a TTF file' do
125
- pdf = create_pdf
126
- data = Prawn::Icon::FontData.new(pdf)
127
- path = data.path
121
+ path = fontawesome.path
128
122
  extname = File.extname(path)
129
123
 
130
124
  expect(extname).to eq('.ttf')
@@ -133,9 +127,7 @@ describe Prawn::Icon::FontData do
133
127
 
134
128
  describe '#specifier' do
135
129
  it 'should retrieve the string specifier from the yaml legend file' do
136
- pdf = create_pdf
137
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
138
- specifier = data.specifier
130
+ specifier = fontawesome.specifier
139
131
 
140
132
  expect(specifier).to eq('fa')
141
133
  end
@@ -143,37 +135,29 @@ describe Prawn::Icon::FontData do
143
135
 
144
136
  describe '#unicode' do
145
137
  it 'should provide a valid UTF-8 encoded string for a valid key' do
146
- pdf = create_pdf
147
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
148
- unicode = data.unicode('arrows')
138
+ unicode = fontawesome.unicode('arrows')
149
139
  valid = unicode.force_encoding('UTF-8').valid_encoding?
150
140
 
151
141
  expect(valid).to be true
152
142
  end
153
143
 
154
144
  it 'should raise an error if unable to match a key' do
155
- pdf = create_pdf
156
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
157
- proc = Proc.new { data.unicode('an invalid sequence') }
145
+ proc = Proc.new { fontawesome.unicode('an invalid sequence') }
158
146
 
159
- expect(proc).to raise_error(Prawn::Errors::IconNotFound)
147
+ expect(proc).to raise_error(Prawn::Icon::Errors::IconNotFound)
160
148
  end
161
149
  end
162
150
 
163
151
  describe '#keys' do
164
152
  it 'should return a non-empty array of strings' do
165
- pdf = create_pdf
166
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
167
- keys = data.keys
153
+ keys = fontawesome.keys
168
154
 
169
155
  expect(keys).not_to be_empty
170
- expect(keys.first.is_a? String).to be true
156
+ expect(keys.first).to be_a(String)
171
157
  end
172
158
 
173
159
  it 'should not contain the version as a key' do
174
- pdf = create_pdf
175
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
176
- keys = data.keys
160
+ keys = fontawesome.keys
177
161
 
178
162
  expect(keys.include?('__font_version__')).to be false
179
163
  end
@@ -181,19 +165,17 @@ describe Prawn::Icon::FontData do
181
165
 
182
166
  describe '#yaml' do
183
167
  it 'should return a hash with the specifier as the first key' do
184
- pdf = create_pdf
185
- data = Prawn::Icon::FontData.new(pdf, set: :fa)
186
- yaml = data.yaml
168
+ yaml = fontawesome.yaml
187
169
  key = yaml.keys.first
188
170
  mapping = yaml['fa']
189
171
  inner_key = mapping.keys.last
190
172
  inner_value = mapping.values.last
191
173
  proc = Proc.new { inner_value.force_encoding('UTF-8').valid_encoding? }
192
174
 
193
- expect(yaml.is_a? Hash).to be true
175
+ expect(yaml).to be_a(Hash)
194
176
  expect(key).to eq('fa')
195
- expect(inner_key.is_a? String).to be true
196
- expect(inner_value.is_a? String).to be true
177
+ expect(inner_key).to be_a(String)
178
+ expect(inner_value).to be_a(String)
197
179
  expect(proc.call).to be true
198
180
  end
199
181
  end