zebra-zpl 1.0.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +71 -0
- data/CONTRIBUTING.md +49 -0
- data/Gemfile +6 -0
- data/README.md +348 -89
- data/docs/example.rb +290 -0
- data/docs/images/barcode.png +0 -0
- data/docs/images/datamatrix.png +0 -0
- data/docs/images/earth.jpg +0 -0
- data/docs/images/graphics.png +0 -0
- data/docs/images/image.png +0 -0
- data/docs/images/image_inverted.png +0 -0
- data/docs/images/image_manipulation.png +0 -0
- data/docs/images/images.png +0 -0
- data/docs/images/justification.png +0 -0
- data/docs/images/qrcode.png +0 -0
- data/docs/images/rotation.png +0 -0
- data/docs/images/text.png +0 -0
- data/lib/zebra/print_job.rb +19 -17
- data/lib/zebra/zpl.rb +26 -18
- data/lib/zebra/zpl/barcode.rb +29 -12
- data/lib/zebra/zpl/barcode_type.rb +4 -1
- data/lib/zebra/zpl/box.rb +16 -4
- data/lib/zebra/zpl/comment.rb +15 -0
- data/lib/zebra/zpl/datamatrix.rb +76 -0
- data/lib/zebra/zpl/font.rb +1 -1
- data/lib/zebra/zpl/graphic.rb +91 -0
- data/lib/zebra/zpl/image.rb +97 -0
- data/lib/zebra/zpl/label.rb +3 -14
- data/lib/zebra/zpl/pdf417.rb +50 -0
- data/lib/zebra/zpl/qrcode.rb +6 -2
- data/lib/zebra/zpl/raw.rb +25 -0
- data/lib/zebra/zpl/text.rb +44 -20
- data/lib/zebra/zpl/version.rb +1 -1
- data/spec/fixtures/default.jpg +0 -0
- data/spec/spec_helper.rb +6 -2
- data/spec/zebra/print_job_spec.rb +13 -18
- data/spec/zebra/zpl/barcode_spec.rb +70 -63
- data/spec/zebra/zpl/box_spec.rb +27 -31
- data/spec/zebra/zpl/character_set_spec.rb +7 -7
- data/spec/zebra/zpl/comment_spec.rb +18 -0
- data/spec/zebra/zpl/datamatrix_spec.rb +124 -0
- data/spec/zebra/zpl/graphics_spec.rb +227 -0
- data/spec/zebra/zpl/image_spec.rb +146 -0
- data/spec/zebra/zpl/label_spec.rb +41 -53
- data/spec/zebra/zpl/pdf417_spec.rb +108 -0
- data/spec/zebra/zpl/qrcode_spec.rb +92 -92
- data/spec/zebra/zpl/text_spec.rb +60 -55
- data/zebra-zpl.gemspec +12 -12
- metadata +63 -27
@@ -0,0 +1,25 @@
|
|
1
|
+
require "zebra/zpl/printable"
|
2
|
+
|
3
|
+
module Zebra
|
4
|
+
module Zpl
|
5
|
+
class Raw
|
6
|
+
include Printable
|
7
|
+
|
8
|
+
attr_reader :width
|
9
|
+
|
10
|
+
def width=(width)
|
11
|
+
unless margin.nil? || margin < 1
|
12
|
+
@width = (width - (margin * 2))
|
13
|
+
else
|
14
|
+
@width = width || 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_zpl
|
19
|
+
# check_attributes
|
20
|
+
"^FW#{rotation}^FO#{x},#{y}#{data}^FS"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/zebra/zpl/text.rb
CHANGED
@@ -5,13 +5,19 @@ module Zebra
|
|
5
5
|
class Text
|
6
6
|
include Printable
|
7
7
|
|
8
|
-
|
8
|
+
class InvalidMaxLinesError < StandardError; end
|
9
|
+
|
10
|
+
attr_reader :font_size, :font_type, :width, :line_spacing, :hanging_indent, :bold
|
9
11
|
|
10
12
|
def font_size=(f)
|
11
13
|
FontSize.validate_font_size f
|
12
14
|
@font_size = f
|
13
15
|
end
|
14
16
|
|
17
|
+
def bold=(value)
|
18
|
+
@bold = value
|
19
|
+
end
|
20
|
+
|
15
21
|
def width=(width)
|
16
22
|
unless (margin.nil? || margin < 1)
|
17
23
|
@width = (width - (margin*2))
|
@@ -20,6 +26,19 @@ module Zebra
|
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
29
|
+
def max_lines=(value)
|
30
|
+
raise InvalidMaxLinesError unless value.to_i >= 1
|
31
|
+
@max_lines = value
|
32
|
+
end
|
33
|
+
|
34
|
+
def line_spacing=(value)
|
35
|
+
@line_spacing = value || 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def hanging_indent=(value)
|
39
|
+
@hanging_indent = value || 0
|
40
|
+
end
|
41
|
+
|
23
42
|
def font_type=(type)
|
24
43
|
FontType.validate_font_type type
|
25
44
|
@font_type = type
|
@@ -38,35 +57,40 @@ module Zebra
|
|
38
57
|
@print_mode || PrintMode::NORMAL
|
39
58
|
end
|
40
59
|
|
41
|
-
def h_multiplier
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
def v_multiplier
|
46
|
-
|
47
|
-
end
|
60
|
+
# def h_multiplier
|
61
|
+
# @h_multiplier || HorizontalMultiplier::VALUE_1
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# def v_multiplier
|
65
|
+
# @v_multiplier || VerticalMultiplier::VALUE_1
|
66
|
+
# end
|
48
67
|
|
49
68
|
def print_mode
|
50
69
|
@print_mode || PrintMode::NORMAL
|
51
70
|
end
|
52
71
|
|
53
|
-
def
|
54
|
-
|
55
|
-
@h_multiplier = multiplier
|
72
|
+
def max_lines
|
73
|
+
@max_lines || 4
|
56
74
|
end
|
57
75
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
end
|
76
|
+
# def h_multiplier=(multiplier)
|
77
|
+
# HorizontalMultiplier.validate_multiplier multiplier
|
78
|
+
# @h_multiplier = multiplier
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# def v_multiplier=(multiplier)
|
82
|
+
# VerticalMultiplier.validate_multiplier multiplier
|
83
|
+
# @v_multiplier = multiplier
|
84
|
+
# end
|
62
85
|
|
63
86
|
def to_zpl
|
64
87
|
check_attributes
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
88
|
+
if !bold.nil?
|
89
|
+
"^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x+2},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS" +
|
90
|
+
"^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y+2}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS"
|
91
|
+
else
|
92
|
+
"^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS"
|
93
|
+
end
|
70
94
|
end
|
71
95
|
|
72
96
|
private
|
data/lib/zebra/zpl/version.rb
CHANGED
Binary file
|
data/spec/spec_helper.rb
CHANGED
@@ -6,9 +6,13 @@
|
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
7
|
|
8
8
|
require "zebra/zpl"
|
9
|
+
require 'byebug'
|
10
|
+
require 'pry'
|
11
|
+
require 'pry-nav'
|
12
|
+
|
13
|
+
ENV['RUBY_ENV'] = 'test'
|
9
14
|
|
10
15
|
RSpec.configure do |config|
|
11
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
16
|
config.run_all_when_everything_filtered = true
|
13
17
|
config.filter_run :focus
|
14
18
|
|
@@ -16,5 +20,5 @@ RSpec.configure do |config|
|
|
16
20
|
# order dependency and want to debug it, you can fix the order by providing
|
17
21
|
# the seed, which is printed after each run.
|
18
22
|
# --seed 1234
|
19
|
-
config.order = 'random'
|
23
|
+
# config.order = 'random'
|
20
24
|
end
|
@@ -1,36 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Zebra::PrintJob do
|
4
|
-
before do
|
5
|
-
Cups.stub(:show_destinations).and_return(["Zebra", "Foobar"])
|
6
|
-
end
|
7
|
-
|
8
4
|
it "receives the name of a printer" do
|
9
|
-
described_class.new("Zebra").printer.
|
10
|
-
end
|
11
|
-
|
12
|
-
it "raises an error if the printer does not exists" do
|
13
|
-
expect {
|
14
|
-
described_class.new("Wrong")
|
15
|
-
}.to raise_error(Zebra::PrintJob::UnknownPrinter)
|
5
|
+
expect(described_class.new("Zebra").printer).to eq 'Zebra'
|
16
6
|
end
|
17
7
|
|
18
8
|
describe "#print" do
|
19
|
-
let(:label) {
|
20
|
-
let(:
|
21
|
-
let(:
|
9
|
+
let(:label) { Zebra::Zpl::Label.new(print_speed: 2) }
|
10
|
+
let(:zpl_string) { '^XA^FO50,50^FDHello, Zebra^FS^XZ' }
|
11
|
+
let(:ip) { '127.0.0.1' }
|
22
12
|
|
23
13
|
subject(:print_job) { described_class.new "Zebra" }
|
24
14
|
|
25
|
-
before { print_job.
|
15
|
+
before { allow(print_job).to receive(:`) { true } }
|
26
16
|
|
27
17
|
it "creates a cups print job with the correct arguments" do
|
28
|
-
print_job.print label
|
18
|
+
print_job.print label, ip
|
29
19
|
end
|
30
20
|
|
31
21
|
it "prints the label" do
|
32
|
-
print_job.
|
33
|
-
print_job.print label
|
22
|
+
expect(print_job).to receive(:system).with(/r?lpr? -(h|H) 127.0.0.1 -(d|P) Zebra.*/).at_least(:once)
|
23
|
+
print_job.print label, ip
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can print from a ZPL string" do
|
27
|
+
expect(print_job).to receive(:system).with(/r?lpr? -(h|H) 127.0.0.1 -(d|P) Zebra.*/).at_least(:once)
|
28
|
+
print_job.print zpl_string, ip
|
34
29
|
end
|
35
30
|
end
|
36
31
|
end
|
@@ -2,48 +2,58 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Zebra::Zpl::Barcode do
|
4
4
|
it "can be initialized with the position of the text to be printed" do
|
5
|
-
barcode = described_class.new :
|
6
|
-
barcode.position.
|
7
|
-
barcode.x.
|
8
|
-
barcode.y.
|
5
|
+
barcode = described_class.new position: [20, 40]
|
6
|
+
expect(barcode.position).to eq [20,40]
|
7
|
+
expect(barcode.x).to eq 20
|
8
|
+
expect(barcode.y).to eq 40
|
9
9
|
end
|
10
10
|
|
11
11
|
it "can be initialized with the barcode rotation" do
|
12
12
|
rotation = Zebra::Zpl::Rotation::DEGREES_90
|
13
|
-
barcode = described_class.new :
|
14
|
-
barcode.rotation.
|
13
|
+
barcode = described_class.new rotation: rotation
|
14
|
+
expect(barcode.rotation).to eq rotation
|
15
15
|
end
|
16
16
|
|
17
17
|
it "can be initialized with the barcode rotation" do
|
18
18
|
rotation = Zebra::Zpl::Rotation::DEGREES_90
|
19
|
-
barcode = described_class.new :
|
20
|
-
barcode.rotation.
|
19
|
+
barcode = described_class.new rotation: rotation
|
20
|
+
expect(barcode.rotation).to eq rotation
|
21
21
|
end
|
22
22
|
|
23
23
|
it "can be initialized with the barcode type" do
|
24
|
-
type = Zebra::Zpl::BarcodeType::
|
25
|
-
barcode = described_class.new :
|
26
|
-
barcode.type.
|
24
|
+
type = Zebra::Zpl::BarcodeType::CODE_128_AUTO
|
25
|
+
barcode = described_class.new type: type
|
26
|
+
expect(barcode.type).to eq type
|
27
27
|
end
|
28
28
|
|
29
|
-
it "can be initialized with the
|
30
|
-
barcode = described_class.new :
|
31
|
-
barcode.
|
29
|
+
it "can be initialized with the barcode width" do
|
30
|
+
barcode = described_class.new width: 5
|
31
|
+
expect(barcode.width).to eq 5
|
32
32
|
end
|
33
33
|
|
34
|
-
it "can be initialized with the
|
35
|
-
barcode = described_class.new :
|
36
|
-
barcode.
|
34
|
+
it "can be initialized with the barcode height" do
|
35
|
+
barcode = described_class.new height: 20
|
36
|
+
expect(barcode.height).to eq 20
|
37
37
|
end
|
38
38
|
|
39
|
-
it "can be initialized with the
|
40
|
-
barcode = described_class.new :
|
41
|
-
barcode.
|
39
|
+
it "can be initialized with the ratio" do
|
40
|
+
barcode = described_class.new ratio: 3.0
|
41
|
+
expect(barcode.ratio).to eq 3.0
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can be initialized with the narrow bar width" do
|
45
|
+
barcode = described_class.new narrow_bar_width: 3
|
46
|
+
expect(barcode.narrow_bar_width).to eq 3
|
47
|
+
end
|
48
|
+
|
49
|
+
it "can be initialized with the wide bar width" do
|
50
|
+
barcode = described_class.new wide_bar_width: 10
|
51
|
+
expect(barcode.wide_bar_width).to eq 10
|
42
52
|
end
|
43
53
|
|
44
54
|
it "can be initialized informing if the human readable code should be printed" do
|
45
|
-
barcode = described_class.new :
|
46
|
-
barcode.print_human_readable_code.
|
55
|
+
barcode = described_class.new print_human_readable_code: true
|
56
|
+
expect(barcode.print_human_readable_code).to eq true
|
47
57
|
end
|
48
58
|
|
49
59
|
describe "#rotation=" do
|
@@ -65,7 +75,7 @@ describe Zebra::Zpl::Barcode do
|
|
65
75
|
describe "#narrow_bar_width=" do
|
66
76
|
it "raises an error if the type is Code 128 and the width is invalid" do
|
67
77
|
expect {
|
68
|
-
described_class.new :
|
78
|
+
described_class.new type: Zebra::Zpl::BarcodeType::CODE_128_AUTO, narrow_bar_width: 20
|
69
79
|
}.to raise_error(Zebra::Zpl::Barcode::InvalidNarrowBarWidthError)
|
70
80
|
end
|
71
81
|
end
|
@@ -73,45 +83,46 @@ describe Zebra::Zpl::Barcode do
|
|
73
83
|
describe "#wide_bar_width=" do
|
74
84
|
it "raises an error if the type is Code 128 and the width is invalid" do
|
75
85
|
expect {
|
76
|
-
described_class.new :
|
86
|
+
described_class.new type: Zebra::Zpl::BarcodeType::CODE_128_AUTO, wide_bar_width: 40
|
77
87
|
}.to raise_error(Zebra::Zpl::Barcode::InvalidWideBarWidthError)
|
78
88
|
end
|
79
89
|
end
|
80
90
|
|
81
91
|
describe "#print_human_readable_code" do
|
82
92
|
it "defaults to false" do
|
83
|
-
described_class.new.print_human_readable_code.
|
93
|
+
expect(described_class.new.print_human_readable_code).to eq false
|
84
94
|
end
|
85
95
|
end
|
86
96
|
|
87
97
|
describe "#to_zpl" do
|
88
98
|
let(:valid_attributes) { {
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
99
|
+
position: [100, 150],
|
100
|
+
type: Zebra::Zpl::BarcodeType::CODE_128_AUTO,
|
101
|
+
height: 20,
|
102
|
+
width: 5,
|
103
|
+
narrow_bar_width: 3,
|
104
|
+
wide_bar_width: 6,
|
105
|
+
data: "foobar"
|
95
106
|
} }
|
96
107
|
let(:barcode) { described_class.new valid_attributes }
|
97
|
-
let(:tokens) { barcode.to_zpl.split(
|
108
|
+
let(:tokens) { barcode.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
|
98
109
|
|
99
110
|
it "raises an error if the X position was not informed" do
|
100
|
-
barcode = described_class.new :
|
111
|
+
barcode = described_class.new position: [nil, 100], data: "foobar"
|
101
112
|
expect {
|
102
113
|
barcode.to_zpl
|
103
114
|
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
|
104
115
|
end
|
105
116
|
|
106
117
|
it "raises an error if the Y position was not informed" do
|
107
|
-
barcode = described_class.new :
|
118
|
+
barcode = described_class.new position: [100, nil]
|
108
119
|
expect {
|
109
120
|
barcode.to_zpl
|
110
121
|
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
|
111
122
|
end
|
112
123
|
|
113
124
|
it "raises an error if the barcode type is not informed" do
|
114
|
-
barcode = described_class.new :
|
125
|
+
barcode = described_class.new position: [100, 100], data: "foobar"
|
115
126
|
expect {
|
116
127
|
barcode.to_zpl
|
117
128
|
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the barcode type to be used is not given")
|
@@ -131,66 +142,62 @@ describe Zebra::Zpl::Barcode do
|
|
131
142
|
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the height to be used is not given")
|
132
143
|
end
|
133
144
|
|
134
|
-
it "raises an error if the
|
145
|
+
it "raises an error if the neither of with, narrow_bar_width, or wide_bar_width are not given" do
|
146
|
+
valid_attributes.delete :width
|
135
147
|
valid_attributes.delete :narrow_bar_width
|
136
|
-
|
137
|
-
expect {
|
138
|
-
barcode.to_zpl
|
139
|
-
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the narrow bar width to be used is not given")
|
140
|
-
end
|
141
|
-
|
142
|
-
it "raises an error if the wide bar width is not given" do
|
143
148
|
valid_attributes.delete :wide_bar_width
|
144
|
-
|
145
149
|
expect {
|
146
150
|
barcode.to_zpl
|
147
|
-
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the
|
151
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the width to be used is not given")
|
148
152
|
end
|
149
153
|
|
150
154
|
it "begins with the command 'B'" do
|
151
|
-
|
155
|
+
expect(tokens[4]).to eq '^BY'
|
152
156
|
end
|
153
157
|
|
154
158
|
it "contains the X position" do
|
155
|
-
tokens[
|
159
|
+
expect(tokens[2]).to eq '100'
|
156
160
|
end
|
157
161
|
|
158
162
|
it "contains the Y position" do
|
159
|
-
tokens[
|
163
|
+
expect(tokens[3]).to eq '150'
|
160
164
|
end
|
161
165
|
|
162
|
-
it "contains the
|
163
|
-
tokens[
|
166
|
+
it "contains the width" do
|
167
|
+
expect(tokens[5]).to eq '5'
|
164
168
|
end
|
165
169
|
|
166
|
-
it "contains the
|
167
|
-
tokens[
|
170
|
+
it "contains the ratio" do
|
171
|
+
expect(tokens[6]).to eq '2.0'
|
168
172
|
end
|
169
173
|
|
170
|
-
it "contains the barcode
|
171
|
-
tokens[
|
174
|
+
it "contains the barcode height" do
|
175
|
+
expect(tokens[7]).to eq '20'
|
172
176
|
end
|
173
177
|
|
174
|
-
it "contains the barcode
|
175
|
-
tokens[
|
178
|
+
it "contains the barcode type" do
|
179
|
+
expect(tokens[8]).to start_with "^B#{Zebra::Zpl::BarcodeType::CODE_128_AUTO}"
|
176
180
|
end
|
177
181
|
|
178
|
-
it "contains the barcode
|
179
|
-
tokens[
|
182
|
+
it "contains the barcode rotation" do
|
183
|
+
expect(tokens[0]).to start_with '^FW'
|
184
|
+
expect(tokens[0]).to end_with Zebra::Zpl::Rotation::NO_ROTATION.to_s
|
185
|
+
expect(tokens[8]).to start_with '^B'
|
186
|
+
expect(tokens[8]).to end_with Zebra::Zpl::Rotation::NO_ROTATION.to_s
|
180
187
|
end
|
181
188
|
|
182
189
|
it "contains the correct indication when the human readable code should be printed" do
|
183
|
-
valid_attributes.merge! :
|
184
|
-
tokens[
|
190
|
+
valid_attributes.merge! print_human_readable_code: true
|
191
|
+
expect(tokens[9]).to eq 'Y'
|
185
192
|
end
|
186
193
|
|
187
194
|
it "contains the correct indication when the human readable code should not be printed" do
|
188
|
-
valid_attributes.merge! :
|
189
|
-
tokens[
|
195
|
+
valid_attributes.merge! print_human_readable_code: false
|
196
|
+
expect(tokens[9]).to eq 'N'
|
190
197
|
end
|
191
198
|
|
192
199
|
it "contains the data to be printed in the barcode" do
|
193
|
-
tokens[
|
200
|
+
expect(tokens[11]).to eq 'foobar'
|
194
201
|
end
|
195
202
|
end
|
196
203
|
end
|
data/spec/zebra/zpl/box_spec.rb
CHANGED
@@ -3,69 +3,65 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Zebra::Zpl::Box do
|
5
5
|
it "can be initialized with initial position" do
|
6
|
-
box = described_class.new :
|
7
|
-
box.position.
|
8
|
-
box.x.
|
9
|
-
box.y.
|
10
|
-
end
|
11
|
-
|
12
|
-
it "can be initialized with the end position" do
|
13
|
-
box = described_class.new :end_position => [20, 40]
|
14
|
-
box.end_position.should == [20, 40]
|
15
|
-
box.end_x.should == 20
|
16
|
-
box.end_y.should == 40
|
6
|
+
box = described_class.new position: [20, 40]
|
7
|
+
expect(box.position).to eq [20, 40]
|
8
|
+
expect(box.x).to eq 20
|
9
|
+
expect(box.y).to eq 40
|
17
10
|
end
|
18
11
|
|
19
12
|
it "can be initialized with the line thckness " do
|
20
|
-
box = described_class.new :
|
21
|
-
box.line_thickness.
|
13
|
+
box = described_class.new line_thickness: 3
|
14
|
+
expect(box.line_thickness).to eq 3
|
22
15
|
end
|
23
16
|
|
24
17
|
describe "#to_zpl" do
|
25
|
-
subject(:box)
|
26
|
-
let(:attributes) {
|
18
|
+
subject(:box) { described_class.new attributes }
|
19
|
+
let(:attributes) {{
|
20
|
+
position: [20,40],
|
21
|
+
line_thickness: 3,
|
22
|
+
box_width: 5,
|
23
|
+
box_height: 4,
|
24
|
+
color: 'B',
|
25
|
+
rounding_degree: 6
|
26
|
+
}}
|
27
27
|
|
28
28
|
it "raises an error if the X position was not informed" do
|
29
|
-
box = described_class.new attributes.merge :
|
29
|
+
box = described_class.new attributes.merge position: [nil, 40]
|
30
30
|
expect {
|
31
31
|
box.to_zpl
|
32
32
|
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "raises an error if the Y position was not informed" do
|
36
|
-
box = described_class.new attributes.merge :
|
36
|
+
box = described_class.new attributes.merge position: [20, nil]
|
37
37
|
expect {
|
38
38
|
box.to_zpl
|
39
39
|
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
|
40
40
|
end
|
41
41
|
|
42
|
-
it "raises an error if the
|
43
|
-
box = described_class.new attributes.merge :
|
42
|
+
it "raises an error if the line thickness was not informed" do
|
43
|
+
box = described_class.new attributes.merge line_thickness: nil
|
44
44
|
expect {
|
45
45
|
box.to_zpl
|
46
|
-
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the
|
46
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the line thickness is not given")
|
47
47
|
end
|
48
48
|
|
49
|
-
it "raises an error if the
|
50
|
-
box = described_class.new attributes.merge :
|
49
|
+
it "raises an error if the box width was not informed" do
|
50
|
+
box = described_class.new attributes.merge box_width: nil
|
51
51
|
expect {
|
52
52
|
box.to_zpl
|
53
|
-
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the
|
53
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the box_width is not given")
|
54
54
|
end
|
55
55
|
|
56
|
-
it "raises an error if the
|
57
|
-
box = described_class.new attributes.merge :
|
56
|
+
it "raises an error if the box height was not informed" do
|
57
|
+
box = described_class.new attributes.merge box_height: nil
|
58
58
|
expect {
|
59
59
|
box.to_zpl
|
60
|
-
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the
|
61
|
-
end
|
62
|
-
|
63
|
-
it "begins with the 'X' command" do
|
64
|
-
box.to_zpl.should =~ /\AX/
|
60
|
+
}.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the box_height is not given")
|
65
61
|
end
|
66
62
|
|
67
63
|
it "contains the attributes in correct order" do
|
68
|
-
box.to_zpl.
|
64
|
+
expect(box.to_zpl).to eq '^FO20,40^GB5,4,3,B,6^FS'
|
69
65
|
end
|
70
66
|
end
|
71
67
|
end
|