Sha256: 84350c908ee3ce23189d0c4ee88816ea5e41ec68d53860ce884820567de0869c

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

describe MadChatter::MessageListeners::ChannelCommands do

  let (:server) { MadChatter::Server.new({'websocket_backend' => 'MadChatter::Servers::EventMachineWebSocket'}) }
  let (:user) { MadChatter::User.new('usertoken') }
  let (:channel) { MadChatter::Channel.new('myroom') }
  let (:listener) { MadChatter::MessageListeners::ChannelCommands.new }
  
  before(:each) do
    MadChatter.users = []
    MadChatter.channels = []
  end
  
  it 'should allow a user to join a channel' do
    MadChatter.users << user
    MadChatter.channels << channel
    begin
      MadChatter.users.include?(user).should be_true
      MadChatter.find_channel_by_name('myroom').users.include?(user).should be_false
      message = MadChatter::Message.new('message', '/join', user.token, channel.id)
      listener.handle(message)
      MadChatter.find_channel_by_name('myroom').users.include?(user).should be_true
    rescue RuntimeError
    end
  end
  
  it 'should allow /join to exist in a normal message' do
    message = MadChatter::Message.new('message', 'this /join should not count')
    listener.handle(message)
    # how to check that nothing happened?
  end
  
  it 'should allow a user to create a channel' do
    MadChatter.users << user
    MadChatter.channels << channel
    begin
      MadChatter.find_channel_by_name('Foobar Room').should be_nil
      message = MadChatter::Message.new('message', '/channel create Foobar Room', user.token, channel.id)
      listener.handle(message)
      MadChatter.find_channel_by_name('Foobar Room').should_not be_nil
    rescue RuntimeError
    end
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mad_chatter-0.3.4 spec/message_listeners/channel_commands_spec.rb
mad_chatter-0.3.3 spec/message_listeners/channel_commands_spec.rb
mad_chatter-0.3.2 spec/message_listeners/channel_commands_spec.rb