On Wed, Apr 29, 2009 at 6:09 AM, Marty A. [email protected]
wrote:
examples will actually run.
Work on this will start later this year (probably not until after the
test implementation
you’ve got any more tips, let me know. I’ll send in a code snippet if I
manage to get it going
There is something you can almost use for this, but it’s
incomplete at the moment. RSpec let’s you write your own output
formatters, which receive messages for every example group and example
as they are run. Currently, the object passed to example_started (and
a few other methods) is an ExampleGroupProxy, which includes an
options hash passed to the example. So if you do this:
it “automates some acceptance test declared on a story”,
:traces_to_story => 25 do
…
end
Then you could do stuff like:
def example_started(example_proxy)
traces_to_story(example_proxy.options[:traces_to_story]
end
This should solve your problem assuming that you have docstrings for
all of your examples. The big missing piece at this moment is that the
ExampleGroupProxy (passed to example_group_started) doesn’t include
the options hash, but I’ll happily add that tonight.
To see this in action, try this:
require ‘spec/runner/formatter/base_text_formatter’
class OptionsFormatter < Spec::Formatter::BaseTextFormatter
def example_started(proxy)
puts proxy.options.inspect unless proxy.options.empty?
end
end
require ‘spec’
describe “example” do
it “supports options”, :like => ‘these’ do
# no need for anything here
end
end
Now, on the command line:
$ spec --require options_formatter.rb example_spec.rb --format
OptionsFormatter
{:like => ‘these’}
Formatter API is here:
http://rspec.rubyforge.org/rspec/1.2.4/classes/Spec/Runner/Formatter/BaseFormatter.html
Let me know if this is a good direction for you and I’ll add the
options hash to the example group proxy.
Cheers,
David