require "pp" require File.dirname(__FILE__) + '/spec_helper' describe Message::Recorder::Collector do before do @recorder = Message::Recorder.new end it "should record" do chain = Message::Recorder::Collector.new(:recorder => @recorder) chain.record_message(:downcase) chain.record_message(:+, " world") chain.size.should be_eql(1) chain.first.size.should be_eql(2) chain.send_to("HELLO", @recorder).should be_eql(["hello world"]) end it "should branch" do chain = Message::Recorder::Collector.new(:recorder => @recorder) chain.record_message(:downcase) chain.record_message(:+, " world") chain.size.should be_eql(1) chain.first.size.should be_eql(2) chain.send_to("HELLO", @recorder).should be_eql(["hello world"]) branch = chain.branch branch.record_message(:+, "!") branch.size.should be_eql(1) branch.first.size.should be_eql(3) branch.send_to("HELLO", @recorder).should be_eql(["hello world!"]) branch.should_not be_equal(chain) end it "should collect a single chain" do collector = Message::Recorder::Collector.new(:recorder => @recorder) collector.collect_messages.downcase + " world" collector.size.should be_eql(1) collector.send_to("HELLO", @recorder).should be_eql(["hello world"]) end it "should collect a branched chain" do collector = Message::Recorder::Collector.new(:recorder => @recorder) collector.collect_messages.downcase.with_results do intern capitalize end collector.size.should be_eql(2) collector.first.size.should be_eql(2) collector.last.size.should be_eql(2) collector.send_to("HELLO",@recorder).should ==([:hello, "Hello"]) end it "should collect a branched chain" do collector = Message::Recorder::Collector.new(:recorder => @recorder) collector.collect_messages.compact.with_results do collect { |s| s.intern } collect { |s| s.capitalize }.with_results do collect { |s| s.concat " world" } collect { |s| s.concat " simon" } end.with_results do collect { |s| s.concat "!" } collect { |s| s.concat "?" } end end expected = [[:hello, :bye], ["Hello world!", "Bye world!"], ["Hello simon!", "Bye simon!"], ["Hello world?", "Bye world?"], ["Hello simon?", "Bye simon?"]] collector.send_to([nil, "hello", nil, "bye", nil], @recorder).should == expected end end