spec/applix_spec.rb in applix-0.3.7 vs spec/applix_spec.rb in applix-0.3.8

- old
+ new

@@ -1,15 +1,59 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "Applix" do + it 'calls cluster prolog' do + Applix.main(%w(foo a b)) do + cluster(:foo) do + prolog { |args, options| + args.should == %w(a b) + args.reverse! + } + handle(:a) { raise 'should not be called!' } + handle(:b) { :b_was_called } + end + end.should == :b_was_called + end + + it 'support :cluster for nesting' do + args = %w(-a -b:2 foo bar p1 p2) + Applix.main(args) do + handle(:foo) do + raise 'should not be called!' + end + cluster(:foo) do + handle(:bar) do |*args, options| + args.should == %w(p1 p2) + options.should == {:a => true, :b => 2} + args + end + end + end.should == %w{p1 p2} + end + + it 'can even cluster clusters' do + args = %w(foo bar f p1 p2) + Applix.main(args) do + cluster(:foo) do + cluster(:bar) do + handle(:f) do |*args, options| + args.should == %w(p1 p2) + options.should == {} + args + end + end + end + end.should == %w{p1 p2} + end + it 'prolog can even temper with arguments to modify the handle sequence' do Applix.main(['a', 'b']) do prolog { |args, options| args.should == ['a', 'b'] args.reverse! } - handle(:a) { raise 'shoule not be called!' } + handle(:a) { raise 'should not be called!' } handle(:b) { :b_was_called } end.should == :b_was_called end it 'prolog has read/write access to args and options' do