I'm trying to use CruiseControl.rb (ver. 2.0.0pre1) with RSpec for my Ruby on Rails 3 app. The cruise_config.rb for my project looks like this:
Project.configure do |project|
project.rake_task = 'db:migrate db:test:prepare spec'
project.scheduler.polling_interval = 1.hour
project.scheduler.always_build = false
end
But when I try to run a build with CruiseControl, it says:
rake aborted!
Custom rake task(s) 'spec' not defined
Tasks: TOP => cc:build
(See full trace by running task with --trace)
It can't find the spec rake task to run the RSpec tests. I also tried to define a custom rake task inside my Rakefile and removed the project.rake_task = 'db:migrate db:test:prepare spec' line inside the cruise_config.rb:
desc "Custom Task for CruiseControl.rb"
task :cruise do
puts "Custom Rake task"
Rake::Task['db:migrate'].execute
Rake::Task['db:test:prepare'].execute
Rake::Task['spec'].execute
end
If i do so, CruiseControl says
rake aborted!
ActiveRecord::ConnectionNotEstablished
Tasks: TOP => cruise
(See full trace by running task with --trace)
[CruiseControl] Invoking Rake task "cruise"
Custom Rake task
Does anybody have CruiseControl.rb working with RSpec?
Ensure that you have the :spec task defined in your Rakefile, for RSpec 2, it looks like this:
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
Related
How can I invoke a rake task from the Heroku scheduler?
I need to invoke the command rake sitemap:refresh (from an external library)
# scheduler.rake
task :sitemap_refresh => :environment do
Rails.application.eager_load!
Rake::Task['-s sitemap:refresh'].invoke
end
Use this as the command: bundle exec rake sitemap:refresh
I want to create a Rake task that builds a Jekyll site, then runs tests on the generated site, similar to the following:
require 'html/proofer'
task :test => [:build] do
HTML::Proofer.new('./_site',{
:only_4xx => true,
:check_favicon => true,
:check_html => true
}).run
end
task :build do
system 'bundle exec jekyll build'
end
I'm relatively new to Ruby and I'm keen to gain more experience. Using system 'bundle exec jekyll build' in the build task seems a bit of a shortcut to me, so as an exercise I wanted to refactor this rake task to build the site using Jekyll::Commands::Build and therefore not calling a command line executable, as the above example does. I was hoping something like this would suffice:
# Including only the changed build task
require 'jekyll'
task :build do
config = { 'source' => './', 'destination' => './_site' }
site = Jekyll::Site.new(config)
Jekyll::Commands::Build.build site, config
end
However, I can't build the site using this task:
joenyland#Joes-MBP ~/Documents/masterroot24.github.io $ bundle exec rake build
rake aborted!
NoMethodError: undefined method `to_sym' for nil:NilClass
/Users/joenyland/.rvm/gems/ruby-2.2.1#masterroot24.github.io/gems/jekyll-2.4.0/lib/jekyll/site.rb:27:in `initialize'
/Users/joenyland/Documents/masterroot24.github.io/Rakefile:14:in `new'
/Users/joenyland/Documents/masterroot24.github.io/Rakefile:14:in `block in <top (required)>'
Tasks: TOP => build
(See full trace by running task with --trace)
How do I build an existing site from a Rake task without using the command line and instead use the Jekyll library directly?
As requested by #DavidJacquel in the comments below, I've thrown together a demo of the issue in a repo here.
The configuration should be a Jekyll.configuration instance:
# Including only the changed build task
require 'jekyll'
task :build do
config = Jekyll.configuration({
'source' => './',
'destination' => './_site'
})
site = Jekyll::Site.new(config)
Jekyll::Commands::Build.build site, config
end
Rake tasks scheduled in Heroku found online are in the "rake task-name" format. Heroku passes in an :environment argument to the rake task, but there is no documentation about extra args being passed to a task listed in scheduler.rake
Heroku Scheduler Doc
You may try this:
task :my_task, [:arg1, :arg2] => :environment do |t, args|
puts "Args were: #{args}"
end
and then run manually to see the output:
heroku run rake my_task
UPDATE:
this answer can be an old one already
Instead of rake task_name input rake task_name[arg1, arg2] to the string input accepted by the Task column in the Heroku Scheduler main screen.
As mentioned by CodeGroover, your rake task defined in lib/scheduler.rake should define the parameters it is expecting.
In my application.rb file I have a few options to modify my apps URLs like so:
config.action_controller.default_url_options = { :trailing_slash => true }
But these do not seem to take effect in my Rake tasks, despite the fact that I am running them in the Rails environment via the :environment dependency.
I know that I can get this to work simply by calling the following in my rake task:
default_url_options[:trailing_slash] = true
... but I'd like to DRY this up. Is there a clean way to make a rake task use Rails' default_url_options from application.rb?
You can use the following in a rake task (and in Rails console):
Rails.application.config.action_controller.default_url_options
Somehow Rspec and Cucumber are making it into my default rake task (which is fine because I want them there). But I have tried adding additional tasks to the default task and it has no effect.
What is the proper way to add tasks to the default rake task?
Typically your Rakefile will have something like this:
task :default => [:spec]
You just need to add more tasks into this list.
The answer from davogenes is correct for non-namespaced rake tasks.
If you want to have a default task in namespaces you need to do the following
namespace :mynamespace do
desc "This should be the default"
task :mydefault do
Do.something_by_default
end
desc "Another task in this namespace"
task :other do
Do.something
end
end
desc "This is the default task of mynamespace"
task mynamespace: 'mynamespace:mydefault'
Then you can run rake mynamespace as well as rake mynamespace:other or rake mynamespace:mydefault.