spec/rflow/component/port_spec.rb in rflow-1.0.0a5 vs spec/rflow/component/port_spec.rb in rflow-1.0.0a6

- old
+ new

@@ -1,69 +1,104 @@ require 'spec_helper' class RFlow class Component - describe Port do - it "should not be connected" do - expect(described_class.new(nil)).not_to be_connected + context "Input and output ports" do + let(:connection) { RFlow::Connection.new(RFlow::Configuration::NullConnectionConfiguration.new) } + let(:message) { RFlow::Message.new('RFlow::Message::Data::Raw') } + + describe Port do + it "should not be connected" do + expect(described_class.new(nil)).not_to be_connected + end end - end - describe HashPort do - it "should not be connected" do - expect(described_class.new(nil)).not_to be_connected + describe HashPort do + it "should not be connected" do + expect(described_class.new(nil)).not_to be_connected + end end - end - describe InputPort do - context "#connect!" do - it "should be connected" do - connection = double('connection') - allow(connection).to receive(:name) - allow(connection).to receive(:uuid) - allow(connection).to receive(:input_port_key) - expect(connection).to receive(:connect_input!) + [InputPort, OutputPort].each do |c| + describe c do + context "#add_connection" do + it "should add the connection" do + described_class.new(nil).tap do |port| + port.add_connection(nil, connection) + expect(port[nil]).to include connection + end + end + end - described_class.new(nil).tap do |port| - port.add_connection(nil, connection) - expect(port).not_to be_connected - port.connect! - expect(port).to be_connected + context "#remove_connection" do + it "should remove the connection" do + described_class.new(nil).tap do |port| + port.add_connection(nil, connection) + port.remove_connection(nil, connection) + expect(port[nil]).not_to include connection + end + end end end end - context "#(add|remove)_connection" do - it "should remove the connection" do - connection = double('connection') - allow(connection).to receive(:name) - allow(connection).to receive(:uuid) - allow(connection).to receive(:input_port_key) + describe InputPort do + context "#connect!" do + it "should be connected" do + expect(connection).to receive(:connect_input!) - described_class.new(nil).tap do |port| - port.add_connection(nil, connection) - expect(port[nil]).to include connection - port.remove_connection(nil, connection) - expect(port[nil]).not_to include connection + described_class.new(nil).tap do |port| + port.add_connection(nil, connection) + expect(port).not_to be_connected + port.connect! + expect(port).to be_connected + end end end end - end - describe OutputPort do - context "#connect!" do - it "should be connected" do - connection = double('connection') - allow(connection).to receive(:name) - allow(connection).to receive(:uuid) - allow(connection).to receive(:input_port_key) - expect(connection).to receive(:connect_output!) + describe OutputPort do + context "#connect!" do + it "should be connected" do + expect(connection).to receive(:connect_output!) - described_class.new(nil).tap do |port| - port.add_connection(nil, connection) - expect(port).not_to be_connected - port.connect! - expect(port).to be_connected + described_class.new(nil).tap do |port| + port.add_connection(nil, connection) + expect(port).not_to be_connected + port.connect! + expect(port).to be_connected + end + end + end + + context "#add_connection" do + it "should deliver messages to the new connection" do + described_class.new(nil).tap do |port| + port.connect! + port.all_connections # trigger caching + + expect(connection).to receive(:connect_output!) + expect(connection).to receive(:send_message).with(message) + port.add_connection(nil, connection) + + port.send_message(message) + end + end + end + + context "#remove_connection" do + it "should not deliver messages to the old connection" do + described_class.new(nil).tap do |port| + allow(connection).to receive(:connect_output!) + port.add_connection(nil, connection) + port.connect! + port.all_connections # trigger caching + + expect(connection).not_to receive(:send_message) + port.remove_connection(nil, connection) + + port.send_message(message) + end end end end end end