[rspec-users] [rspec] loading specs as an object model without running them

David Chelimsky dchelimsky at gmail.com
Wed Apr 29 06:54:20 EDT 2009


On Wed, Apr 29, 2009 at 1:23 AM, Marty Andrews <marty at martyandrews.net> wrote:
> I'd like to load all of my examples into memory without actually
> running them, so I can traverse the object tree and get descriptions
> etc.  I'm finding it tricky to figure out how to do that though.
> There seems to be an inherent assumption in the framework that that
> examples will actually run.
>
> So basically, I want to do something like this:
>
> examples = load_examples_without_running
> examples.each {|example| puts example.description}

There is a --dry-run command line switch that will do this for you,
but I've been considering deprecating it because it can't work
consistently with matcher-generated descriptions:

describe RSpec do
  it { should be_concise }
end

$ spec rspec_spec.rb
RSpec
  should be concise

In this case, the be_concise matcher generates the text "should be
concise" when it is run. If you don't run it, there is no description.
As this approach becomes more and more popular, the --dry-run not only
becomes less useful, it actually becomes somewhat of a frustration.

As for getting a handle on the objects, this is something that is not
really baked into RSpec, but will definitely be baked into rspec-2.0.
Work on this will start later this year (probably not until after the
rspec book is off to print). Goals for it include a very clean
separation of the DSL and the underlying object model and a very
lightweight runner.

So in the short run, your best option is to use --dry-run and
understand that you only get value out of it if you write docstrings
for all of your examples.

Cheers,
David

>
> def load_examples_without_running
>  # what goes here?
> end
>
>
> Does anyone have an idea about how I might do that?
>
> -- Marty Andrews
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list