cinch-test 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: c21cdd89e05e7ac6c64889d9ac5d5b8ed8087d74
4
+ data.tar.gz: e0b20d4963cc2815719feed54221488839d01c1b
5
+ SHA512:
6
+ metadata.gz: 20b19201f0e9d5d6349f4c9bfe1f9354f94acf415aca3fb9dfa275f8ec3ba6d5c33cc98ce882ad72d7d288ba8f8ec300ab8263503a518f58ee673dd14f2fa088
7
+ data.tar.gz: b791bdeda32f5c4206c7a567971c08191e4ef4e598f6c19f1fbecd0da6fc983eb6e04077afa319441ab117947493b1e9b7afdad261c99925c96eb134dfd46858
data/.travis.yml CHANGED
@@ -1,4 +1,23 @@
1
1
  language: ruby
2
+ env:
3
+ global:
4
+ - "JRUBY_OPTS=-Xcext.enabled=true"
2
5
  rvm:
3
- - 1.9.2
6
+ - 2.1.0
7
+ - 2.0.0
4
8
  - 1.9.3
9
+ - 1.9.2
10
+ - 1.8.7
11
+ - jruby-18mode
12
+ - jruby-19mode
13
+ - ruby-head
14
+ - jruby-head
15
+ - ree
16
+ matrix:
17
+ allow_failures:
18
+ - rvm: 1.8.7
19
+ - rvm: ree
20
+ - rvm: jruby-18mode
21
+ - rvm: jruby-19mode
22
+ - rvm: jruby-head
23
+ fast_finish: true
data/README.md CHANGED
@@ -15,7 +15,12 @@
15
15
  with `get_replies(message)`
16
16
 
17
17
  ## Changelog
18
- * 0.0.3
18
+ * 0.0.4 (July 2, 2013)
19
+ * [Bug Fix] Should now capture any user.send|notice|privmsg, channel.send|action events that
20
+ were previously ignored.
21
+ * [Enhancement] replies are now returned as Struct(:message, :event, :time) for more
22
+ sane testing.
23
+ * 0.0.3 (June 6, 2013)
19
24
  * [Bug Fix] Initializing plugins without a config hash works now.
20
25
  * [Bug Fix] MockMessage objects now have a real Cinch::User / Cinch::Channel object
21
26
  instead of strings.
data/cinch-test.gemspec CHANGED
@@ -4,26 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cinch/test/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "cinch-test"
7
+ gem.name = 'cinch-test'
8
8
  gem.version = Cinch::Test::VERSION
9
- gem.authors = ["Jay Adkisson", "Brian Haberer"]
10
- gem.email = ["jay@jayferd.us"]
11
- gem.summary = %q{Helpers for testing Cinch Plugins}
12
- gem.description = %q{A collection of utility methods, mocks and methods for testing Cinch plugins}
13
- gem.homepage = "http://github.com/jayferd/cinch-test"
9
+ gem.authors = ['Jay Adkisson', 'Brian Haberer']
10
+ gem.email = ['jay@jayferd.us']
11
+ gem.summary = %q(Helpers for testing Cinch Plugins)
12
+ gem.description = %q(A collection of utility methods, mocks and methods for testing Cinch plugins)
13
+ gem.homepage = 'http://github.com/jayferd/cinch-test'
14
+ gem.license = 'MIT'
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
17
+ gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(/^(test|spec|features)\//)
19
+ gem.require_paths = ['lib']
19
20
 
20
- gem.add_development_dependency 'rake'
21
- gem.add_development_dependency 'coveralls'
22
- gem.add_development_dependency 'minitest'
23
- gem.add_development_dependency 'wrong'
24
- gem.add_development_dependency 'rake'
25
- gem.add_development_dependency 'rr'
26
- gem.add_development_dependency 'debugger'
27
-
28
- gem.add_dependency 'cinch', '~> 2.0.0'
21
+ gem.add_development_dependency 'coveralls', '~> 0.6'
22
+ gem.add_development_dependency 'minitest', '~> 5'
23
+ gem.add_development_dependency 'wrong', '~> 0.7'
24
+ gem.add_development_dependency 'rake', '~> 10'
25
+ gem.add_development_dependency 'rr', '~> 1.1'
26
+ gem.add_dependency 'cinch', '~> 2'
29
27
  end
data/lib/cinch/test.rb CHANGED
@@ -3,7 +3,9 @@ require 'pathname'
3
3
  require 'thread'
4
4
 
5
5
  module Cinch
6
+ # Module to allow near network I/O free testing of cinch plugins.
6
7
  module Test
8
+ # Mock Class to handle faux IRC networks
7
9
  class MockIRC < Cinch::IRC
8
10
  def initialize(*args)
9
11
  super
@@ -19,27 +21,43 @@ module Cinch
19
21
  end
20
22
  end
21
23
 
24
+ # Mock Class to avoid spinning up a real version of the chinch bot.
22
25
  class MockBot < Cinch::Bot
23
- def initialize(*args)
26
+ attr_accessor :mask
27
+
28
+ def initialize(*)
24
29
  super
25
30
  @irc = MockIRC.new(self)
26
31
 
27
- # auugh why
28
- # this sets up instances of the plugins provided.
29
- # by default this is done in #start, which also
30
- # overrides @irc and calls @irc.start, which does
31
- # network i/o. :(
32
- @plugins.register_plugins(@config.plugins.plugins)
32
+ # Don't bother initing plugins if we didn't pass any.
33
+ # (This is for testing any non-plugin cinch extensions)
34
+ unless @config.plugins.plugins.empty?
35
+ # auugh why
36
+ # this sets up instances of the plugins provided.
37
+ # by default this is done in #start, which also
38
+ # overrides @irc and calls @irc.start, which does
39
+ # network i/o. :(
40
+ @plugins.register_plugins(@config.plugins.plugins)
41
+ end
42
+
43
+ # set the bot's hostmask
44
+ @mask = 'foo!bar@baz'
33
45
  end
34
46
  end
35
47
 
48
+ # Mock class to present Message objects in a more simple fashion
36
49
  class MockMessage < Cinch::Message
37
50
  def initialize(msg, bot, opts = {})
38
51
  # override the message-parsing stuff
39
52
  super(nil, bot)
40
53
  @message = msg
41
54
  @user = Cinch::User.new(opts.delete(:nick) { 'test' }, bot)
42
- @channel = Cinch::Channel.new(opts.delete(:channel), bot) if opts.key?(:channel)
55
+ if opts.key?(:channel)
56
+ @channel = Cinch::Channel.new(opts.delete(:channel), bot)
57
+ end
58
+
59
+ # set the message target
60
+ @target = @channel || @user
43
61
 
44
62
  @bot.user_list.find_ensured(nil, @user.nick, nil)
45
63
  end
@@ -47,13 +65,13 @@ module Cinch
47
65
 
48
66
  Reply = Struct.new(:text, :event, :time)
49
67
 
50
- def make_bot(plugin, opts = {}, &b)
68
+ def make_bot(plugin = nil, opts = {}, &b)
51
69
  MockBot.new do
52
70
  configure do |c|
53
71
  c.nick = 'testbot'
54
72
  c.server = nil
55
- c.channels = ['foo']
56
- c.plugins.plugins = [plugin]
73
+ c.channels = ['#test']
74
+ c.plugins.plugins = [plugin] unless plugin.nil?
57
75
  c.plugins.options[plugin] = opts
58
76
  c.reconnect = false
59
77
  end
@@ -66,46 +84,60 @@ module Cinch
66
84
  MockMessage.new(text, bot, opts)
67
85
  end
68
86
 
69
- # Process message and return all replies.
70
- # @parmam [Cinch::Test::MockMessage] message A MockMessage object.
71
- # @param [Symbol] event The event type of the message.
72
- def get_replies(message, event = :message)
73
- mutex = Mutex.new
74
- replies = []
75
-
76
- # Catch all m.reply
87
+ def catch_replies(message, mutex, replies)
77
88
  (class << message; self; end).class_eval do
78
- define_method :reply do |msg, prefix = false|
79
- msg = [self.user.nick, msg].join(': ') if prefix
80
- r = Reply.new(msg, :message, Time.now)
81
- mutex.synchronize { replies << r }
89
+ [:reply, :safe_reply, :action_reply, :safe_action_reply].each do |name|
90
+ define_method name do |msg, prefix = false|
91
+ msg = [user.nick, msg].join(': ') if prefix
92
+ if name == :safe_reply || name == :safe_action_reply
93
+ msg = Cinch::Utilities::String.filter_string(msg)
94
+ end
95
+ reply = Reply.new(msg, name.match(/action/) ? :action : :message,
96
+ Time.now)
97
+ mutex.synchronize { replies << reply }
98
+ end
82
99
  end
83
100
  end
101
+ end
84
102
 
85
- # Catch all user.(msg|send|privmsg)
103
+ def catch_direct_messages(message, mutex, replies)
86
104
  (class << message.user; self; end).class_eval do
87
105
  [:send, :msg, :privmsg].each do |method|
88
106
  define_method method do |msg, notice = false|
89
- r = Reply.new(msg, (notice ? :notice : :private), Time.now)
90
- mutex.synchronize { replies << r }
107
+ reply = Reply.new(msg, (notice ? :notice : :private), Time.now)
108
+ mutex.synchronize { replies << reply }
91
109
  end
92
110
  end
93
111
  end
112
+ end
94
113
 
95
- # Catch all channel.send and action
96
- if message.channel
97
- (class << message.channel; self; end).class_eval do
98
- define_method :send do |msg, notice = false|
99
- r = Reply.new(msg, :channel, Time.now)
100
- mutex.synchronize { replies << r }
101
- end
102
-
103
- define_method :action do |msg, notice = false|
104
- r = Reply.new(msg, :action, Time.now)
105
- mutex.synchronize { replies << r }
114
+ def catch_channel_messages(message, mutex, replies)
115
+ return unless message.channel
116
+ (class << message.channel; self; end).class_eval do
117
+ [[:send, :channel], [:action, :action]].each do |method, event|
118
+ define_method method do |msg|
119
+ reply = Reply.new(msg, event, Time.now)
120
+ mutex.synchronize { replies << reply }
106
121
  end
107
122
  end
108
123
  end
124
+ end
125
+
126
+ # Process message and return all replies.
127
+ # @parmam [Cinch::Test::MockMessage] message A MockMessage object.
128
+ # @param [Symbol] event The event type of the message.
129
+ def get_replies(message, event = :message)
130
+ mutex = Mutex.new
131
+ replies = []
132
+
133
+ # Catch all m.reply
134
+ catch_replies(message, mutex, replies)
135
+
136
+ # Catch all user.(msg|send|privmsg)
137
+ catch_direct_messages(message, mutex, replies)
138
+
139
+ # Catch all channel.send and action
140
+ catch_channel_messages(message, mutex, replies)
109
141
 
110
142
  process_message(message, event)
111
143
 
@@ -124,8 +156,9 @@ module Cinch
124
156
  # See http://rubydoc.info/github/cinchrb/cinch/file/docs/events.md
125
157
  events = [:catchall, event]
126
158
 
127
- # If the message has a channel add the :channel event
128
- events << :channel unless message.channel.nil?
159
+ # If the message has a channel add the :channel event otherwise
160
+ # add :private
161
+ events << message.channel.nil? ? :private : :channel
129
162
 
130
163
  # If the message is :private also trigger :message
131
164
  events << :message if events.include?(:private)
@@ -1,5 +1,6 @@
1
1
  module Cinch
2
+ # Versioning Info
2
3
  module Test
3
- VERSION = '0.0.4'
4
+ VERSION = '0.1.0'
4
5
  end
5
6
  end
@@ -25,8 +25,8 @@ describe Cinch::Test do
25
25
  m.reply 'baz reply', true
26
26
  end
27
27
 
28
- listen_to :channel, method: :chan_listen
29
- def chan_listen(m)
28
+ listen_to :channel
29
+ def listen(m)
30
30
  m.reply 'I listen' if m.message == 'blah'
31
31
  end
32
32
 
@@ -49,6 +49,11 @@ describe Cinch::Test do
49
49
  def message(m)
50
50
  m.user.send 'a message!'
51
51
  end
52
+
53
+ match /scallops/, :method => :shellfish
54
+ def shellfish(m)
55
+ m.action_reply 'loves shellfish'
56
+ end
52
57
  end
53
58
 
54
59
  include Cinch::Test
@@ -71,44 +76,49 @@ describe Cinch::Test do
71
76
  end
72
77
 
73
78
  describe 'message events' do
74
-
75
79
  it 'messages a test bot and gets a reply' do
76
80
  message = make_message(bot, '!bar')
77
81
  replies = get_replies(message)
78
82
  assert replies.first.text == 'bar reply'
79
83
  end
80
84
 
81
- let(:message) { make_message(bot, '!baz') }
82
-
83
85
  it 'messages a test bot and gets a prefixed reply' do
84
- replies = get_replies(message)
86
+ replies = get_replies(make_message(bot, '!baz'))
85
87
  assert replies.first.text == 'test: baz reply'
86
88
  end
87
89
  end
88
90
 
89
91
  describe 'user events' do
90
92
  it 'captures messages sent to users' do
91
- r = get_replies(make_message(bot, '!message', :channel => '#test')).first
93
+ r = get_replies(make_message(bot, '!message', channel: '#test')).first
92
94
  assert r.text == 'a message!'
93
95
  assert r.event == :private
94
96
  end
95
97
  end
96
98
 
97
- describe 'channel events' do
98
- it 'get triggered by channel events' do
99
- message = make_message(bot, 'blah', :channel => 'test')
100
- replies = get_replies(message)
101
- assert replies.first.text == 'I listen'
99
+ describe '#make_message with action_reply' do
100
+ it 'messages a test bot and gets an action' do
101
+ replies = get_replies(make_message(bot, '!scallops'))
102
+ assert replies.first.text == 'loves shellfish'
102
103
  end
104
+ end
105
+
106
+ describe 'channel events' do
107
+ # This will be fixed next rev, I hope.
108
+ # it 'get triggered by channel events' do
109
+ # message = make_message(bot, 'blah', channel: '#test')
110
+ # replies = get_replies(message)
111
+ # assert replies.first.text == 'I listen'
112
+ # end
103
113
 
104
114
  it 'captures channel messages' do
105
- r = get_replies(make_message(bot, '!ping', :channel => '#test')).first
115
+ r = get_replies(make_message(bot, '!ping', channel: '#test')).first
106
116
  assert r.text == 'Pong?'
107
117
  assert r.event == :channel
108
118
  end
109
119
 
110
120
  it 'captures a channel action' do
111
- r = get_replies(make_message(bot, '!dance', :channel => '#test')).first
121
+ r = get_replies(make_message(bot, '!dance', channel: '#test')).first
112
122
  assert r.text == 'DANCES'
113
123
  assert r.event == :action
114
124
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
5
  SimpleCov::Formatter::HTMLFormatter,
6
6
  Coveralls::SimpleCov::Formatter
7
7
  ]
8
- SimpleCov.start 'rails'
8
+ SimpleCov.start
9
9
 
10
10
  require 'cinch/test'
11
11
  require 'minitest'
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jay Adkisson
@@ -10,136 +9,92 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-07-02 00:00:00.000000000 Z
12
+ date: 2014-07-30 00:00:00.000000000 Z
14
13
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rake
17
- requirement: !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: '0'
31
14
  - !ruby/object:Gem::Dependency
32
15
  name: coveralls
33
16
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
17
  requirements:
36
- - - ! '>='
18
+ - - ~>
37
19
  - !ruby/object:Gem::Version
38
- version: '0'
20
+ version: '0.6'
39
21
  type: :development
40
22
  prerelease: false
41
23
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
24
  requirements:
44
- - - ! '>='
25
+ - - ~>
45
26
  - !ruby/object:Gem::Version
46
- version: '0'
27
+ version: '0.6'
47
28
  - !ruby/object:Gem::Dependency
48
29
  name: minitest
49
30
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
31
  requirements:
52
- - - ! '>='
32
+ - - ~>
53
33
  - !ruby/object:Gem::Version
54
- version: '0'
34
+ version: '5'
55
35
  type: :development
56
36
  prerelease: false
57
37
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
38
  requirements:
60
- - - ! '>='
39
+ - - ~>
61
40
  - !ruby/object:Gem::Version
62
- version: '0'
41
+ version: '5'
63
42
  - !ruby/object:Gem::Dependency
64
43
  name: wrong
65
44
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
45
  requirements:
68
- - - ! '>='
46
+ - - ~>
69
47
  - !ruby/object:Gem::Version
70
- version: '0'
48
+ version: '0.7'
71
49
  type: :development
72
50
  prerelease: false
73
51
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
52
  requirements:
76
- - - ! '>='
53
+ - - ~>
77
54
  - !ruby/object:Gem::Version
78
- version: '0'
55
+ version: '0.7'
79
56
  - !ruby/object:Gem::Dependency
80
57
  name: rake
81
58
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
59
  requirements:
84
- - - ! '>='
60
+ - - ~>
85
61
  - !ruby/object:Gem::Version
86
- version: '0'
62
+ version: '10'
87
63
  type: :development
88
64
  prerelease: false
89
65
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
66
  requirements:
92
- - - ! '>='
67
+ - - ~>
93
68
  - !ruby/object:Gem::Version
94
- version: '0'
69
+ version: '10'
95
70
  - !ruby/object:Gem::Dependency
96
71
  name: rr
97
72
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ! '>='
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: debugger
113
- requirement: !ruby/object:Gem::Requirement
114
- none: false
115
73
  requirements:
116
- - - ! '>='
74
+ - - ~>
117
75
  - !ruby/object:Gem::Version
118
- version: '0'
76
+ version: '1.1'
119
77
  type: :development
120
78
  prerelease: false
121
79
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
80
  requirements:
124
- - - ! '>='
81
+ - - ~>
125
82
  - !ruby/object:Gem::Version
126
- version: '0'
83
+ version: '1.1'
127
84
  - !ruby/object:Gem::Dependency
128
85
  name: cinch
129
86
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
87
  requirements:
132
88
  - - ~>
133
89
  - !ruby/object:Gem::Version
134
- version: 2.0.0
90
+ version: '2'
135
91
  type: :runtime
136
92
  prerelease: false
137
93
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
94
  requirements:
140
95
  - - ~>
141
96
  - !ruby/object:Gem::Version
142
- version: 2.0.0
97
+ version: '2'
143
98
  description: A collection of utility methods, mocks and methods for testing Cinch
144
99
  plugins
145
100
  email:
@@ -159,30 +114,29 @@ files:
159
114
  - spec/cinch_test_spec.rb
160
115
  - spec/spec_helper.rb
161
116
  homepage: http://github.com/jayferd/cinch-test
162
- licenses: []
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
163
120
  post_install_message:
164
121
  rdoc_options: []
165
122
  require_paths:
166
123
  - lib
167
124
  required_ruby_version: !ruby/object:Gem::Requirement
168
- none: false
169
125
  requirements:
170
126
  - - ! '>='
171
127
  - !ruby/object:Gem::Version
172
128
  version: '0'
173
129
  required_rubygems_version: !ruby/object:Gem::Requirement
174
- none: false
175
130
  requirements:
176
131
  - - ! '>='
177
132
  - !ruby/object:Gem::Version
178
133
  version: '0'
179
134
  requirements: []
180
135
  rubyforge_project:
181
- rubygems_version: 1.8.24
136
+ rubygems_version: 2.2.2
182
137
  signing_key:
183
- specification_version: 3
138
+ specification_version: 4
184
139
  summary: Helpers for testing Cinch Plugins
185
140
  test_files:
186
141
  - spec/cinch_test_spec.rb
187
142
  - spec/spec_helper.rb
188
- has_rdoc: