cinch-test 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'minitest'
5
+ gem 'wrong'
6
+ gem 'rake'
7
+ gem 'rr'
8
+ gem 'debugger'
@@ -0,0 +1,17 @@
1
+ require './lib/cinch/test/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "cinch-test"
5
+ s.version = Cinch::Test.version
6
+ s.authors = ["Jay Adkisson"]
7
+ s.email = ["jay@jayferd.us"]
8
+ s.summary = "utility methods for testing Cinch bots"
9
+ s.description = <<-desc.strip.gsub(/\s+/, ' ')
10
+ A collection of utility methods for testing Cinch bots
11
+ desc
12
+ s.homepage = "http://github.com/jayferd/cinch-test"
13
+ s.rubyforge_project = "cinch-test"
14
+ s.files = Dir['Gemfile', 'cinch-test.gemspec', 'lib/**/*.rb']
15
+
16
+ s.add_dependency 'cinch'
17
+ end
@@ -0,0 +1,98 @@
1
+ require 'cinch'
2
+
3
+ require 'pathname'
4
+ require 'thread'
5
+
6
+ load Pathname.new(__FILE__).dirname.join('test/version.rb')
7
+
8
+ module Cinch
9
+ module Test
10
+ class MockIRC < Cinch::IRC
11
+ def initialize(*)
12
+ super
13
+ # the #setup method adds the @network property among
14
+ # other things
15
+ setup
16
+ end
17
+
18
+ # @override
19
+ # never try to actually connect to a network
20
+ def connect
21
+ @bot.loggers.info('mock irc: not connecting')
22
+ end
23
+ end
24
+
25
+ class MockBot < Cinch::Bot
26
+ def initialize(*)
27
+ super
28
+ @irc = MockIRC.new(self)
29
+
30
+ # auugh why
31
+ # this sets up instances of the plugins provided.
32
+ # by default this is done in #start, which also
33
+ # overrides @irc and calls @irc.start, which does
34
+ # network i/o. :(
35
+ @plugins.register_plugins(@config.plugins.plugins)
36
+ end
37
+ end
38
+
39
+ class MockMessage < Cinch::Message
40
+ def initialize(msg, bot, opts={})
41
+ # override the message-parsing stuff
42
+ super(nil, bot)
43
+ @message = msg
44
+ @user = opts.delete(:user) {
45
+ @bot.user_list.find_ensured(nil, 'test', nil)
46
+ }
47
+
48
+ @channel = opts.delete(:channel) { nil }
49
+ end
50
+ end
51
+
52
+ def make_bot(plugin, opts, &b)
53
+ MockBot.new do
54
+ configure do |c|
55
+ c.nick = 'testbot'
56
+ c.server = nil
57
+ c.channels = []
58
+ c.plugins.plugins = [plugin]
59
+ c.plugins.options[plugin] = opts
60
+ c.reconnect = false
61
+ end
62
+
63
+ instance_eval(&b) if b
64
+ end
65
+ end
66
+
67
+ def make_message(bot, text, opts={})
68
+ MockMessage.new(text, bot, opts)
69
+ end
70
+
71
+ def send_message(message, event=:message)
72
+ handlers = message.bot.handlers
73
+ handlers.dispatch(event, message)
74
+
75
+ # join all of the freaking threads, like seriously
76
+ # why is there no option to dispatch synchronously
77
+ handlers.each do |handler|
78
+ handler.thread_group.list.each(&:join)
79
+ end
80
+ end
81
+
82
+ def get_replies(message, event=:message)
83
+ mutex = Mutex.new
84
+
85
+ replies = []
86
+
87
+ (class << message; self; end).class_eval do
88
+ define_method :reply do |r|
89
+ mutex.synchronize { replies << r }
90
+ end
91
+ end
92
+
93
+ send_message(message, event)
94
+
95
+ replies
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,7 @@
1
+ module Cinch
2
+ module Test
3
+ def self.version
4
+ '0.0.1'
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jay Adkisson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cinch
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: A collection of utility methods for testing Cinch bots
31
+ email:
32
+ - jay@jayferd.us
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - Gemfile
38
+ - cinch-test.gemspec
39
+ - lib/cinch/test/version.rb
40
+ - lib/cinch/test.rb
41
+ homepage: http://github.com/jayferd/cinch-test
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project: cinch-test
61
+ rubygems_version: 1.8.23
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: utility methods for testing Cinch bots
65
+ test_files: []
66
+ has_rdoc: