chatterbot 0.2.0

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.
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Chatterbot::Reply" do
4
+ it "calls require_login" do
5
+ bot = test_bot
6
+ #bot = Chatterbot::Bot.new
7
+ bot.should_receive(:require_login).and_return(false)
8
+ bot.replies
9
+ end
10
+
11
+ # it "calls update_since_id" do
12
+ # bot = Chatterbot::Bot.new
13
+ # bot.should_receive(:require_login).and_return(true)
14
+ # bot.stub!(:client).and_return(fake_replies(100))
15
+ # bot.should_receive(:update_since_id).with({'results' => []})
16
+
17
+ # bot.replies
18
+ # end
19
+
20
+ it "iterates results" do
21
+ #bot = Chatterbot::Bot.new
22
+ bot = test_bot
23
+ bot.should_receive(:require_login).and_return(true)
24
+ bot.stub!(:client).and_return(fake_replies(100, 3))
25
+
26
+ bot.should_receive(:update_since_id).exactly(3).times
27
+
28
+ indexes = []
29
+ bot.replies do |x|
30
+ indexes << x[:index]
31
+ end
32
+
33
+ indexes.should == [1,2,3]
34
+ end
35
+
36
+ it "checks blacklist" do
37
+ bot = test_bot
38
+ # bot = Chatterbot::Bot.new
39
+ bot.should_receive(:require_login).and_return(true)
40
+ bot.stub!(:client).and_return(fake_replies(100, 3))
41
+
42
+ bot.should_receive(:update_since_id).exactly(2).times
43
+
44
+ bot.stub!(:on_blacklist?).and_return(true, false)
45
+
46
+ indexes = []
47
+ bot.replies do |x|
48
+ indexes << x[:index]
49
+ end
50
+
51
+ indexes.should == [2,3]
52
+ end
53
+
54
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Chatterbot::Search" do
4
+ it "calls search" do
5
+ bot = Chatterbot::Bot.new
6
+ bot.should_receive(:search)
7
+ bot.search("foo")
8
+ end
9
+
10
+ it "calls init_client" do
11
+ bot = test_bot
12
+ bot.should_receive(:init_client).and_return(false)
13
+ bot.search("foo")
14
+ end
15
+
16
+ it "calls update_since_id" do
17
+ bot = test_bot
18
+
19
+ bot.stub!(:client).and_return(fake_search(100))
20
+ bot.should_receive(:update_since_id).with({'max_id' => 100, 'results' => []})
21
+
22
+ bot.search("foo")
23
+ end
24
+
25
+ it "accepts multiple searches at once" do
26
+ bot = test_bot
27
+ #bot = Chatterbot::Bot.new
28
+
29
+ bot.stub!(:client).and_return(fake_search(100))
30
+ bot.client.should_receive(:search).with("foo", {:since_id => 1})
31
+ bot.client.should_receive(:search).with("bar", {:since_id => 1})
32
+
33
+ bot.search(["foo", "bar"])
34
+ end
35
+
36
+ it "accepts a single search query" do
37
+ bot = test_bot
38
+
39
+ bot.stub!(:client).and_return(fake_search(100))
40
+ bot.client.should_receive(:search).with("foo", {:since_id => 1})
41
+
42
+ bot.search("foo")
43
+ end
44
+
45
+ it "iterates results" do
46
+ bot = test_bot
47
+ bot.stub!(:client).and_return(fake_search(100, 3))
48
+ indexes = []
49
+
50
+ bot.search("foo") do |x|
51
+ indexes << x[:index]
52
+ end
53
+
54
+ indexes.should == [1,2,3]
55
+ end
56
+
57
+ it "checks blacklist" do
58
+ bot = test_bot
59
+ # bot = Chatterbot::Bot.new
60
+ bot.stub!(:client).and_return(fake_search(100, 3))
61
+
62
+ bot.stub!(:on_blacklist?).and_return(true, false)
63
+
64
+ indexes = []
65
+ bot.search("foo") do |x|
66
+ indexes << x[:index]
67
+ end
68
+
69
+ indexes.should == [2,3]
70
+ end
71
+
72
+ end
@@ -0,0 +1,52 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'bundler/setup'
5
+ Bundler.require
6
+
7
+ require 'rspec'
8
+ require 'chatterbot'
9
+
10
+ require "twitter_oauth"
11
+
12
+
13
+ require 'tempfile'
14
+ require 'sqlite3'
15
+
16
+
17
+ # Requires supporting files with custom matchers and macros, etc,
18
+ # in ./support/ and its subdirectories.
19
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
20
+
21
+
22
+ def test_bot
23
+ bot = Chatterbot::Bot.new
24
+ bot.stub!(:load_config).and_return({})
25
+ bot
26
+ end
27
+
28
+ def fake_search(max_id = 100, result_count = 0)
29
+ mock(TwitterOAuth::Client,
30
+ {
31
+ :search => {
32
+ 'max_id' => max_id,
33
+ 'results' => 1.upto(result_count).collect { |i| fake_tweet(i) }
34
+ }
35
+ }
36
+ )
37
+ end
38
+
39
+ def fake_replies(max_id = 100, result_count = 0)
40
+ mock(TwitterOAuth::Client,
41
+ {
42
+ :replies => 1.upto(result_count).collect { |i| fake_tweet(i) }
43
+ }
44
+ )
45
+ end
46
+
47
+ def fake_tweet(index)
48
+ {
49
+ :from_user => "chatterbot",
50
+ :index => index
51
+ }
52
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Chatterbot::Tweet" do
4
+ describe "#tweet" do
5
+ before(:each) do
6
+ @bot = test_bot
7
+ end
8
+
9
+ it "calls require_login when tweeting" do
10
+ @bot.should_receive(:require_login).and_return(false)
11
+ @bot.tweet "tweet test!"
12
+ end
13
+
14
+ it "calls client.update with the right values" do
15
+ bot = test_bot
16
+
17
+ bot.should_receive(:require_login).and_return(true)
18
+ bot.stub!(:client).and_return(mock(TwitterOAuth::Client))
19
+
20
+ bot.stub!(:debug_mode?).and_return(false)
21
+
22
+ test_str = "test!"
23
+ bot.client.should_receive(:update).with(test_str, {})
24
+ bot.tweet test_str
25
+ end
26
+
27
+ it "doesn't tweet when debug_mode? is set" do
28
+ bot = test_bot
29
+
30
+ bot.should_receive(:require_login).and_return(true)
31
+ bot.stub!(:client).and_return(mock(TwitterOAuth::Client))
32
+
33
+ bot.stub!(:debug_mode?).and_return(true)
34
+
35
+ bot.client.should_not_receive(:update)
36
+ bot.tweet "no tweet!"
37
+ end
38
+ end
39
+
40
+ describe "#reply" do
41
+ it "calls require_login when replying" do
42
+ bot = test_bot
43
+ bot.should_receive(:require_login).and_return(false)
44
+ bot.reply "reply test!", {"id" => 100}
45
+ end
46
+
47
+ it "calls client.update with the right values" do
48
+ bot = test_bot
49
+ bot.should_receive(:require_login).and_return(true)
50
+ bot.stub!(:client).and_return(mock(TwitterOAuth::Client))
51
+
52
+ bot.stub!(:debug_mode?).and_return(false)
53
+
54
+ test_str = "test!"
55
+
56
+ s = {
57
+ 'id' => 100
58
+ }
59
+ bot.client.should_receive(:update).with(test_str, {:in_reply_to_status_id => 100})
60
+ bot.reply test_str, s
61
+ end
62
+
63
+
64
+ it "doesn't reply when debug_mode? is set" do
65
+ bot = test_bot
66
+ bot.should_receive(:require_login).and_return(true)
67
+ bot.stub!(:client).and_return(mock(TwitterOAuth::Client))
68
+
69
+ bot.stub!(:debug_mode?).and_return(true)
70
+
71
+ bot.client.should_not_receive(:update)
72
+ bot.reply "no reply test!", {"id" => 100}
73
+ end
74
+ end
75
+
76
+ end
data/specs.watchr ADDED
@@ -0,0 +1,60 @@
1
+ # Run me with:
2
+ #
3
+ # $ watchr specs.watchr
4
+
5
+ # --------------------------------------------------
6
+ # Convenience Methods
7
+ # --------------------------------------------------
8
+ def all_spec_files
9
+ Dir['spec/**/*_spec.rb']
10
+ end
11
+
12
+ def run_spec_matching(thing_to_match)
13
+ matches = all_spec_files.grep(/#{thing_to_match}/i)
14
+ if matches.empty?
15
+ puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}"
16
+ else
17
+ run matches.join(' ')
18
+ end
19
+ end
20
+
21
+ def run(files_to_run)
22
+ puts("Running: #{files_to_run}")
23
+ system("clear;rspec -cfs #{files_to_run}")
24
+ no_int_for_you
25
+ end
26
+
27
+ def run_all_specs
28
+ run(all_spec_files.join(' '))
29
+ end
30
+
31
+ # --------------------------------------------------
32
+ # Watchr Rules
33
+ # --------------------------------------------------
34
+ watch('^spec/(.*)_spec\.rb') { |m| run_spec_matching(m[1]) }
35
+ #watch('^spec/controllers/(.*)_spec\.rb') { |m| run_spec_matching(m[1]) }
36
+
37
+ watch("^lib/chatterbot/(.*)\.rb") { |m| run_spec_matching(m[1]) }
38
+ #watch('^spec/spec_helper\.rb') { run_all_specs }
39
+
40
+ # --------------------------------------------------
41
+ # Signal Handling
42
+ # --------------------------------------------------
43
+
44
+ def no_int_for_you
45
+ @sent_an_int = nil
46
+ end
47
+
48
+ Signal.trap 'INT' do
49
+ if @sent_an_int then
50
+ puts " A second INT? Ok, I get the message. Shutting down now."
51
+ exit
52
+ else
53
+ puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
54
+ @sent_an_int = true
55
+ Kernel.sleep 1.5
56
+ run_all_specs
57
+ end
58
+ end
59
+
60
+ run_all_specs
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chatterbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Colin Mitchell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-05-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: twitter_oauth
16
+ requirement: &12468800 !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: *12468800
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ requirement: &12468300 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *12468300
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &12467820 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *12467820
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: &12467340 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *12467340
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &12466860 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *12466860
69
+ - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ requirement: &12466380 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *12466380
80
+ - !ruby/object:Gem::Dependency
81
+ name: watchr
82
+ requirement: &12465900 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *12465900
91
+ description: A framework for writing bots that run on Twitter. Comes with a simple
92
+ DSL for easy coding.
93
+ email: colin@muffinlabs.com
94
+ executables:
95
+ - chatterbot-blacklist
96
+ extensions: []
97
+ extra_rdoc_files: []
98
+ files:
99
+ - .document
100
+ - .gitignore
101
+ - Gemfile
102
+ - LICENSE.txt
103
+ - README.rdoc
104
+ - Rakefile
105
+ - bin/chatterbot-blacklist
106
+ - chatterbot.gemspec
107
+ - examples/class_bot.rb
108
+ - examples/config.yml.example
109
+ - examples/dsl_test.rb
110
+ - examples/echoes_bot.rb
111
+ - lib/chatterbot.rb
112
+ - lib/chatterbot/blacklist.rb
113
+ - lib/chatterbot/bot.rb
114
+ - lib/chatterbot/client.rb
115
+ - lib/chatterbot/config.rb
116
+ - lib/chatterbot/db.rb
117
+ - lib/chatterbot/dsl.rb
118
+ - lib/chatterbot/helpers.rb
119
+ - lib/chatterbot/logging.rb
120
+ - lib/chatterbot/reply.rb
121
+ - lib/chatterbot/search.rb
122
+ - lib/chatterbot/tweet.rb
123
+ - lib/chatterbot/version.rb
124
+ - spec/blacklist_spec.rb
125
+ - spec/bot_spec.rb
126
+ - spec/client_spec.rb
127
+ - spec/config_spec.rb
128
+ - spec/db_spec.rb
129
+ - spec/dsl_spec.rb
130
+ - spec/helpers_spec.rb
131
+ - spec/logging_spec.rb
132
+ - spec/reply_spec.rb
133
+ - spec/search_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/tweet_spec.rb
136
+ - specs.watchr
137
+ homepage: http://github.com/muffinista/chatterbot
138
+ licenses:
139
+ - WTFDBAL
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project: chatterbot
158
+ rubygems_version: 1.8.3
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: A framework for writing Twitter bots
162
+ test_files: []