Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
159 lines (129 sloc) 5.13 KB
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
namespace :gem do
namespace :plugin do
desc "Create a new plugin"
task :create do
raise "You need to set a name! `rake plugin:create name=[plugin_name]`" unless ENV["name"]
name = ENV["name"].downcase
file = File.join("lib", "ceiling_cat", "plugins", "#{name}.rb")
test_file = File.join("spec", "ceiling_cat", "plugins", "#{name}_spec.rb")
unless File.exists?(file) || File.exists?(test_file)
contents = plugin_base(name)
File.open(file, 'w') {|f| f.write(contents) }
test_contents = plugin_test_base(name).gsub('\#','#')
File.open(test_file, 'w') {|f| f.write(test_contents) }
puts "Plugin '#{name}' created at #{file}."
puts "Make sure you require it in your Chatfile and add it to your config.plugins so it runs."
else
puts "A plugin named '#{name}' already exists. Try another name."
end
end
end
def plugin_base(name)
%Q{module CeilingCat
module Plugin
class #{name.camelize} < CeilingCat::Plugin::Base
# See lib/ceiling_cat/plugins/base.rb for the methods available by default.
# Plugins are run in the order they are listed in the Chatfile.
# When a plugin returns anything other than nil the plugin execution chain is halted.
# If you want your plugin to do something but let the remaining plugins execute, return nil at the end of your method.
# handle manages a plugin's entire interaction with an event.
# If you only want to execute commands - "![command]" - leave handle alone (or remove it and define commands below)
def handle
super
end
# If you want the plugin to run when certain text is sent use commands instead of handle.
# Ceiling Cat will watch for "![command]" or "[name]: [command" and execute the method for that command.
def self.commands
[{:command => "#{name}", :description => "Does something", :method => "#{name}", :public => false}]
end
def self.description
"A plugin called #{name.capitalize}"
end
def self.name
"#{name.gsub("_"," ").capitalize}"
end
def self.public?
false
end
def #{name}
reply "You've created the '#{name.capitalize}' plugin. Now make it do something awesome!"
end
end
end
end
}
end
def plugin_test_base(name)
%Q{require 'spec_helper'
require 'ceiling_cat/plugins/#{name}'
describe "#{name.camelize}" do
before(:each) do
CeilingCat::Storage::Hash.send "clear" # Clear the calls and response each time.
subdomain = "subdomain"
token = "1234abcd"
plugins = [CeilingCat::Plugin::#{name.camelize}]
FakeWeb.register_uri(:get, "https://\#{token}:X@\#{subdomain}.campfirenow.com/rooms.json", :body => fixture('campfire/rooms.json'), :status => ["200"])
FakeWeb.register_uri(:get, "https://\#{token}:X@\#{subdomain}.campfirenow.com/users/me.json", :body => fixture('campfire/me.json'), :status => ["200"])
@connection = CeilingCat::Campfire::Connection.new(OpenStruct.new({:service => 'campfire', :subdomain => subdomain, :token => token, :room => 'Room 1', :plugins => plugins}))
@room = CeilingCat::Campfire::Room.new(:connection => @connection, :room_name => @connection.config.room)
end
describe "base methods" do
# Tests for any methods that run outside of a command
end
describe "commands" do
# Tests for commands
describe "from a guest user" do
before(:each) do
@guest_user = CeilingCat::User.new("Guest", :id => 12345, :role => "guest")
end
describe "calling the 'default' command" do
it "should not do or say anything" do
event = CeilingCat::Event.new(@room,"!#{name}", @guest_user)
@room.should_not_receive(:say)
CeilingCat::Plugin::#{name.camelize}.new(event).handle
end
end
end
describe "from a registered user" do
before(:each) do
@registered_user = CeilingCat::User.new("Guest", :id => 12345, :role => "member")
end
describe "calling the 'default' command" do
it "should call the 'default' method" do
event = CeilingCat::Event.new(@room,"!#{name}", @registered_user)
@room.should_receive(:say).with("You've created the '#{name.capitalize}' plugin. Now make it do something awesome!")
CeilingCat::Plugin::#{name.camelize}.new(event).handle
end
end
end
end
describe 'entrance and exit' do
# Tests for things to run when a user enters or exits the room
describe "entering the room" do
before(:each) do
@registered_user = CeilingCat::User.new("Guest", :id => 12345, :role => "member", :type => :entrance)
end
it "should do something" do
end
end
describe "exiting the room" do
before(:each) do
@registered_user = CeilingCat::User.new("Guest", :id => 12345, :role => "member", :type => :exit)
end
it "should do something" do
end
end
end
end
}
end
end
class String
def camelize
self.split("_").each{|z|z.capitalize!}.join("")
end
end
Something went wrong with that request. Please try again.