|
25 | 25 | RQRCode::QRCode.new("png").as_png |
26 | 26 | end |
27 | 27 |
|
| 28 | + context "with various color inputs" do |
| 29 | + before :each do |
| 30 | + allow(ChunkyPNG).to receive(:Color).and_call_original |
| 31 | + expect(mockImage).to receive(:save) |
| 32 | + .once |
| 33 | + .with("some/path", {bit_depth: 1, color_mode: 0}) |
| 34 | + end |
| 35 | + |
| 36 | + it "should handle the defaults" do |
| 37 | + expect(ChunkyPNG::Image).to receive(:new) |
| 38 | + .once |
| 39 | + .with(174, 174, 4294967295) |
| 40 | + .and_return(mockImage) |
| 41 | + |
| 42 | + RQRCode::QRCode.new("png").as_png( |
| 43 | + file: "some/path" |
| 44 | + ) |
| 45 | + |
| 46 | + expect(ChunkyPNG).to have_received(:Color).with("black").once |
| 47 | + expect(ChunkyPNG).to have_received(:Color).with("white").once |
| 48 | + end |
| 49 | + |
| 50 | + it "should handle a blue 'color'" do |
| 51 | + expect(ChunkyPNG::Image).to receive(:new) |
| 52 | + .once |
| 53 | + .with(174, 174, 4294967295) |
| 54 | + .and_return(mockImage) |
| 55 | + |
| 56 | + RQRCode::QRCode.new("png").as_png( |
| 57 | + file: "some/path", |
| 58 | + color: "blue" |
| 59 | + ) |
| 60 | + |
| 61 | + expect(ChunkyPNG).to have_received(:Color).with("blue").once |
| 62 | + expect(ChunkyPNG).to have_received(:Color).with("white").once |
| 63 | + end |
| 64 | + |
| 65 | + it "should handle a #FC0000 'color'" do |
| 66 | + expect(ChunkyPNG::Image).to receive(:new) |
| 67 | + .once |
| 68 | + .with(174, 174, 4294967295) |
| 69 | + .and_return(mockImage) |
| 70 | + |
| 71 | + RQRCode::QRCode.new("png").as_png( |
| 72 | + file: "some/path", |
| 73 | + color: "#FC0000" |
| 74 | + ) |
| 75 | + |
| 76 | + expect(ChunkyPNG).to have_received(:Color).with("#FC0000").once |
| 77 | + expect(ChunkyPNG).to have_received(:Color).with("white").once |
| 78 | + end |
| 79 | + |
| 80 | + it "should handle an rgb 'color'" do |
| 81 | + expect(ChunkyPNG::Image).to receive(:new) |
| 82 | + .once |
| 83 | + .with(174, 174, 4294967295) |
| 84 | + .and_return(mockImage) |
| 85 | + |
| 86 | + RQRCode::QRCode.new("png").as_png( |
| 87 | + file: "some/path", |
| 88 | + color: [0, 0, 0] |
| 89 | + ) |
| 90 | + |
| 91 | + expect(ChunkyPNG).to have_received(:Color).with(0, 0, 0).once |
| 92 | + expect(ChunkyPNG).to have_received(:Color).with("white").once |
| 93 | + end |
| 94 | + |
| 95 | + it "should handle a green 'fill'" do |
| 96 | + expect(ChunkyPNG::Image).to receive(:new) |
| 97 | + .once |
| 98 | + .with(174, 174, 8388863) |
| 99 | + .and_return(mockImage) |
| 100 | + |
| 101 | + RQRCode::QRCode.new("png").as_png( |
| 102 | + file: "some/path", |
| 103 | + fill: "green" |
| 104 | + ) |
| 105 | + |
| 106 | + expect(ChunkyPNG).to have_received(:Color).with("black").once |
| 107 | + expect(ChunkyPNG).to have_received(:Color).with("green").once |
| 108 | + end |
| 109 | + |
| 110 | + it "should handle an rgb 'fill'" do |
| 111 | + expect(ChunkyPNG::Image).to receive(:new) |
| 112 | + .once |
| 113 | + .with(174, 174, 4294967295) |
| 114 | + .and_return(mockImage) |
| 115 | + |
| 116 | + RQRCode::QRCode.new("png").as_png( |
| 117 | + file: "some/path", |
| 118 | + fill: [255, 255, 255] |
| 119 | + ) |
| 120 | + |
| 121 | + expect(ChunkyPNG).to have_received(:Color).with("black").once |
| 122 | + expect(ChunkyPNG).to have_received(:Color).with(255, 255, 255).once |
| 123 | + end |
| 124 | + end |
| 125 | + |
| 126 | + it "should not handle nonsense color " do |
| 127 | + expect { |
| 128 | + RQRCode::QRCode.new("png").as_png( |
| 129 | + file: "some/path", |
| 130 | + color: "madeupcolor" |
| 131 | + ) |
| 132 | + }.to raise_error(ArgumentError, "Unknown color name madeupcolor!") |
| 133 | + end |
| 134 | + |
| 135 | + it "should not handle nonsense fill " do |
| 136 | + expect { |
| 137 | + RQRCode::QRCode.new("png").as_png( |
| 138 | + file: "some/path", |
| 139 | + fill: "madeupcolor" |
| 140 | + ) |
| 141 | + }.to raise_error(ArgumentError, "Unknown color name madeupcolor!") |
| 142 | + end |
| 143 | + |
28 | 144 | context "with file save and constaints" do |
29 | 145 | it "should export using the correct defaults" do |
30 | 146 | expect(ChunkyPNG::Image).to receive(:new) |
|
0 commit comments