Skip to content

Instantly share code, notes, and snippets.

@nicholasf
Created December 16, 2009 23:39
Show Gist options
  • Select an option

  • Save nicholasf/258343 to your computer and use it in GitHub Desktop.

Select an option

Save nicholasf/258343 to your computer and use it in GitHub Desktop.
#the rspec
require File.dirname(__FILE__) + '/../spec_helper'
require 'nesstar/ruotes'
require 'nesstar/initialize_directory_participant'
# require 'ruote/engine'
# require 'ruote/storage/hash_storage'
require 'ruote/storage/base'
require 'ruote/storage/fs_storage'
require 'ruote/worker'
# require 'ruote/context'
require 'ruote'
describe Nesstar::InitializeDirectoryParticipant, "an attempt to spec ruote process definitions" do
# include Nesstar::Ruotes
before(:each) do
# @storage = Ruote::HashStorage.new
@storage = Ruote::FsStorage.new("/tmp/atsida-ruote/")
@worker = Ruote::Worker.new(@storage)
@engine = Ruote::Engine.new(@worker)
end
it "should initialize a directory" do
foo = Time.now.to_i
foo = "/tmp/#{foo.to_s}"
@engine.register_participant 'initialize_directory', Nesstar::InitializeDirectoryParticipant
process_def = Ruote.process_definition :name => 'init' do
sequence do
set :dir, :value => foo
participant :ref => 'initialize_directory'
end
end
ARGV << "-d"
@engine.launch(process_def)
# @engine.initialize(@storage)
File.exists?(foo).should be_true
end
end
#the participant
rerequire 'fileutils'
# require 'ruote/context'
require 'ruote/part/local_participant'
require 'ruote/part/template'
require 'ruote'
module Nesstar
class InitializeDirectoryParticipant
include FileUtils
attr_accessor :context
include Ruote::LocalParticipant
include Ruote::TemplateMixin
def initialize (opts, &block)
end
def consume (workitem)
puts "ok"
mkdir(workitem[:dir]) unless File.exists?(workitem[:dir])
puts "ok - #{workitem[:dir]}"
reply_to_engine(workitem)
end
def cancel (fei, flavour)
rm_rf(workitem[:dir]) if File.exists?(workitem[:dir])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment