views:

48

answers:

1
+2  Q: 

rake task on gem

I have a rake task for a series of rspecs as follows...

require 'spec/rake/spectask'
require 'joliscrapper'

namespace :spec do

  desc "Web scraping files"
  task :scrapers => :environment do
    Spec::Rake::SpecTask.new do |t|
      t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
      t.spec_files = FileList['spec/scrapers/*_spec.rb']
      puts t
    end
  end

end

My question is how to get out put as usual from an Rspec... now it outputs nothing... I'd like to find any errors and generate an email if one occurs.

adding:

  t.warning = true
  t.verbose = true

does't seem to have the desired effect either.

http://rspec.rubyforge.org/rspec/1.1.12/classes/Spec/Rake/SpecTask.html

+1  A: 

Your code as written will create the spec task when rake spec:scrapers is called and be finished, which isn't what you want I think.

Try:

namespace :spec do

  desc "Web scraping files"  
  Spec::Rake::SpecTask.new :scrapers do |t| #creates the spec task with the name :scrapers
    t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
    t.spec_files = FileList['spec/scrapers/*_spec.rb']
  end 
  task :scrapers => :environment #adds environment as a prereq
end
BaroqueBobcat
ok, that seems to work. But i get an error because my gem is not included. I tried adding require 'somegem' for my gem but it doesn't seem to work?
holden
For your gem, unless you have installed it on your machine, `require 'foo'` won't work. You need to either add your project's lib to the load path, or require the file more explicitly, like so: `require File.expand_path(__FILE__)+'/../lib/joliscrapper'`
BaroqueBobcat