1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
require "spec_helper"
require "rqrcode/data"
describe "RQRCode" do
it "must provide a custom to_s" do
qr = RQRCode::QRCode.new("http://kyan.com", size: 3)
expect(qr.to_s[0..50]).to eq("xxxxxxx x x xxx xxxxxxx\nx x xxxxx x x ")
expect(qr.to_s(dark: "q", light: "n")[0..36]).to eq("qqqqqqqnnnqnqnnqqqnnnnqqqqqqq\nqnnnnnq")
expect(qr.to_s(dark: "@")[0..21]).to eq("@@@@@@@ @ @ @@@ ")
end
it "must expose the core qrcode" do
expect(RQRCode::QRCode.new("svg").qrcode).to be_instance_of(RQRCodeCore::QRCode)
end
it "should do a basic render" do
qr = RQRCode::QRCode.new("http://kyan.com")
str = ""
qr.qrcode.modules.each do |row|
row.each do |col|
str << (col ? "X" : "O")
end
str << "\n"
end
expect(str).to eq(AS_BASIC)
end
it 'should do a basic render using old "modules" interface' do
qr = RQRCode::QRCode.new("http://kyan.com")
str = ""
qr.modules.each do |row|
row.each do |col|
str << (col ? "X" : "O")
end
str << "\n"
end
expect(str).to eq(AS_BASIC)
end
it "should pass options to rqrcode_core" do
options = {
size: 5,
mode: :alphanumeric
}
qr = RQRCode::QRCode.new("QRCODE", options)
expect(qr.qrcode.mode).to eq(:mode_alpha_numk)
expect(qr.qrcode.version).to eq(options[:size])
end
end
|