[rspec-users] tags and spec_helper

90 views
Skip to first unread message

Matt Wynne

unread,
Jun 24, 2011, 12:55:07 PM6/24/11
to rspec-users
I've been trying to separate out some fast specs in a Rails app in a Gary Bernhardt style[1], and I experimented with using tags.

The problem with using tags is that in order to scan the specs for examples that match the tags, it loads every spec file, most of which require spec_helper, which loads Rails, and so takes 5-6 seconds. Thereby totally defeating the original purpose.

One idea I have is to put some if statements into spec_helper to check the tags that were passed to RSpec and only load the rails env if necessary. Is that possible?

Has anyone else tried doing anything like this?

cheers,
Matt

ma...@mattwynne.net
07974 430184

[1] https://www.destroyallsoftware.com/screencasts/catalog/fast-tests-with-and-without-rails
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

David Chelimsky

unread,
Jun 25, 2011, 9:57:33 AM6/25/11
to rspec-users
On Jun 24, 2011, at 11:55 AM, Matt Wynne wrote:

> I've been trying to separate out some fast specs in a Rails app in a Gary Bernhardt style[1], and I experimented with using tags.
>
> The problem with using tags is that in order to scan the specs for examples that match the tags, it loads every spec file, most of which require spec_helper, which loads Rails, and so takes 5-6 seconds. Thereby totally defeating the original purpose.
>
> One idea I have is to put some if statements into spec_helper to check the tags that were passed to RSpec and only load the rails env if necessary. Is that possible?

What I'm about to tell you is used internally, is not a formal API, and is subject to change without notice. That said, for the moment, you can do this:

if !RSpec.configuration.inclusion_filter[:no_rails]
# ... load rails
end

rspec spec --tag no_rails

I created https://github.com/rspec/rspec-core/issues/416 to address formalizing an API for this. Comments/suggestions/patches welcome.

Cheers,
David

Reply all
Reply to author
Forward
0 new messages