Skip to content

Commit

Permalink
Call to_s on argument to Document.escape
Browse files Browse the repository at this point in the history
* (Thanks to Jonas Bähr for reporting this change in behavior from the v1 branch)
  • Loading branch information
Bruce Williams committed Sep 20, 2008
1 parent 9259528 commit 07278e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/rtex/escaping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Escaping

# Escape text using +replacements+
def escape(text)
replacements.inject(text) do |corpus, (pattern, replacement)|
replacements.inject(text.to_s) do |corpus, (pattern, replacement)|
corpus.gsub(pattern, replacement)
end
end
Expand Down
20 changes: 16 additions & 4 deletions test/document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ class DocumentTest < Test::Unit::TestCase
should "have a to_pdf method" do
assert document(:first).respond_to?(:to_pdf)
end

should "escape characters" do
assert_equal '\textbackslash{}\textasciitilde{}', RTeX::Document.escape('\~')

context "when escaping" do
setup do
@obj = Object.new
def @obj.to_s
'\~'
end
@escaped = '\textbackslash{}\textasciitilde{}'
end
should "escape character" do
assert_equal @escaped, RTeX::Document.escape(@obj.to_s)
end
should "convert argument to string before attempting escape" do
assert_equal @escaped, RTeX::Document.escape(@obj)
end
end

should "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')
Expand Down

0 comments on commit 07278e3

Please sign in to comment.