Sha256: e8a9b719ee4114684376a2c68243a6e086023247a7afc2312be1c682533d8c17

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 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", 0)
    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", 0)
      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", 0)
      printer.should_receive(:cut)
      printer.print_report(TitledReport.new("A title"))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rescpos-0.0.8 spec/lib/rescpos/printer_spec.rb