Writing a simple RSpec test to check that Rake tasks are correct
Posted
by John Feminella
on Stack Overflow
See other posts from Stack Overflow
or by John Feminella
Published on 2010-04-26T19:59:42Z
Indexed on
2010/04/26
20:03 UTC
Read the original article
Hit count: 322
I'm trying to be diligent about checking my rake
tasks with RSpec tests, but in the process of feeling my way around I seem to have hit a wall. I've got a really simple RSpec test that looks like this:
# ./test/meta_spec.rb
describe "Rake tasks" do
require 'rake'
before(:each) do
@rake = Rake::Application.new
@rake.load_rakefile # => Error here!
Rake.application = @rake
end
after(:each) do
Rake.application = nil
end
it "should have at least one RSpec test to execute" do
Rake.application["specs"].spec_files.size.should > 0
end
end
I have a simple task called "specs" defined in ./Rakefile.rb
which has an RSpec task that includes all the *_spec.rb
files.
If I put the @rake.load_rakefile
method in, I want that Rakefile to load. But instead it just bombs out. If I comment it out, however, the test fails because the "specs" task is (understandably) not defined.
Where am I going wrong?
© Stack Overflow or respective owner