[rspec-users] Slow Focus tags

David Chelimsky dchelimsky at gmail.com
Wed Jun 6 11:24:10 UTC 2012

On Wed, Jun 6, 2012 at 5:14 AM, Rainer Kuhn <rainer at incutio.com> wrote:
> [This is my third and final attempt to post to this group, first 2 were with
> google groups]

The google group is a mirror of the rspec-users list, but for that to
work you actually have to post to the rspec-users list, not the google
group. We're considering retiring that list and only using the google
group, at which point you'd be able to post directly to the google

> I noticed that focusing a single spec takes ages to run. We commonly use
> that, often in combination with guard to speed up our spec runs. I admit
> that the overall performance of our specs is bad, since we ditched mocking
> entirely and went with semi-integration specs on all levels. But this
> practice has served us very well on picking up failures.
> All runs on a single spec with focus: true that only tests (2 + 2).should ==
> 4, among 700 other specs.
> Any ideas how to profile or even fix that?
> # What I want to get:
> $ time rspec spec/models/user_spec.rb:5
> Finished in 1.41 seconds 1 example, 0 failures
> real 0m13.768s
> user 0m11.269s
> sys 0m1.692s

Wow. This is _not_ what I'd want to get. Nearly 14 secs to run a
single example sounds like you're suffering some serious startup time.
What version of rspec, ruby, rails, etc are you running?

> # What I get using the focus tag:
> $ time rake spec
> Finished in 2.1 seconds 1 example, 0 failures
> real 1m5.502s
> user 0m46.467s
> sys 0m14.455s

When you run `rake spec` it loads up the Rails development environment
(because that's the environment you're running rake in) and then
shells out the `rspec spec` command with the Rails test environment.
That's why `rake spec` will always take longer than running `rspec

> $time rspec spec
> Finished in 1.39 seconds 1 example, 0 failures
> real 0m51.350s
> user 0m36.069s
> sys 0m12.842s

When you run with `--tag focus` on the command line, or
`config.filter_run_including :focus`, rspec evaluates the metadata for
every example in the suite in order to find the one(s) that match(es)
the tag. It's possible that you've got a filter in your config or in a
spec that takes a long time to evaluate. What's in RSpec.configure in


More information about the rspec-users mailing list