Sha256: 07eed76142fcfb7e0eee10d85f2341779e6504e4ab47b570d0415e2d5cbb3764
Contents?: true
Size: 1.94 KB
Versions: 3
Compression:
Stored size: 1.94 KB
Contents
require 'spec_helper' module WebsocketRails describe Channel do subject { Channel.new :awesome_channel } let(:connection) { double('connection') } before do connection.stub!(:trigger) end it "should maintain a pool of subscribed connections" do subject.subscribers.should == [] end describe "#subscribe" do it "should add the connection to the subscriber pool" do subject.subscribe connection subject.subscribers.include?(connection).should be_true end end describe "#trigger" do it "should create a new event and trigger it on all subscribers" do event = double('event').as_null_object Event.should_receive(:new) do |name,data| name.should == 'event' data[:data].should == 'data' event end connection.should_receive(:trigger).with(event) subject.subscribe connection subject.trigger 'event', :data => 'data' end end describe "#trigger_event" do it "should forward the event to the subscribers" do subject.should_receive(:send_data).with('event') subject.trigger_event 'event' end end context "private channels" do it "should be public by default" do subject.instance_variable_get(:@private).should_not be_true end describe "#make_private" do it "should set the @private instance variable to true" do subject.make_private subject.instance_variable_get(:@private).should be_true end end describe "#is_private?" do it "should return true if the channel is private" do subject.instance_variable_set(:@private,true) subject.is_private?.should be_true end it "should return false if the channel is public" do subject.instance_variable_set(:@private,false) subject.is_private?.should_not be_true end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
websocket-rails-0.1.8 | spec/unit/channel_spec.rb |
websocket-rails-0.1.7 | spec/unit/channel_spec.rb |
websocket-rails-0.1.6 | spec/unit/channel_spec.rb |