Sauter la navigation

Note personnelle : Ne pas utiliser des dates historiques – du type 14 juillet 1789 – pour tester des timestamps, sous peine d’avoir des valeurs négatives ! :-)

Grace à cet article (et ceux cités dedans !), je peux tester une tâche rake avec Rspec.

Cependant j’avais besoin de passer des paramètres à ma tâche rake.

Ceci peut être fait en utilisant la variable ENV :

describe "app rake tasks" do
  before :each do
    @rake = Rake::Application.new
    Rake.application = @rake
    load "#{RAILS_ROOT}/lib/tasks/read_file.rake"
    @file_path = "#{RAILS_ROOT}/tmp/jaccuse.txt"
    ENV["file_to_read"] = @file_path # paramètre passé à la tâche rake
  end

Dans la tâche rake (lib/tasks/read_file.rake) :
  task :validate => :environment do
    puts File.read(ENV["file_to_read"])
  end

En fait, ça équivaut à lancer la tâche :

rake read_file file_to_read=jaccuse.txt

J’ai longtemps cherché !

Object.const_get("Array") #=> Array

Bonjour à tous,

Ce blog est davantage un carnet de notes qu’une vitrine personnelle. C’est sec et bref ! :p

(z ||= []) << 'test'

équivaut à :

z.nil? ? z = ['test'] : z << 'test'

EventMachine is a framework for network and concurrent programming, based on the Reactor design pattern. The Reactor pattern describes a service handler that receives events and dispatches them to registered event handlers. The benefits of the reactor pattern are a clear separation between the event dispatching and the application logic that handles the events, without complicating the code with multithreading.(source : http://www.infoq.com/news/2008/06/eventmachine )

http://rubyeventmachine.com/

Partie 1 : http://www.akitaonrails.com/2008/5/25/rolling-with-rails-2-1-the-first-full-tutorial-part-1

Partie 2 : http://www.akitaonrails.com/2008/5/26/rolling-with-rails-2-1-the-first-full-tutorial-part-2

Suivre

Get every new post delivered to your Inbox.