We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: Ruby LaTeX to PDF preprocessor (and Rails plugin)
Homepage: http://rtex.rubyforge.org
Clone URL: git://github.com/bruce/rtex.git
Click here to lend your support to: rtex and make a donation at www.pledgie.com !
rtex / test / document_test.rb
100644 70 lines (59 sloc) 2.162 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require File.dirname(__FILE__) << '/test_helper'
 
context "Document Generation" do
  
  def setup
    change_tmpdir_for_testing
  end
  
  specify "documents have a to_pdf method" do
    assert document(:first).respond_to?(:to_pdf)
  end
  
  specify "can escape characters" do
    assert_equal '\textbackslash{}\textasciitilde{}', RTeX::Document.escape('\~')
  end
  
  specify "documents can use a to_pdf block to move a file to a relative path" do
    begin
      path = File.expand_path(File.dirname(__FILE__) << '/tmp/this_is_relative_to_pwd.pdf')
      document(:first).to_pdf do |filename|
        assert_nothing_raised do
          FileUtils.move filename, path
        end
        assert File.exists?(path)
      end
    ensure
      FileUtils.rm path rescue nil
    end
  end
  
  specify "can generate PDF and return as a string" do
    @author = 'Foo'
    assert_equal '%PDF', document(:first).to_pdf(binding)[0, 4]
  end
  
  specify "can generate TeX source and return as a string with debug option" do
    @author = 'Foo'
    assert_not_equal '%PDF', document(:first, :tex => true).to_pdf(binding)[0, 4]
  end
  
  specify "can generate PDF and give access to file directly" do
    @author = 'Foo'
    data_read = nil
    invocation_result = document(:first).to_pdf(binding) do |filename|
      data_read = File.open(filename, 'rb') { |f| f.read }
      :not_the_file_contents
    end
    assert_equal '%PDF', data_read[0, 4]
    assert_equal :not_the_file_contents, invocation_result
  end
  
  specify "can generate TeX source and give access to file directly" do
    @author = 'Foo'
    data_read = nil
    invocation_result = document(:first, :tex => true).to_pdf(binding) do |filename|
      data_read = File.open(filename, 'rb') { |f| f.read }
      :not_the_file_contents
    end
    assert_not_equal '%PDF', data_read[0, 4]
    assert_equal :not_the_file_contents, invocation_result
  end
  
  specify "can wrap in a layout using `yield'" do
    doc = document(:fragment, :layout => 'testing_layout[<%= yield %>]')
    @name = 'ERB'
    source = doc.source(binding)
    assert source =~ /^testing_layout.*?ERB, Fragmented/
  end
  
end