Hi all
(I tried to send this question to the list a few hours ago, but it
seems to have not got through. If it did sorry for the duplication.)
Does anyone have any tips or examples of how to run RSpec example
groups programmatically from within a Ruby application?
Essentially I would like to be able to:
- load example groups from a set of files I know about
- run them
- get back an object that contains information about successes and
failures - reload the example groups
I think I i can accomplish (3) with a custom formatter, (4) by
reflecting on and undefining the classes Example::Subclass_1 etc as
required.
But I’m having real trouble with the first two steps. Here’s what I have
so far:
require ‘rubygems’
require ‘spec’
$spec_runner_at_exit_hook_registered = true
require ‘some_specs’
err = StringIO.new
out = StringIO.new
options = Spec::Options.new(err, out)
options.add_example_group(Spec::Example::ExampleGroup::Subclass_1)
runner = Spec::ExampleGroupRunner.new(options)
runner.run
puts “results:”
puts out.string
puts “\n\n[script end]”
But the results string here claims that there were 0 examples run. By
looking at the output I know that my example is being run however.
Can someone help me put these pieces together?
thanks,
Dan