cinch-test 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: c21cdd89e05e7ac6c64889d9ac5d5b8ed8087d74
4
- data.tar.gz: e0b20d4963cc2815719feed54221488839d01c1b
3
+ metadata.gz: ffa5c1ce20e4f337f9e1f4566ae8e26cf4dc0018
4
+ data.tar.gz: 60199f145b4f948f7891c45f2400867cb702e369
5
5
  SHA512:
6
- metadata.gz: 20b19201f0e9d5d6349f4c9bfe1f9354f94acf415aca3fb9dfa275f8ec3ba6d5c33cc98ce882ad72d7d288ba8f8ec300ab8263503a518f58ee673dd14f2fa088
7
- data.tar.gz: b791bdeda32f5c4206c7a567971c08191e4ef4e598f6c19f1fbecd0da6fc983eb6e04077afa319441ab117947493b1e9b7afdad261c99925c96eb134dfd46858
6
+ metadata.gz: bfd8b2b23ca8531736f584370e7534fb87a78ee7b55fa5825ef8b42ed49564dc5bb9186572b72a7beb9b495bdc544475019a038f524ace0fabeba844ddd16763
7
+ data.tar.gz: 9131e5744509a6ec3d9e53c3fe2c1eeb0d4e00fcead755592ee936dc83f63bfd8e23d57ba02b02611871da4b566053655c68ddbaf7e0237f4c244492695368a7
data/Rakefile CHANGED
@@ -1,9 +1,7 @@
1
- require 'rake'
2
- require 'rake/testtask'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
3
 
4
- Rake::TestTask.new do |t|
5
- t.test_files = Dir.glob('spec/**/*_spec.rb')
6
- t.libs.push 'spec'
7
- end
4
+ RSpec::Core::RakeTask.new
8
5
 
9
- task :default => :test
6
+ task :default => :spec
7
+ task :test => :spec
@@ -18,10 +18,10 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(/^(test|spec|features)\//)
19
19
  gem.require_paths = ['lib']
20
20
 
21
- gem.add_development_dependency 'coveralls', '~> 0.6'
22
- gem.add_development_dependency 'minitest', '~> 5'
23
- gem.add_development_dependency 'wrong', '~> 0.7'
21
+
24
22
  gem.add_development_dependency 'rake', '~> 10'
25
- gem.add_development_dependency 'rr', '~> 1.1'
23
+ gem.add_development_dependency 'rspec', '~> 3'
24
+ gem.add_development_dependency 'coveralls', '~> 0.7'
25
+
26
26
  gem.add_dependency 'cinch', '~> 2'
27
27
  end
@@ -144,24 +144,14 @@ module Cinch
144
144
  replies
145
145
  end
146
146
 
147
- private
148
-
149
147
  # Process message by dispatching it to the handlers
150
148
  # @param [Cinch::Test::MockMessage] message A MockMessage object.
151
149
  # @param [Symbol] event The event type of the message.
152
150
  def process_message(message, event)
153
151
  handlers = message.bot.handlers
154
152
 
155
- # Deal with secondary event types
156
- # See http://rubydoc.info/github/cinchrb/cinch/file/docs/events.md
157
- events = [:catchall, event]
158
-
159
- # If the message has a channel add the :channel event otherwise
160
- # add :private
161
- events << message.channel.nil? ? :private : :channel
162
-
163
- # If the message is :private also trigger :message
164
- events << :message if events.include?(:private)
153
+ # Get a list of applicable event types.
154
+ events = get_events(message, event)
165
155
 
166
156
  # Dispatch each of the events to the handlers
167
157
  events.each { |e| handlers.dispatch(e, message) }
@@ -172,5 +162,20 @@ module Cinch
172
162
  handler.thread_group.list.each(&:join)
173
163
  end
174
164
  end
165
+
166
+ def get_events(message, event)
167
+ # Deal with secondary event types
168
+ # See http://rubydoc.info/github/cinchrb/cinch/file/docs/events.md
169
+ events = event.is_a?(Array) ? [:catchall] + event : [:catchall, event]
170
+
171
+ # If the message has a channel add the :channel event otherwise
172
+ # add :private
173
+ events << (message.channel.nil? ? :private : :channel)
174
+
175
+ # If the message is :private also trigger :message
176
+ events << :message if events.include?(:private)
177
+
178
+ events
179
+ end
175
180
  end
176
181
  end
@@ -1,6 +1,6 @@
1
1
  module Cinch
2
2
  # Versioning Info
3
3
  module Test
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
6
6
  end
@@ -1,126 +1,81 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cinch::Test do
4
- class MyPlugin
5
- include Cinch::Plugin
4
+ include Cinch::Test
6
5
 
7
- attr_reader :foo
8
- def initialize(*)
9
- super
10
- @foo = config[:foo]
11
- end
6
+ before(:each) do
7
+ @bot = make_bot(MyPlugin, foo: 'foo_value')
8
+ end
12
9
 
13
- match /foo/, method: :foo
14
- def foo(m)
15
- m.reply "foo: #{@foo}"
10
+ describe 'Cinch::Test' do
11
+ it 'should add the :channel event to messages with a channel set' do
12
+ message = make_message(@bot, 'blah', channel: '#test')
13
+ expect(get_events(message, []))
14
+ .to include(:channel)
16
15
  end
16
+ end
17
17
 
18
- match /bar/, method: :bar
19
- def bar(m)
20
- m.reply 'bar reply'
18
+ describe 'Mock bot' do
19
+ it 'makes a test bot without a config' do
20
+ bot = make_bot(MyPlugin)
21
+ expect(bot).to be_instance_of(Cinch::Test::MockBot)
21
22
  end
22
23
 
23
- match /baz/, method: :baz
24
- def baz(m)
25
- m.reply 'baz reply', true
24
+ it 'makes a test bot with a config' do
25
+ expect(@bot).to be_instance_of(Cinch::Test::MockBot)
26
26
  end
27
27
 
28
- listen_to :channel
29
- def listen(m)
30
- m.reply 'I listen' if m.message == 'blah'
28
+ it 'makes a bot with config values available to the plugin' do
29
+ message = make_message(@bot, '!foo')
30
+ replies = get_replies(message)
31
+ expect(replies.first.text).to eq('foo: foo_value')
31
32
  end
33
+ end
32
34
 
33
- match /trout/, method: :action, react_on: :action
34
- def action(m)
35
- m.reply 'I hate fish'
35
+ describe 'Messages' do
36
+ it 'sent directly to a test bot get a logged reply' do
37
+ message = make_message(@bot, '!bar')
38
+ replies = get_replies(message)
39
+ expect(replies.first.text).to eq('bar reply')
36
40
  end
37
41
 
38
- match /ping/, method: :ping
39
- def ping(m)
40
- m.channel.send 'Pong?'
42
+ it 'sent directly to a test bot and can receive a prefixed reply' do
43
+ replies = get_replies(make_message(@bot, '!baz'))
44
+ expect(replies.first.text).to eq('test: baz reply')
41
45
  end
42
46
 
43
- match /dance/, method: :dance
44
- def dance(m)
45
- m.channel.action 'DANCES'
47
+ it 'sent to users are logged' do
48
+ r = get_replies(make_message(@bot, '!message', channel: '#test')).first
49
+ expect(r.text).to eq('a message!')
50
+ expect(r.event).to eq(:private)
46
51
  end
47
52
 
48
- match /message/, method: :message
49
- def message(m)
50
- m.user.send 'a message!'
53
+ it 'sent to a bot can be responded to with a logged action' do
54
+ replies = get_replies(make_message(@bot, '!scallops'))
55
+ expect(replies.first.text).to eq('loves shellfish')
51
56
  end
52
57
 
53
- match /scallops/, :method => :shellfish
54
- def shellfish(m)
55
- m.action_reply 'loves shellfish'
58
+ it 'should trigger listeners' do
59
+ message = make_message(@bot, 'blah', channel: '#test')
60
+ expect(get_replies(message)).to_not be_empty
56
61
  end
57
- end
58
-
59
- include Cinch::Test
60
62
 
61
- it 'makes a test bot without a config' do
62
- bot = make_bot(MyPlugin)
63
- assert bot.is_a?(Cinch::Bot)
64
- end
65
-
66
- let(:bot) { make_bot(MyPlugin, :foo => 'foo_value') }
67
-
68
- it 'makes a test bot with a config' do
69
- assert bot.is_a?(Cinch::Bot)
70
- end
71
-
72
- it 'makes a bot with config values available to the plugin' do
73
- message = make_message(bot, '!foo')
74
- replies = get_replies(message)
75
- assert replies.first.text == 'foo: foo_value'
76
- end
77
-
78
- describe 'message events' do
79
- it 'messages a test bot and gets a reply' do
80
- message = make_message(bot, '!bar')
63
+ it 'should trigger listeners and log the output text' do
64
+ message = make_message(@bot, 'blah', channel: '#test')
81
65
  replies = get_replies(message)
82
- assert replies.first.text == 'bar reply'
66
+ expect(replies.first.text).to eq('I listen')
83
67
  end
84
68
 
85
- it 'messages a test bot and gets a prefixed reply' do
86
- replies = get_replies(make_message(bot, '!baz'))
87
- assert replies.first.text == 'test: baz reply'
88
- end
89
- end
90
-
91
- describe 'user events' do
92
- it 'captures messages sent to users' do
93
- r = get_replies(make_message(bot, '!message', channel: '#test')).first
94
- assert r.text == 'a message!'
95
- assert r.event == :private
96
- end
97
- end
98
-
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'
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
113
-
114
- it 'captures channel messages' do
115
- r = get_replies(make_message(bot, '!ping', channel: '#test')).first
116
- assert r.text == 'Pong?'
117
- assert r.event == :channel
69
+ it 'should trigger in channels properly' do
70
+ r = get_replies(make_message(@bot, '!ping', channel: '#test')).first
71
+ expect(r.text).to eq('Pong?')
72
+ expect(r.event).to eq(:channel)
118
73
  end
119
74
 
120
- it 'captures a channel action' do
121
- r = get_replies(make_message(bot, '!dance', channel: '#test')).first
122
- assert r.text == 'DANCES'
123
- assert r.event == :action
75
+ it 'that are events should trigger properly' do
76
+ r = get_replies(make_message(@bot, '!dance', channel: '#test')).first
77
+ expect(r.text).to eq('DANCES')
78
+ expect(r.event).to eq(:action)
124
79
  end
125
80
  end
126
81
  end
@@ -0,0 +1,54 @@
1
+ class MyPlugin
2
+ include Cinch::Plugin
3
+
4
+ attr_reader :foo
5
+ def initialize(*)
6
+ super
7
+ @foo = config[:foo]
8
+ end
9
+
10
+ match /foo/, method: :foo
11
+ def foo(m)
12
+ m.reply "foo: #{@foo}"
13
+ end
14
+
15
+ match /bar/, method: :bar
16
+ def bar(m)
17
+ m.reply 'bar reply'
18
+ end
19
+
20
+ match /baz/, method: :baz
21
+ def baz(m)
22
+ m.reply 'baz reply', true
23
+ end
24
+
25
+ listen_to :channel
26
+ def listen(m)
27
+ m.reply 'I listen' if m.message == 'blah'
28
+ end
29
+
30
+ match /trout/, method: :action, react_on: :action
31
+ def action(m)
32
+ m.reply 'I hate fish'
33
+ end
34
+
35
+ match /ping/, method: :ping
36
+ def ping(m)
37
+ m.channel.send 'Pong?'
38
+ end
39
+
40
+ match /dance/, method: :dance
41
+ def dance(m)
42
+ m.channel.action 'DANCES'
43
+ end
44
+
45
+ match /message/, method: :message
46
+ def message(m)
47
+ m.user.send 'a message!'
48
+ end
49
+
50
+ match /scallops/, :method => :shellfish
51
+ def shellfish(m)
52
+ m.action_reply 'loves shellfish'
53
+ end
54
+ end
@@ -8,10 +8,4 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
8
  SimpleCov.start
9
9
 
10
10
  require 'cinch/test'
11
- require 'minitest'
12
- require 'minitest/autorun'
13
- require 'wrong/adapters/minitest'
14
- require 'rr'
15
-
16
- Wrong.config[:color] = true
17
-
11
+ require 'my_plugin'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Adkisson
@@ -9,38 +9,38 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-30 00:00:00.000000000 Z
12
+ date: 2014-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: coveralls
15
+ name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: '0.6'
20
+ version: '10'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: '0.6'
27
+ version: '10'
28
28
  - !ruby/object:Gem::Dependency
29
- name: minitest
29
+ name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: '5'
34
+ version: '3'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ~>
40
40
  - !ruby/object:Gem::Version
41
- version: '5'
41
+ version: '3'
42
42
  - !ruby/object:Gem::Dependency
43
- name: wrong
43
+ name: coveralls
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ~>
@@ -53,34 +53,6 @@ dependencies:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0.7'
56
- - !ruby/object:Gem::Dependency
57
- name: rake
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ~>
61
- - !ruby/object:Gem::Version
62
- version: '10'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: '10'
70
- - !ruby/object:Gem::Dependency
71
- name: rr
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ~>
75
- - !ruby/object:Gem::Version
76
- version: '1.1'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ~>
82
- - !ruby/object:Gem::Version
83
- version: '1.1'
84
56
  - !ruby/object:Gem::Dependency
85
57
  name: cinch
86
58
  requirement: !ruby/object:Gem::Requirement
@@ -112,6 +84,7 @@ files:
112
84
  - lib/cinch/test.rb
113
85
  - lib/cinch/test/version.rb
114
86
  - spec/cinch_test_spec.rb
87
+ - spec/my_plugin.rb
115
88
  - spec/spec_helper.rb
116
89
  homepage: http://github.com/jayferd/cinch-test
117
90
  licenses:
@@ -139,4 +112,5 @@ specification_version: 4
139
112
  summary: Helpers for testing Cinch Plugins
140
113
  test_files:
141
114
  - spec/cinch_test_spec.rb
115
+ - spec/my_plugin.rb
142
116
  - spec/spec_helper.rb