Sha256: 32c1a06e1f85a06908bde827373557a88df48bf980069f4006aed85456e9085b

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# coding: utf-8
require 'spec_helper'

class TitledReport < Rescpos::Report
  attr_reader :title

  def initialize(title = "")
    @title = title
  end
end

module Rescpos
  describe Printer do
    before(:each) do
      TCPSocket.should_receive(:open).with("192.168.1.3", 9100).and_return(socket)
      socket.should_receive(:send).with("\x1b\x40", Socket::MSG_OOB)
    end

    let(:socket) { Object.new }

    it "connects to the printer server" do
      Printer.open("192.168.1.3", 9100)
    end

    it "prints the a rendered report" do
      printer = Printer.open("192.168.1.3", 9100)

      socket.should_receive(:send).with("A title", Socket::MSG_OOB)
      printer.should_receive(:cut)
      printer.print(TitledReport.new("A title").render(:template => "<%= @title %>"))
    end

    it "prints the report" do
      Rescpos.configure do |config|
        config.template_path = File.join(File.dirname(__FILE__), "../../reports")
      end
      printer = Printer.open("192.168.1.3", 9100)

      socket.should_receive(:send).with("A title\n", Socket::MSG_OOB)
      printer.should_receive(:cut)
      printer.print_report(TitledReport.new("A title"))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rescpos-0.0.7 spec/lib/rescpos/printer_spec.rb
rescpos-0.0.6 spec/lib/rescpos/printer_spec.rb
rescpos-0.0.5 spec/lib/rescpos/printer_spec.rb
rescpos-0.0.3 spec/lib/rescpos/printer_spec.rb
rescpos-0.0.2 spec/lib/rescpos/printer_spec.rb
rescpos-0.0.1 spec/lib/rescpos/printer_spec.rb