spec/templates/onefile_spec.rb in yard-0.7.5 vs spec/templates/onefile_spec.rb in yard-0.8.0
- old
+ new
@@ -4,44 +4,61 @@
attr_accessor :files, :string
def initialize(files, string)
@files = files
@string = string
end
-
+
def serialize(object, data)
files << object
string << data
end
end
describe YARD::Templates::Engine.template(:default, :onefile) do
- before { Registry.clear }
+ before do
+ Registry.clear
+ if defined?(::Encoding)
+ @eenc, Encoding.default_external = Encoding.default_external, 'ascii-8bit'
+ @ienc, Encoding.default_internal = Encoding.default_internal, 'ascii-8bit'
+ end
+ end
- it "should render html" do
- files = []
- string = ''
+ after do
+ if defined?(::Encoding)
+ Encoding.default_internal = @ienc
+ Encoding.default_external = @eenc
+ end
+ end
+
+ def render
+ @files = []
+ @output = ''
YARD.parse_string <<-eof
class A
# Foo method
# @return [String]
def foo; end
-
+
# Bar method
# @return [Numeric]
def bar; end
end
eof
- readme = CodeObjects::ExtraFileObject.new('README',
+ readme = CodeObjects::ExtraFileObject.new('README',
"# This is a code comment\n\n# Top of file\n\n\nclass C; end")
- Templates::Engine.generate Registry.all(:class),
- :serializer => StringSerializer.new(files, string),
+ Templates::Engine.generate Registry.all(:class),
+ :serializer => StringSerializer.new(@files, @output),
:onefile => true, :format => :html, :readme => readme, :files => [readme,
CodeObjects::ExtraFileObject.new('LICENSE', 'This is a license!')
]
- files.should == ['index.html']
- string.should include("This is a code comment")
- string.should include("This is a license!")
- string.should include("Class: A")
- string.should include("Foo method")
- string.should include("Bar method")
+ end
+
+ it "should render html" do
+ render
+ @files.should == ['index.html']
+ @output.should include("This is a code comment")
+ @output.should include("This is a license!")
+ @output.should include("Class: A")
+ @output.should include("Foo method")
+ @output.should include("Bar method")
end
end