[rspec-users] Rake task for focused examples

David Chelimsky dchelimsky at gmail.com
Wed Nov 3 08:40:12 EDT 2010

On Nov 3, 2010, at 1:08 AM, Toni Tuominen wrote:

> Hi,
> Is it possible to make a rake task to run examples with a certain
> filter on? In this case I want to run rake spec:focused and run only
> the examples with :focus => true.

Not yet. Right now (2.0.1) the only way to define filters is in an RSpec.configure block. I do it like the first example on http://relishapp.com/rspec/rspec-core/v/2-0/dir/filtering/run-all-when-everything-filtered. If there are any examples or groups with ":focus => true", only those get run. If there are not, then everything gets run.

There is an open issue/pull request to add command line support for "tags" similar to that in Cucumber. So if you have:

  describe "foo", :fast => true do
    it("does something"){ ... }

Then you can do this on the command line:

  rspec spec --tags fast

I'm planning to include this in the next minor release (2.1.0). Once that's in place you can set up rake tasks like this:

  RSpec::Core::RakeTask.new(:fast) do |t|
    t.rspec_options = "--tags fast"

Take a look at the pull request (https://github.com/rspec/rspec-core/pull/205) to see all the options that will be available once this in place. It's going to be pretty powerful.


More information about the rspec-users mailing list