cognition 2.0.4 → 2.0.5
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +1 -2
- data/Rakefile +4 -4
- data/bin/console +14 -0
- data/bin/setup +5 -0
- data/cognition.gemspec +5 -5
- data/lib/cognition/bot.rb +26 -26
- data/lib/cognition/matcher.rb +2 -2
- data/lib/cognition/message.rb +2 -2
- data/lib/cognition/plugins/base.rb +19 -19
- data/lib/cognition/plugins/default.rb +7 -5
- data/lib/cognition/responder.rb +2 -2
- data/lib/cognition/version.rb +1 -1
- data/lib/cognition.rb +2 -2
- data/test/fixtures/hello.rb +19 -19
- data/test/test_cognition.rb +8 -8
- data/test/test_default_plugin.rb +2 -2
- data/test/test_helper.rb +5 -3
- data/test/test_matcher.rb +27 -27
- data/test/test_message.rb +6 -6
- data/test/test_plugin.rb +2 -2
- data/test/test_responder.rb +9 -9
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f69c16258ad17a29dd1f7ee7353d331b36c9a37
|
4
|
+
data.tar.gz: c4c31934035e95b8ce435bc7fd885e892e22c08a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f5d6226701ffe0397d560df2dd3ba32d4979cb04e216f6164d65120bcd7e16804dee9bbc7ded759cb07a698d785554ea6fd74ace914662d17a07022bd46c916
|
7
|
+
data.tar.gz: 383bfa407321bd36ab89f1bfb692aceed77f9ae917c2a36220c031dd08182e59347187aba4a8ce9375bcd31f79558ad52eee784f4f31cbad5b65b10ae8a62ce6
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -66,7 +66,7 @@ matches and logic that should be run:
|
|
66
66
|
```ruby
|
67
67
|
class Hello < Cognition::Plugins::Base
|
68
68
|
# Simple string based matcher. Must match *EXACTLY*
|
69
|
-
match 'hello',
|
69
|
+
match 'hello', :hello, help: { 'hello' => 'Returns Hello World' }
|
70
70
|
|
71
71
|
# Advanced Regexp based matcher. Capture groups are made available
|
72
72
|
# via MatchData in the matches method
|
@@ -74,7 +74,6 @@ class Hello < Cognition::Plugins::Base
|
|
74
74
|
'hello <name>' => 'Greets you by name!'
|
75
75
|
}
|
76
76
|
|
77
|
-
|
78
77
|
def hello(*)
|
79
78
|
'Hello World'
|
80
79
|
end
|
data/Rakefile
CHANGED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cognition"
|
5
|
+
|
6
|
+
puts "Get started with your Cognition bot by registering the 'Hello' test plugin!"
|
7
|
+
puts "> test_bot = Cognition::Bot.new"
|
8
|
+
puts '> require_relative "../test/fixtures/hello"'
|
9
|
+
puts "> test_bot.register(Hello)\n\n"
|
10
|
+
puts "Process commands with: "
|
11
|
+
puts "> test_bot.process('message')\n\n"
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/cognition.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "cognition/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "cognition"
|
8
8
|
spec.version = Cognition::VERSION
|
9
9
|
spec.authors = ["Nathan Anderson"]
|
10
10
|
spec.email = ["andnat@gmail.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage = "https://github.com/
|
11
|
+
spec.summary = "A rules engine for running commands."
|
12
|
+
spec.description = "Match text; run commands. Works great for building a chatbot!"
|
13
|
+
spec.homepage = "https://github.com/basecamp/cognition"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
data/lib/cognition/bot.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "cognition/message"
|
2
|
+
require "cognition/matcher"
|
3
|
+
require "cognition/responder"
|
4
|
+
require "cognition/plugins/base"
|
5
|
+
require "cognition/plugins/default"
|
6
6
|
|
7
7
|
module Cognition
|
8
8
|
class Bot
|
9
9
|
attr_accessor :plugins, :matchers
|
10
10
|
|
11
11
|
def initialize
|
12
|
-
# Default plugin, responds to
|
12
|
+
# Default plugin, responds to "ping" with "PONG" and provides help text
|
13
13
|
register(Cognition::Plugins::Default)
|
14
14
|
end
|
15
15
|
|
@@ -42,31 +42,31 @@ module Cognition
|
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
45
|
+
def process_msg(msg)
|
46
|
+
response = false
|
47
|
+
matchers.each do |matcher|
|
48
|
+
if matcher.attempt(msg)
|
49
|
+
response = matcher.response
|
50
|
+
break
|
52
51
|
end
|
53
|
-
response ? response : not_found(msg.command)
|
54
52
|
end
|
53
|
+
response ? response : not_found(msg.command)
|
54
|
+
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
def process_string(message, metadata = {})
|
57
|
+
process_msg(Cognition::Message.new(message.strip, metadata))
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
def matchers
|
61
|
+
plugins.flat_map(&:matchers).compact
|
62
|
+
end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
def plugins
|
65
|
+
@plugins ||= []
|
66
|
+
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
def not_found(message)
|
69
|
+
"No such command: #{message}\nUse 'help' for available commands!"
|
70
|
+
end
|
71
71
|
end
|
72
72
|
end
|
data/lib/cognition/matcher.rb
CHANGED
@@ -3,8 +3,8 @@ module Cognition
|
|
3
3
|
attr_reader :trigger, :action, :response, :help, :match_data
|
4
4
|
|
5
5
|
def initialize(trigger, options = {}, &action)
|
6
|
-
|
7
|
-
|
6
|
+
fail ArgumentError, "matcher must have a trigger" unless trigger
|
7
|
+
fail ArgumentError, "matcher must have a action" unless action
|
8
8
|
@trigger = trigger
|
9
9
|
@help = options[:help] ||= {}
|
10
10
|
@action = action
|
data/lib/cognition/message.rb
CHANGED
@@ -5,11 +5,11 @@ module Cognition
|
|
5
5
|
def initialize(command, metadata = {})
|
6
6
|
@command = command
|
7
7
|
@metadata = metadata
|
8
|
-
@responder = Cognition::Responder.new(metadata[
|
8
|
+
@responder = Cognition::Responder.new(metadata["callback_url"]) if metadata["callback_url"]
|
9
9
|
end
|
10
10
|
|
11
11
|
def reply(text)
|
12
|
-
return
|
12
|
+
return "No Callback URL provided" unless @responder
|
13
13
|
@responder.reply(text)
|
14
14
|
end
|
15
15
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "erb"
|
2
|
+
require "tilt"
|
3
|
+
require "cgi"
|
4
4
|
|
5
5
|
module Cognition
|
6
6
|
module Plugins
|
@@ -20,7 +20,7 @@ module Cognition
|
|
20
20
|
# subclass, since we can't use __FILE__ here, and have it use the
|
21
21
|
# subclass's location.
|
22
22
|
def self.inherited(plugin)
|
23
|
-
plugin.view_root = File.dirname(caller[0].split(
|
23
|
+
plugin.view_root = File.dirname(caller[0].split(":", 2).first)
|
24
24
|
end
|
25
25
|
|
26
26
|
attr_accessor :matchers, :bot
|
@@ -51,23 +51,23 @@ module Cognition
|
|
51
51
|
|
52
52
|
private
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def template_file(name, type, extension)
|
55
|
+
# Defaults to html ERB for now. Override when calling #render(path_to_file)
|
56
|
+
File.join(templates_path, "#{name}.#{type}.#{extension}")
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
def underscore(string)
|
60
|
+
word = string.to_s.gsub(/::/, "/")
|
61
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, "\1_\2")
|
62
|
+
word.gsub!(/([a-z\d])([A-Z])/, "\1_\2")
|
63
|
+
word.tr!("-", "_")
|
64
|
+
word.downcase!
|
65
|
+
word
|
66
|
+
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
def templates_path
|
69
|
+
File.expand_path("#{underscore(self.class.name)}/views", self.class.view_root)
|
70
|
+
end
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
module Cognition
|
2
2
|
module Plugins
|
3
3
|
class Default < Cognition::Plugins::Base
|
4
|
+
# rubocop:disable Lint/AmbiguousRegexpLiteral
|
4
5
|
match /^ping/i, :pong, help: {
|
5
|
-
|
6
|
+
"ping" => "Test if the endpoint is responding. Returns PONG."
|
6
7
|
}
|
7
8
|
|
8
9
|
match /^help\s*(?<command>.*)/i, :help, help: {
|
9
|
-
|
10
|
-
|
10
|
+
"help" => "Lists all commands with help",
|
11
|
+
"help <command>" => "Lists help for <command>"
|
11
12
|
}
|
13
|
+
# rubocop:enable Lint/AmbiguousRegexpLiteral
|
12
14
|
|
13
|
-
def pong(
|
14
|
-
|
15
|
+
def pong(*)
|
16
|
+
"PONG"
|
15
17
|
end
|
16
18
|
|
17
19
|
def help(msg, match_data = nil)
|
data/lib/cognition/responder.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "httparty"
|
2
2
|
module Cognition
|
3
3
|
class Responder
|
4
4
|
include HTTParty
|
@@ -11,7 +11,7 @@ module Cognition
|
|
11
11
|
|
12
12
|
def reply(text)
|
13
13
|
self.class.post(@uri, @options.merge(body: { content: text }))
|
14
|
-
rescue Timeout::Error
|
14
|
+
rescue Timeout::Error
|
15
15
|
"Request to #{@uri} timed out."
|
16
16
|
end
|
17
17
|
end
|
data/lib/cognition/version.rb
CHANGED
data/lib/cognition.rb
CHANGED
data/test/fixtures/hello.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "tilt/haml"
|
2
|
+
require "tilt/erb"
|
3
|
+
require "haml"
|
4
4
|
class Hello < Cognition::Plugins::Base
|
5
|
-
match
|
6
|
-
|
5
|
+
match "hello", :hello, help: {
|
6
|
+
"hello" => "Returns Hello World"
|
7
7
|
}
|
8
8
|
|
9
|
-
def hello(
|
10
|
-
|
9
|
+
def hello(*)
|
10
|
+
"Hello World"
|
11
11
|
end
|
12
12
|
|
13
|
-
def hi(
|
14
|
-
@message =
|
13
|
+
def hi(*)
|
14
|
+
@message = "Hi"
|
15
15
|
render
|
16
16
|
end
|
17
17
|
|
18
|
-
def hola(
|
19
|
-
@message =
|
20
|
-
render(template: File.expand_path(
|
18
|
+
def hola(*)
|
19
|
+
@message = "Hola"
|
20
|
+
render(template: File.expand_path("../hello/views/hola.haml", __FILE__))
|
21
21
|
end
|
22
22
|
|
23
|
-
def bonjour(
|
24
|
-
@message =
|
23
|
+
def bonjour(*)
|
24
|
+
@message = "Bonjour"
|
25
25
|
render(type: "text")
|
26
26
|
end
|
27
27
|
|
28
|
-
def hey(
|
29
|
-
@message =
|
28
|
+
def hey(*)
|
29
|
+
@message = "Hey"
|
30
30
|
render(extension: "haml")
|
31
31
|
end
|
32
32
|
|
33
|
-
def yo(
|
34
|
-
@message =
|
35
|
-
render(locals: {num_yos: 3})
|
33
|
+
def yo(*)
|
34
|
+
@message = "Yo"
|
35
|
+
render(locals: { num_yos: 3 })
|
36
36
|
end
|
37
37
|
end
|
data/test/test_cognition.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require_relative
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "cognition"
|
3
|
+
require_relative "fixtures/hello"
|
4
4
|
|
5
5
|
class CognitionTest < Minitest::Test
|
6
6
|
def setup
|
@@ -21,21 +21,21 @@ class CognitionTest < Minitest::Test
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_processes_messages
|
24
|
-
msg = Cognition::Message.new(
|
25
|
-
assert_equal
|
24
|
+
msg = Cognition::Message.new("ping")
|
25
|
+
assert_equal "PONG", @bot.process(msg)
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_processes_strings
|
29
|
-
assert_equal
|
29
|
+
assert_equal "PONG", @bot.process("ping")
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_processes_strings_with_metadata
|
33
|
-
assert_equal
|
33
|
+
assert_equal "PONG", @bot.process("ping", foo: "bar")
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_shows_help_if_no_matches
|
37
37
|
@bot.register(Hello)
|
38
|
-
msg = Cognition::Message.new(
|
38
|
+
msg = Cognition::Message.new("pong")
|
39
39
|
output = @bot.process(msg)
|
40
40
|
assert_match "No such command: pong\nUse 'help' for available commands!", output
|
41
41
|
end
|
data/test/test_default_plugin.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/test_matcher.rb
CHANGED
@@ -1,88 +1,88 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "cognition"
|
3
3
|
|
4
4
|
class MatcherTest < Minitest::Test
|
5
5
|
def test_raises_error_without_a_trigger
|
6
6
|
assert_raises ArgumentError do
|
7
|
-
_ = Cognition::Matcher.new(action:
|
7
|
+
_ = Cognition::Matcher.new(action: "foo")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_raises_error_without_an_action
|
12
12
|
assert_raises ArgumentError do
|
13
|
-
_ = Cognition::Matcher.new(trigger:
|
13
|
+
_ = Cognition::Matcher.new(trigger: "foo")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_matches_string
|
18
|
-
msg = Cognition::Message.new(
|
19
|
-
matcher = Cognition::Matcher.new(
|
18
|
+
msg = Cognition::Message.new("help")
|
19
|
+
matcher = Cognition::Matcher.new("help", {}, &proc {})
|
20
20
|
assert matcher.matches?(msg)
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_string_fails_with_invalid_message
|
24
|
-
msg = Cognition::Message.new(
|
25
|
-
matcher = Cognition::Matcher.new(
|
24
|
+
msg = Cognition::Message.new("Help")
|
25
|
+
matcher = Cognition::Matcher.new("help", {}, &proc {})
|
26
26
|
refute matcher.matches?(msg)
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_matches_regexp
|
30
|
-
msg = Cognition::Message.new(
|
31
|
-
matcher = Cognition::Matcher.new(/ping/, {}, &
|
30
|
+
msg = Cognition::Message.new("ping")
|
31
|
+
matcher = Cognition::Matcher.new(/ping/, {}, &proc {})
|
32
32
|
assert matcher.matches?(msg)
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_regexp_fails_with_invalid_message
|
36
|
-
msg = Cognition::Message.new(
|
37
|
-
matcher = Cognition::Matcher.new(/ping/, {}, &
|
36
|
+
msg = Cognition::Message.new("pink")
|
37
|
+
matcher = Cognition::Matcher.new(/ping/, {}, &proc {})
|
38
38
|
refute matcher.matches?(msg)
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_sets_response_on_attemp_if_matches
|
42
|
-
msg = Cognition::Message.new(
|
43
|
-
matcher = Cognition::Matcher.new(/ping/, {}, &
|
42
|
+
msg = Cognition::Message.new("ping")
|
43
|
+
matcher = Cognition::Matcher.new(/ping/, {}, &proc { "PONG" })
|
44
44
|
matcher.attempt(msg)
|
45
|
-
assert_equal
|
45
|
+
assert_equal "PONG", matcher.response
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_returns_false_on_attemp_if_no_match
|
49
|
-
msg = Cognition::Message.new(
|
50
|
-
matcher = Cognition::Matcher.new(/ping/, {}, &
|
49
|
+
msg = Cognition::Message.new("pink")
|
50
|
+
matcher = Cognition::Matcher.new(/ping/, {}, &proc { "PONG" })
|
51
51
|
refute matcher.attempt(msg)
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_sets_match_data
|
55
|
-
msg = Cognition::Message.new(
|
56
|
-
matcher = Cognition::Matcher.new(/hello\s*(?<name>.*)/, {}, &
|
55
|
+
msg = Cognition::Message.new("hello john")
|
56
|
+
matcher = Cognition::Matcher.new(/hello\s*(?<name>.*)/, {}, &proc { "PONG" })
|
57
57
|
matcher.matches?(msg)
|
58
58
|
assert_equal "john", matcher.match_data[:name]
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_captures_response
|
62
|
-
msg = Cognition::Message.new(
|
63
|
-
matcher = Cognition::Matcher.new(/hello\s*(?<name>.*)/, {}, &
|
62
|
+
msg = Cognition::Message.new("hello john")
|
63
|
+
matcher = Cognition::Matcher.new(/hello\s*(?<name>.*)/, {}, &proc(&method(:dummy_method)))
|
64
64
|
matcher.attempt(msg)
|
65
65
|
assert_equal "Hello john", matcher.response
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_only_sets_help_when_help_provided
|
69
|
-
matcher_without_help = Cognition::Matcher.new(/hello\s*(?<name>.*)/, {}, &
|
69
|
+
matcher_without_help = Cognition::Matcher.new(/hello\s*(?<name>.*)/, {}, &proc(&method(:dummy_method)))
|
70
70
|
assert_equal [], matcher_without_help.help
|
71
71
|
end
|
72
72
|
|
73
73
|
def test_sets_help
|
74
|
-
matcher_with_help = Cognition::Matcher.new(/hello\s*(?<name>.*)/, {help: {
|
75
|
-
assert_equal [
|
74
|
+
matcher_with_help = Cognition::Matcher.new(/hello\s*(?<name>.*)/, { help: { "hello" => "says hello" } }, &proc(&method(:dummy_method)))
|
75
|
+
assert_equal ["hello - says hello"], matcher_with_help.help
|
76
76
|
end
|
77
77
|
|
78
78
|
def test_returns_error_if_method_returns_an_error
|
79
|
-
msg = Cognition::Message.new(
|
80
|
-
matcher_with_error = Cognition::Matcher.new(/error/, &
|
79
|
+
msg = Cognition::Message.new("error")
|
80
|
+
matcher_with_error = Cognition::Matcher.new(/error/, &proc(&method(:error_method)))
|
81
81
|
assert matcher_with_error.attempt(msg).match("'error' found, but raised")
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
def dummy_method(
|
85
|
+
def dummy_method(_, match_data)
|
86
86
|
"Hello #{match_data['name']}"
|
87
87
|
end
|
88
88
|
|
data/test/test_message.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "cognition"
|
3
3
|
|
4
4
|
class CognitionTest < Minitest::Test
|
5
5
|
def test_sets_metadata
|
6
|
-
msg = Cognition::Message.new(
|
6
|
+
msg = Cognition::Message.new("test", user_id: 15, foo: "bar")
|
7
7
|
assert_equal 15, msg.metadata[:user_id]
|
8
|
-
assert_equal
|
8
|
+
assert_equal "bar", msg.metadata[:foo]
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_sets_responder_if_callback_url
|
12
|
-
msg = Cognition::Message.new(
|
12
|
+
msg = Cognition::Message.new("ping", "callback_url" => "http://foo.bar/")
|
13
13
|
assert_kind_of Cognition::Responder, msg.responder
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_no_responder_if_no_callback_url
|
17
|
-
msg = Cognition::Message.new(
|
17
|
+
msg = Cognition::Message.new("ping", user: { name: "foo", id: 123_456 })
|
18
18
|
refute msg.responder
|
19
19
|
end
|
20
20
|
end
|
data/test/test_plugin.rb
CHANGED
data/test/test_responder.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "cognition"
|
3
|
+
require "test_helper"
|
4
4
|
|
5
5
|
class ResponderTest < Minitest::Test
|
6
6
|
def test_sends_reply
|
7
|
-
stub_request(:any, "http://foo.bar/path")
|
8
|
-
to_return(status: 200)
|
9
|
-
responder = Cognition::Responder.new(
|
7
|
+
stub_request(:any, "http://foo.bar/path")
|
8
|
+
.to_return(status: 200)
|
9
|
+
responder = Cognition::Responder.new("http://foo.bar/path")
|
10
10
|
|
11
|
-
assert_equal 200, responder.reply(
|
11
|
+
assert_equal 200, responder.reply("foobar").code
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_handles_timeouts
|
15
15
|
stub_request(:any, "http://foo.bar/path").to_timeout
|
16
|
-
responder = Cognition::Responder.new(
|
16
|
+
responder = Cognition::Responder.new("http://foo.bar/path")
|
17
17
|
|
18
|
-
assert_equal
|
18
|
+
assert_equal "Request to http://foo.bar/path timed out.", responder.reply("foobar")
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cognition
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -111,7 +111,9 @@ dependencies:
|
|
111
111
|
description: Match text; run commands. Works great for building a chatbot!
|
112
112
|
email:
|
113
113
|
- andnat@gmail.com
|
114
|
-
executables:
|
114
|
+
executables:
|
115
|
+
- console
|
116
|
+
- setup
|
115
117
|
extensions: []
|
116
118
|
extra_rdoc_files: []
|
117
119
|
files:
|
@@ -120,6 +122,8 @@ files:
|
|
120
122
|
- LICENSE.txt
|
121
123
|
- README.md
|
122
124
|
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
123
127
|
- cognition.gemspec
|
124
128
|
- lib/cognition.rb
|
125
129
|
- lib/cognition/bot.rb
|
@@ -144,7 +148,7 @@ files:
|
|
144
148
|
- test/test_message.rb
|
145
149
|
- test/test_plugin.rb
|
146
150
|
- test/test_responder.rb
|
147
|
-
homepage: https://github.com/
|
151
|
+
homepage: https://github.com/basecamp/cognition
|
148
152
|
licenses:
|
149
153
|
- MIT
|
150
154
|
metadata: {}
|