#!/usr/bin/ruby -w # test_optionparser.rb: Unit tests for the pdfmult script. # # Copyright (C) 2011-2012 Marcus Stollsteimer require 'minitest/spec' require 'minitest/autorun' require 'pdfmult' describe Pdfmult::Optionparser do it 'should return the correct default values' do options = Pdfmult::Optionparser.parse!(['sample.pdf']) expected = { :infile => 'sample.pdf', :outfile => 'sample_2.pdf', :number => 2, :pages => nil, :latex => false } options.must_equal expected end it 'should recognize the -n option and set the corresponding output filename' do options = Pdfmult::Optionparser.parse!(['sample.pdf', '-n', '4']) options[:outfile].must_equal 'sample_4.pdf' options[:number].must_equal 4 end it 'should not accept invalid -n option values' do lambda { Pdfmult::Optionparser.parse!(['sample.pdf', '-n', '3']) }.must_raise OptionParser::InvalidArgument end it 'should recognize the -o option' do options = Pdfmult::Optionparser.parse!(['sample.pdf', '-o', 'outfile.pdf']) options[:outfile].must_equal 'outfile.pdf' end it 'should recognize the -p option' do options = Pdfmult::Optionparser.parse!(['sample.pdf', '-p', '4']) options[:pages].must_equal 4 end it 'should recognize the -l option and set the corresponding output filename' do options = Pdfmult::Optionparser.parse!(['sample.pdf', '-l']) options[:outfile].must_equal 'sample_2.tex' options[:latex].must_equal true end it 'should only accept positive -p option values' do lambda { Pdfmult::Optionparser.parse!(['sample.pdf', '-p', '0.5']) }.must_raise OptionParser::InvalidArgument lambda { Pdfmult::Optionparser.parse!(['sample.pdf', '-p', '0']) }.must_raise OptionParser::InvalidArgument lambda { Pdfmult::Optionparser.parse!(['sample.pdf', '-p', '-1']) }.must_raise OptionParser::InvalidArgument end it 'should not accept wrong number of arguments' do lambda { Pdfmult::Optionparser.parse!(['sample.pdf', 'sample2.pdf']) }.must_raise ArgumentError lambda { Pdfmult::Optionparser.parse!(['']) }.must_raise ArgumentError lambda { Pdfmult::Optionparser.parse!([]) }.must_raise ArgumentError end it 'should not accept invalid options' do lambda { Pdfmult::Optionparser.parse!(['-x']) }.must_raise OptionParser::InvalidOption end end