The HtmlFormatter wants a way to output stuff. Give it STDOUT:
@html = RSpec::Core::Formatters::HtmlFormatter.new(STDOUT)
If you want the output to go to a file however, such as an HTML file, give it a file handle:
fh = File.open('path/to/html_output/rspec-html-output.html', 'w')
@html = RSpec::Core::Formatters::HtmlFormatter.new(fh)
Now you'll have a nice little html file of rspec's formatted output.
Edit:
Whatever you pass to RSpec::Core::Formatters::HtmlFormatter.new
needs to respond to puts
and flush
.
Since you want to save the output to accessors you can define those methods on your own custom classes that will save the output to the appropriate accessors :html and :documentation:
class HTMLOutput
def initialize(rspec_runner)
@rspec_runner = rspec_runner
end
def puts(html)
@rspec_runner.html ||= ""
@rspec_runner.html << html
end
def flush; end
end
class DocOutput
def initialize(rspec_runner)
@rspec_runner = rspec_runner
end
def puts(html)
@rspec_runner.documentation ||= ""
@rspec_runner.documentation << html
end
def flush; end
end
class RSpecRunner
def initialize(path)
# I assumed you wanted to save the output of the formatter to the
# accessors :html and :documentation but you were already assigning
# the formatters to these accessors via @html etc. Make new instance vars
# for these and use the accessors just for the output.
# By instantiating these output classes and passing in self they will be able
# to save the output to the :html, :documentation accessors.
@html_formatter = RSpec::Core::Formatters::HtmlFormatter.new(HTMLOutput.new(self))
@documentation_formatter = RSpec::Core::Formatters::DocumentationFormatter.new(DocOutput.new(self))
end
... rest of your code ...
end
Finally, in your runner's run!
method you don't need to instantiate this guy again:
@html = RSpec::Core::Formatters::HtmlFormatter.new(nil)
Hope that helps.