Skip to content
Permalink
Browse files
Adding rake task for specs.
Ugh. This is so stupid. If I name this :spec, it doesn't work. But :spec_lolz does.
  • Loading branch information
steveklabnik committed Nov 22, 2011
1 parent f92752f commit 15625a8da275109cd09d61e28da341062c2197e2
Showing 1 changed file with 4 additions and 0 deletions.
@@ -0,0 +1,4 @@
RSpec::Core::RakeTask.new(:spec_lolz) do |spec|
spec.rspec_opts = ["-r./spec/spec_helper.rb"]
end

6 comments on commit 15625a8

@justinko
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:spec is the default argument to RSpec::Core::RakeTask.new

@justinko
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And by not work, you mean it still uses the default (rspec-rails provided) "spec" rake task?

@steveklabnik
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. If I make it :spec, and I run rake spec, the argument is not respected. It's very strange.

@justinko
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You basically have two options:

1.) Keep the "spec_lolz" task. It works because it's not named "spec".
2.) Add Rake.application.instance_variable_get('@tasks').delete('spec') to the top of your rspec.rake file. This will delete the "spec" task that rspec-rails provides via railties.

@steveklabnik
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh I didn't know about that! I swear that I used to be able to just override it, did something change?

I don't have time to do that right now, but if you worked up a pull request, I'd totally merge it. :)

@justinko
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh I didn't know about that! I swear that I used to be able to just override it, did something change?

RSpec::Core::RakeTask.new just creates new rake tasks using the task DSL. And, Rake doesn't allow you to "override" tasks, it just creates new ones:

task :spec do
  puts 'one'
end

task :spec do
  puts 'two'
end

# running `rake spec` will output "one" & "two"

To overwrite a task, you have get hacky.

Please sign in to comment.