Sha256: 951d0e27e1f8bacf5149951b0f5fd7f2beecbf3f5b81d54edd3fbd7425468684

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

require File.expand_path( File.dirname(__FILE__) + '/test_helper')
require 'zxing'

class ZXingTest < MiniTest::Test
  context "A QR decoder singleton" do

    class Foo < Struct.new(:v); def to_s; self.v; end; end

    setup do
      @decoder = ZXing
      @uri = "http://2d-code.co.uk/images/bbc-logo-in-qr-code.gif"
      @path = File.expand_path( File.dirname(__FILE__) + '/qrcode.png')
      @file = File.new(@path)
      @google_logo = "http://www.google.com/logos/grandparentsday10.gif"
      @uri_result = "http://bbc.co.uk/programmes"
      @path_result = "http://rubyflow.com"
    end

    should "decode a URL" do
      assert_equal @decoder.decode(@uri), @uri_result
    end

    should "decode a file path" do
      assert_equal @decoder.decode(@path), @path_result
    end

    should "return nil if #decode fails" do
      assert_nil @decoder.decode(@google_logo)
    end

    should "raise an exception if #decode! fails" do
      assert_raises(ZXing::ReaderException,
                    ZXing::NotFoundException) { @decoder.decode!(@google_logo) }
    end

    should "decode objects that respond to #path" do
      assert_equal @decoder.decode(@file), @path_result
    end

    should "call #to_s to argument passed in as a last resort" do
      assert_equal @decoder.decode(Foo.new(@path)), @path_result
    end
  end

  context "A QR decoder module" do
    
    setup do
      class SpyRing; include ZXing end
      @ring = SpyRing.new
    end

    should "include #decode and #decode! into classes" do
      assert @ring.method(:decode)
      assert @ring.method(:decode!)
    end

  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
zxing_cpp_mac_big_sur-0.1.1 test/test_zxing.rb
zxing_cpp_no_cmake-0.1.2 test/test_zxing.rb
zxing_cpp-0.1.1 test/test_zxing.rb
zxing_cpp-0.1.0 test/test_zxing.rb