robut-rps 1.0.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
+ SHA1:
3
+ metadata.gz: 38f14ad9e1d58a79ac3e5de115a24540dc7379d9
4
+ data.tar.gz: a4a95d3b02537f2dded20393474f3e2cdf264cdb
5
+ SHA512:
6
+ metadata.gz: c85ce9764f7de1059e27a09bb2c2c45755f262463acc6199c06bdac8b3eab714f2a3e9ac020c923bad461d3c030bd80508306b6474feda0ff2fa29cfac41cf0a
7
+ data.tar.gz: b4950d09f9240b3e59c6fff02178971ef3157bf746b0d773afc431dbad7e9bb02082012716f40f41638cd678830885789c676b0cbd451c0ef5e5ae39f95e32af
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "robut", ">= 0.4"
7
+ gem "calc"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "simplecov"
13
+ gem "shoulda", ">= 0"
14
+ gem "rdoc", "~> 3.12"
15
+ gem "bundler", "~> 1.0"
16
+ gem "jeweler", "~> 2.0.0"
17
+ gem "mocha"
18
+ gem "test-unit"
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Richard Lynskey
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,21 @@
1
+ = robut-rps
2
+
3
+ A Rock Paper Scissors module for {Robut}[https://github.com/justinweiss/robut]
4
+
5
+ {<img src="https://badge.fury.io/rb/robut-rps.png" alt="Gem Version" />}[http://badge.fury.io/rb/robut-rps]
6
+
7
+ == Contributing to robut-rps
8
+
9
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
10
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
11
+ * Fork the project.
12
+ * Start a feature/bugfix branch.
13
+ * Commit and push until you are happy with your contribution.
14
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
15
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
16
+
17
+ == Copyright
18
+
19
+ Copyright (c) 2014 Richard Lynskey. See LICENSE.txt for
20
+ further details.
21
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "robut-rps"
18
+ gem.homepage = "http://github.com/richard4339/robut-rps"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A rock paper scissors plugin for robut}
21
+ gem.description = %Q{A rock paper scissors plugin for robut}
22
+ gem.email = "richard@mozor.net"
23
+ gem.authors = ["Richard Lynskey"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "robut-rps #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/lib/robut-rps.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'calc'
2
+
3
+ # Rock Paper Scissors
4
+ class Robut::Plugin::RockPaperScissors
5
+ include Robut::Plugin
6
+
7
+ def usage
8
+ ["#{at_nick} rps <rock|paper|scissors>"]
9
+ end
10
+
11
+ def handle(time, sender_nick, message)
12
+ if sent_to_me?(message)
13
+ words = words(message)
14
+
15
+ return unless words[0] == "rps" && (words[1] == "rock" || words[1] == "scissors" || words[1] == "paper")
16
+
17
+ answers = ["rock",
18
+ "paper",
19
+ "scissors"]
20
+ choice = answers[random(answers.length)]
21
+
22
+ if choice == words[1]
23
+ reply "We both threw #{choice}. It's a tie!"
24
+ return
25
+ end
26
+
27
+ win = false
28
+ win = true if choice == "rock" && words[1] == "paper"
29
+ win = true if choice == "paper" && words[1] == "scissors"
30
+ win = true if choice == "scissors" && words[1] == "rock"
31
+ reply("You threw #{words[1]} which beats #{choice}. You win!") if win
32
+ reply("I threw #{choice} which beats #{words[1]}. You lose!") unless win
33
+
34
+ end
35
+
36
+ end
37
+
38
+ def random(c)
39
+ rand(c)
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ require 'robut/storage/hash_store'
2
+
3
+ class Robut::ConnectionMock < Robut::Connection
4
+
5
+ attr_accessor :messages
6
+
7
+ def initialize(config = nil)
8
+ self.messages = []
9
+ self.config = config || self.class.config
10
+ self.store = Robut::Storage::HashStore
11
+ self.client = Jabber::Client.new ''
12
+ end
13
+
14
+ def connect
15
+ self.rooms = []
16
+ self
17
+ end
18
+
19
+ def reply(message, to)
20
+ self.messages << [message, to]
21
+ end
22
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'robut-rps'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,25 @@
1
+ require 'robut/storage/hash_store'
2
+
3
+ class Robut::PresenceMock < Robut::Room
4
+
5
+ def initialize(connection)
6
+ self.connection = connection
7
+ end
8
+
9
+ def replies
10
+ @replies ||= []
11
+ end
12
+
13
+ def reply(msg, to = nil)
14
+ replies << msg
15
+ end
16
+
17
+ def handle_message(plugins, time, nick, message)
18
+ messages << [time, nick, message]
19
+ end
20
+
21
+ def messages
22
+ @messages ||= []
23
+ end
24
+
25
+ end
@@ -0,0 +1,2 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
@@ -0,0 +1,9 @@
1
+ require 'robut'
2
+ require 'test/unit'
3
+ require 'presence_mock'
4
+ require 'connection_mock'
5
+
6
+ Robut::ConnectionMock.configure do |config|
7
+ config.nick = "Robut t. Robot"
8
+ config.mention_name = "robut"
9
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+ require 'robut'
3
+ require 'robut-rps'
4
+ require 'mocha/setup'
5
+
6
+ #random() = 0 -> "rock"
7
+ # 1 -> "paper"
8
+ # 2 -> "scissors"
9
+
10
+ class Robut::Plugin::RockPaperScissorsTest < Test::Unit::TestCase
11
+
12
+ def setup
13
+ @connection = Robut::ConnectionMock.new
14
+ @presence = Robut::PresenceMock.new(@connection)
15
+ @plugin = Robut::Plugin::RockPaperScissors.new(@presence)
16
+ end
17
+
18
+ def test_handle_rps_no_robut
19
+ @plugin.stubs(:random).returns(1)
20
+ @plugin.handle(Time.now, "John", "rps rock")
21
+ assert_equal( [], @plugin.reply_to.replies )
22
+ end
23
+
24
+ def test_handle_rps_no_guess
25
+ @plugin.stubs(:random).returns(1)
26
+ @plugin.handle(Time.now, "John", "@robut rps")
27
+ assert_equal( [], @plugin.reply_to.replies )
28
+ end
29
+
30
+ def test_handle_rps_invalid_guess
31
+ @plugin.stubs(:random).returns(1)
32
+ @plugin.handle(Time.now, "John", "@robut rps this isn't valid")
33
+ assert_equal( [], @plugin.reply_to.replies )
34
+ end
35
+
36
+ def test_handle_rps_tie_rock
37
+ @plugin.stubs(:random).returns(0)
38
+ @plugin.handle(Time.now, "John", "@robut rps rock")
39
+ assert_equal( ["We both threw rock. It's a tie!"], @plugin.reply_to.replies )
40
+ end
41
+
42
+ def test_handle_rps_tie_paper
43
+ @plugin.stubs(:random).returns(1)
44
+ @plugin.handle(Time.now, "John", "@robut rps paper")
45
+ assert_equal( ["We both threw paper. It's a tie!"], @plugin.reply_to.replies )
46
+ end
47
+
48
+ def test_handle_rps_tie_scissors
49
+ @plugin.stubs(:random).returns(2)
50
+ @plugin.handle(Time.now, "John", "@robut rps scissors")
51
+ assert_equal( ["We both threw scissors. It's a tie!"], @plugin.reply_to.replies )
52
+ end
53
+
54
+ def test_handle_rps_lose_rock_paper
55
+ @plugin.stubs(:random).returns(1)
56
+ @plugin.handle(Time.now, "John", "@robut rps rock")
57
+ assert_equal( ["I threw paper which beats rock. You lose!"], @plugin.reply_to.replies )
58
+ end
59
+
60
+ def test_handle_rps_win_rock_paper
61
+ @plugin.stubs(:random).returns(0)
62
+ @plugin.handle(Time.now, "John", "@robut rps paper")
63
+ assert_equal( ["You threw paper which beats rock. You win!"], @plugin.reply_to.replies )
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: robut-rps
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Lynskey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: robut
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: calc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: shoulda
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jeweler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: mocha
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: test-unit
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A rock paper scissors plugin for robut
140
+ email: richard@mozor.net
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files:
144
+ - LICENSE.txt
145
+ - README.rdoc
146
+ files:
147
+ - ".document"
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.rdoc
151
+ - Rakefile
152
+ - VERSION
153
+ - lib/robut-rps.rb
154
+ - test/connection_mock.rb
155
+ - test/helper.rb
156
+ - test/presence_mock.rb
157
+ - test/simplecov_helper.rb
158
+ - test/test_helper.rb
159
+ - test/test_robut-rps.rb
160
+ homepage: http://github.com/richard4339/robut-rps
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.4.2
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: A rock paper scissors plugin for robut
184
+ test_files: []