Sha256: b1a27862cd1d6c91eacbe23b1f06cfbca9a4ca623b656d8866aa35cd2a219294
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 KB
Contents
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>. # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved. # License:: GNU General Public License (GPL). # Revision:: $Id: factory.rb 221 2005-05-09 12:40:57Z ertai $ module Commands class Factory < Command def initialize super(nil) @command_class = Command end def new_command ( *a, &b ) cmd = @command_class.new(*a, &b) instance_variables.each do |var| next if var =~ /^@command(_class)?$/ cmd.send(var[1..-1] + '=', instance_variable_get(var)) end cmd end alias :create :new_command end # class Factory if $0 == __FILE__ require 'test/unit' class FactoryTest < Test::Unit::TestCase def setup assert_nothing_raised { @fa = Factory.new } end def test_0_initialize end def test_new_command assert_nothing_raised do assert_kind_of(Command, @fa.create('wc')) assert_kind_of(Command, @fa.new_command('ls')) end end def test_simple assert_nothing_raised do @fa << 42 @fa.input = 'inp' @fa = @fa > 'out' @cmd = @fa.create('foo') end assert_equal('foo', @cmd.command) assert_equal(42, @cmd.arg_list.first) assert_equal('inp', @cmd.input) assert_equal('out', @cmd.output) end end # class FactoryTest end end # module Commands
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vcs-0.2.148 | ruby_ex/commands/factory.rb |