Skip to content

Commit

Permalink
More complete testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jamez01 committed Dec 4, 2014
1 parent b36da85 commit 719962a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def command_privmsg(args)
def command_msg(args)
target,msg = args['args'].split(/\s/,2)
begin
@bot.Target(target).send(msg)
bot.Target(target).send(msg)
rescue
systemmsg("error","No such channel or user, #{target}")
end
Expand All @@ -50,7 +50,7 @@ def command_me(args)
def command_join(args)
return unless args['args']
args['args'].split(/[,\s]/).each { |channel|
bot.join(channel) if channel.start_with? "#" # join if actual channel
bot.join(channel.strip) if channel.strip.start_with? "#" # join if actual channel
}
end

Expand Down
2 changes: 1 addition & 1 deletion public/webric.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ body {
}
#inputRow { margin-top: 15px; }
#chatCol {
overflow-x: none;
overflow-x: auto;
overflow-y: auto;
word-wrap: normal;
white-space: normal;
Expand Down
67 changes: 67 additions & 0 deletions spec/lib/commands_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'spec_helper'
require './webric.rb'
require 'cinch/test'

describe WebRic::Commands do
before :each do
@ws = double("Web Socket",send: true)

@client = WebRic::Client.new(@ws)
end

it "Can parse a command" do
expect(@client).to receive(:command_names).with({ 'channel' => "#WebRicIRC" })
@client.parse_command({'command' => 'names', 'args' => { 'channel' => "#WebRicIRC" }})
end

it "parts channels" do
@channel = double("Channel", part: true)
@bot = double("Cinch Bot",Channel: @channel)
allow(@client).to receive(:bot).and_return(@bot)

expect(@bot).to receive(:Channel).with("#WebRicIRC")
expect(@channel).to receive(:part)

@client.command_part({'args' => "#WebRicIRC"})
end

it "joins channels" do
@bot = double("Cinch Bot",join: true)
allow(@client).to receive(:bot).and_return(@bot)

expect(@bot).to receive(:join).with("#WebRicIRC")

@client.command_join({'args' => "#WebRicIRC"})
end

it "lists names" do
@channel = double("Channel", part: true, :users => {"TestUser"=>"o"})
@bot = double("Cinch Bot",Channel: @channel)
allow(@client).to receive(:bot).and_return(@bot)

expect(@client).to receive(:send_command).with("names",{:users=>["@TestUser"]})

@client.command_names({'args' => { 'channel' => '#WebRicIRC'}})
end

it "sends actions" do
@target = double("Target", action: true)
@bot = double("Cinch Bot", Target: @target, :nick => "TestUser")
allow(@client).to receive(:bot).and_return(@bot)

expect(@client).to receive(:action).with("#WebRicIRC","TestUser", "test")

@client.command_me({'channel' => '#WebRicIRC', 'message' => 'test'})
end

it "sends messages" do
@target = double("Target", send: true)
@bot = double("Cinch Bot", Target: @target)
allow(@client).to receive(:bot).and_return(@bot)

expect(@bot).to receive(:Target).with("#WebRicIRC")
expect(@target).to receive(:send).with("test")

@client.command_msg({'args' => '#WebRicIRC test'})
end
end
16 changes: 15 additions & 1 deletion spec/lib/webric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@ws = double("Web Socket",send: true)
@client = WebRic::Client.new(@ws)
end

it "can bet setup" do
expect(@client).to receive(:connect)
@client.setup('nick' => 'test_nick', 'server' => 'irc.test.com', 'port' => 6667)
Expand All @@ -30,4 +30,18 @@
@client.privmsg("#test", "testUser","message")
end

it "can list names" do
channel = double("Channel", :users => {"TestUser"=>"o"})
bot = double("Cinch Bot", Channel: channel)

allow(@client).to receive(:bot).and_return(bot)

expect(@client).to receive(:send_command).with("names",{:channel => "#WebRicIRC", :users => ["@TestUser"] })
@client.names("#WebRicIRC")
end

it "can handle actions" do
expect(@client).to receive(:send_command).with(:action, {:nick=>"TestUser", :channel=>"#WebRicIRC", :message=>"test"})
@client.action("#WebRicIRC","TestUser","test")
end
end
2 changes: 1 addition & 1 deletion webric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def socket

# Send list of users in channel to websocket
def names(channel)
target=@bot.Channel(channel)
target = bot.Channel(channel)
users = target.users.map { |u,m| "#{'@' if m.include? "o" }#{'+' if m.include? "v"}#{u}"}.sort
send_command("names",users: users, channel: channel)
end
Expand Down

0 comments on commit 719962a

Please sign in to comment.