battle 0.0.1
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 +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +1 -0
- data/battle.gemspec +28 -0
- data/lib/battle/game.rb +98 -0
- data/lib/battle/ship.rb +11 -0
- data/lib/battle/version.rb +3 -0
- data/lib/battle.rb +35 -0
- data/spec/fixtures/error.json +1 -0
- data/spec/fixtures/grab_the_prize.json +1 -0
- data/spec/fixtures/loose.json +1 -0
- data/spec/fixtures/nuke_hit_battleship.json +1 -0
- data/spec/fixtures/nuke_miss.json +1 -0
- data/spec/fixtures/register.json +1 -0
- data/spec/lib/battle/game_spec.rb +235 -0
- data/spec/lib/battle/ship_spec.rb +19 -0
- data/spec/lib/battle_spec.rb +17 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c438f9982d66971b78a5695443b14e59c3c30fe4
|
4
|
+
data.tar.gz: a6bec87dde2f34c2779619b467717bf71a8c842e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25d92626cdf8adbaff5927caa1b5803aebe83e7877c56eb27668b00ecb261c280527eb370f2ab107c31522d18511a855ceb09f05b86ef95bd19452d76ac7fbea
|
7
|
+
data.tar.gz: 21b4f39ba4763e2a838543814733569e72bd02607efa30d6b9accf27874326b618d0add8dbe91c6d4ce7fefde2bb4d51ea816e4251f35d02f3c3630584b11087
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Vitaly Tatarintsev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Battle
|
2
|
+
|
3
|
+
This gem is extraction from my [Battle45](https://github.com/ck3g/battle45) project
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'battle'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install battle
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
# init the game
|
22
|
+
game = Battle::Game.new 'name', 'email@example.com'
|
23
|
+
# register your game and get game ID
|
24
|
+
game.register!
|
25
|
+
|
26
|
+
# Fight till victory
|
27
|
+
game.nuke 0, 0 # don't forget to change coordinates
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
I'm sorry but contribution aren't allowed here.
|
32
|
+
It's [developer challenge](http://battle.platform45.com/) you should develop it by yourself.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/battle.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'battle/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "battle"
|
8
|
+
spec.version = Battle::VERSION
|
9
|
+
spec.authors = ["Vitaly Tatarintsev"]
|
10
|
+
spec.email = ["Kalastiuz@gmail.com"]
|
11
|
+
spec.description = %q{Battle vs Platform45}
|
12
|
+
spec.summary = %q{Wrapper to Platform45 developer challenge API http://battle.platform45.com/}
|
13
|
+
spec.homepage = "http://github.com/ck3g/battle"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rest-client", "~> 1.6.7"
|
22
|
+
spec.add_dependency "json", "~> 1.7.7"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "webmock", "~> 1.9.0"
|
28
|
+
end
|
data/lib/battle/game.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
module Battle
|
2
|
+
class Game
|
3
|
+
attr_reader :name, :email, :id, :coords, :status, :ships, :prize,
|
4
|
+
:response
|
5
|
+
|
6
|
+
STATUSES = %w[start victory defeat]
|
7
|
+
|
8
|
+
def initialize(name, email)
|
9
|
+
@name = name
|
10
|
+
@email = email
|
11
|
+
@coords = [nil, nil]
|
12
|
+
@status = "init"
|
13
|
+
@ships = []
|
14
|
+
@response = {}
|
15
|
+
Battle.ships.each { |name| @ships << Ship.new(name) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def register!
|
19
|
+
raise PlayerNameNotSpecified if name.nil? || name.empty?
|
20
|
+
raise PlayerEmailNotSpecified if email.nil? || email.empty?
|
21
|
+
|
22
|
+
do_request REGISTER_URL, "name" => name, "email" => email
|
23
|
+
handle_register
|
24
|
+
|
25
|
+
response
|
26
|
+
end
|
27
|
+
|
28
|
+
def nuke(x, y)
|
29
|
+
raise GameNotStartedYetError if init?
|
30
|
+
raise GameAlreadyFinishedError if finished?
|
31
|
+
|
32
|
+
do_request NUKE_URL, id: id, x: x, y: y
|
33
|
+
handle_nuke
|
34
|
+
|
35
|
+
response
|
36
|
+
end
|
37
|
+
|
38
|
+
def init?
|
39
|
+
status == "init"
|
40
|
+
end
|
41
|
+
|
42
|
+
def finished?
|
43
|
+
status == "lost" || status == "victory"
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
STATUSES.each do |status|
|
48
|
+
define_method status do
|
49
|
+
@status = status
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def do_request(url, data)
|
54
|
+
options = { content_type: :json, accept: :json }
|
55
|
+
@response = JSON.parse RestClient.post(url, data.to_json, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def sink_ship(name)
|
59
|
+
ships.delete ships.find { |ship| ship.is? name }
|
60
|
+
end
|
61
|
+
|
62
|
+
def has_ships?
|
63
|
+
!ships.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
def won?
|
67
|
+
!response["prize"].nil? || !has_ships?
|
68
|
+
end
|
69
|
+
|
70
|
+
def handle_nuke
|
71
|
+
sink_ship response['sunk'] unless response['sunk'].nil?
|
72
|
+
handle_defeat
|
73
|
+
handle_victory
|
74
|
+
assign_coordinates
|
75
|
+
end
|
76
|
+
|
77
|
+
def handle_victory
|
78
|
+
if won?
|
79
|
+
victory
|
80
|
+
@prize = response['prize']
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def handle_defeat
|
85
|
+
defeat if response["game_status"] == "lost"
|
86
|
+
end
|
87
|
+
|
88
|
+
def handle_register
|
89
|
+
@id = response["id"]
|
90
|
+
assign_coordinates
|
91
|
+
start
|
92
|
+
end
|
93
|
+
|
94
|
+
def assign_coordinates
|
95
|
+
@coords = [response["x"], response["y"]]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/battle/ship.rb
ADDED
data/lib/battle.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest_client'
|
3
|
+
|
4
|
+
require "battle/version"
|
5
|
+
require 'battle/game'
|
6
|
+
require 'battle/ship'
|
7
|
+
|
8
|
+
module Battle
|
9
|
+
API_HOST = "http://battle.platform45.com"
|
10
|
+
REGISTER_URL = "#{ API_HOST }/register"
|
11
|
+
NUKE_URL = "#{ API_HOST }/nuke"
|
12
|
+
|
13
|
+
AVAILABLE_SHIPS = [
|
14
|
+
{ name: 'Carrier', amount: 1 },
|
15
|
+
{ name: 'Battleship', amount: 1 },
|
16
|
+
{ name: 'Destroyer', amount: 1 },
|
17
|
+
{ name: 'Submarine', amount: 2 },
|
18
|
+
{ name: 'Patrol Boat', amount: 2 }
|
19
|
+
]
|
20
|
+
|
21
|
+
class PlayerNameNotSpecified < StandardError; end
|
22
|
+
class PlayerEmailNotSpecified < StandardError; end
|
23
|
+
class GameNotStartedYetError < StandardError; end
|
24
|
+
class GameAlreadyFinishedError < StandardError; end
|
25
|
+
|
26
|
+
def self.ships
|
27
|
+
ships = []
|
28
|
+
AVAILABLE_SHIPS.each do |ship|
|
29
|
+
ship[:amount].times { ships << ship[:name] }
|
30
|
+
end
|
31
|
+
|
32
|
+
ships
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"error":"something went wrong"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"prize": "You've got the prize!"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"game_status":"lost"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"status":"hit", "sunk":"Battleship", "x":1, "y": 7}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"status":"miss", "x":0, "y":6}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"id":"2746", "x":7, "y":6}
|
@@ -0,0 +1,235 @@
|
|
1
|
+
require 'battle'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
|
4
|
+
describe Battle::Game do
|
5
|
+
def load_fixture(name)
|
6
|
+
File.open File.join("spec", "fixtures", "#{name}.json")
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:game) { Battle::Game.new("Bob", "bob@example.com") }
|
10
|
+
let(:headers) do
|
11
|
+
{ 'Accept'=>'application/json', 'Content-Type'=>'application/json' }
|
12
|
+
end
|
13
|
+
let(:register_response_body) { load_fixture "register" }
|
14
|
+
|
15
|
+
it "stores player name" do
|
16
|
+
expect(game.name).to eq "Bob"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "stores player email" do
|
20
|
+
expect(game.email).to eq "bob@example.com"
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'stores the ships' do
|
24
|
+
expect(game.ships.count).to eq 7
|
25
|
+
end
|
26
|
+
|
27
|
+
it "init the game" do
|
28
|
+
expect(game.status).to eq "init"
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#register!" do
|
32
|
+
|
33
|
+
context "when success" do
|
34
|
+
before do
|
35
|
+
body = "{\"name\":\"Bob\",\"email\":\"bob@example.com\"}"
|
36
|
+
stub_request(:post, "http://battle.platform45.com/register").
|
37
|
+
with(body: body, headers: headers).
|
38
|
+
to_return(status: 200, body: register_response_body, headers: {})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns game id and coordinates" do
|
42
|
+
expect(game.register!).to eq({ "id" => "2746", "x" => 7, "y" => 6 })
|
43
|
+
end
|
44
|
+
|
45
|
+
it "stores game id" do
|
46
|
+
expect { game.register! }.to change { game.id }.to "2746"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "sets last nuke coordinates" do
|
50
|
+
expect { game.register! }.to change { game.coords }.to [7, 6]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "begins the game" do
|
54
|
+
expect { game.register! }.to change { game.status }.to "start"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when name not specified" do
|
59
|
+
let(:game) { Battle::Game.new("", "bob@example.com") }
|
60
|
+
before do
|
61
|
+
body = "{\"name\":\"\",\"email\":\"bob@example.com\"}"
|
62
|
+
stub_request(:post, "http://battle.platform45.com/register").
|
63
|
+
with(body: body, headers: headers).
|
64
|
+
to_return(status: 400, body: register_response_body, headers: {})
|
65
|
+
end
|
66
|
+
|
67
|
+
it "raises the exception" do
|
68
|
+
expect { game.register! }.to raise_error Battle::PlayerNameNotSpecified
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when email not specified" do
|
73
|
+
let(:game) { Battle::Game.new("Bob", "") }
|
74
|
+
before do
|
75
|
+
body = "{\"name\":\"Bob\",\"email\":\"\"}"
|
76
|
+
stub_request(:post, "http://battle.platform45.com/register").
|
77
|
+
with(body: body, headers: headers).
|
78
|
+
to_return(status: 400, body: register_response_body, headers: {})
|
79
|
+
end
|
80
|
+
|
81
|
+
it "raises the exception" do
|
82
|
+
expect { game.register! }.to raise_error Battle::PlayerEmailNotSpecified
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#nuke' do
|
88
|
+
before do
|
89
|
+
body = "{\"name\":\"Bob\",\"email\":\"bob@example.com\"}"
|
90
|
+
stub_request(:post, "http://battle.platform45.com/register").
|
91
|
+
with(body: body, headers: headers).
|
92
|
+
to_return(status: 200, body: register_response_body, headers: {})
|
93
|
+
game.register!
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'changes last coordinates' do
|
97
|
+
body = "{\"id\":\"2746\",\"x\":5,\"y\":9}"
|
98
|
+
stub_request(:post, "http://battle.platform45.com/nuke").
|
99
|
+
with(body: body, headers: headers).
|
100
|
+
to_return(status: 200, body: load_fixture("nuke_miss"), headers: {})
|
101
|
+
|
102
|
+
expect { game.nuke(5, 9) }.to change { game.coords }.to [0, 6]
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'when miss' do
|
106
|
+
before do
|
107
|
+
body = "{\"id\":\"2746\",\"x\":5,\"y\":9}"
|
108
|
+
stub_request(:post, "http://battle.platform45.com/nuke").
|
109
|
+
with(body: body, headers: headers).
|
110
|
+
to_return(status: 200, body: load_fixture("nuke_miss"), headers: {})
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'launch the salvos' do
|
114
|
+
expect(game.nuke(5, 9)).to eq({ 'status' => 'miss', 'x' => 0, 'y' => 6 })
|
115
|
+
end
|
116
|
+
|
117
|
+
it "don't change game status" do
|
118
|
+
expect { game.nuke(5, 9) }.to_not change { game.status }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when hit battleship" do
|
123
|
+
before do
|
124
|
+
body = "{\"id\":\"2746\",\"x\":5,\"y\":9}"
|
125
|
+
stub_request(:post, "http://battle.platform45.com/nuke").
|
126
|
+
with(body: body, headers: headers).
|
127
|
+
to_return(status: 200, body: load_fixture("nuke_hit_battleship"), headers: {})
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'gets proper response' do
|
131
|
+
expect(game.nuke(5, 9)).to eq({ "status" => "hit",
|
132
|
+
"sunk" => "Battleship",
|
133
|
+
"x" => 1,
|
134
|
+
"y" => 7 })
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'decrease ships count' do
|
138
|
+
expect { game.nuke(5, 9) }.to change { game.ships.count }.by(-1)
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'when has ships on battlefield' do
|
142
|
+
it "don't change game status" do
|
143
|
+
expect { game.nuke(5, 9) }.to_not change { game.status }
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when it was last ship' do
|
148
|
+
before { game.stub(:has_ships?).and_return false }
|
149
|
+
it 'changes game status' do
|
150
|
+
expect { game.nuke(5, 9) }.to change { game.status }.to "victory"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "when loose" do
|
156
|
+
before do
|
157
|
+
body = "{\"id\":\"2746\",\"x\":5,\"y\":9}"
|
158
|
+
stub_request(:post, "http://battle.platform45.com/nuke").
|
159
|
+
with(body: body, headers: headers).
|
160
|
+
to_return(status: 200, body: load_fixture("loose"), headers: {})
|
161
|
+
end
|
162
|
+
|
163
|
+
it "changes game status" do
|
164
|
+
expect { game.nuke(5, 9) }.to change { game.status }.to 'defeat'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "when reach error" do
|
169
|
+
before do
|
170
|
+
body = "{\"id\":\"2746\",\"x\":5,\"y\":9}"
|
171
|
+
stub_request(:post, "http://battle.platform45.com/nuke").
|
172
|
+
with(body: body, headers: headers).
|
173
|
+
to_return(status: 200, body: load_fixture("error"), headers: {})
|
174
|
+
end
|
175
|
+
|
176
|
+
it "returns error message" do
|
177
|
+
expect(game.nuke(5, 9)).to eq({ "error" => "something went wrong" })
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "when grab the prize" do
|
182
|
+
before do
|
183
|
+
body = "{\"id\":\"2746\",\"x\":5,\"y\":9}"
|
184
|
+
stub_request(:post, "http://battle.platform45.com/nuke").
|
185
|
+
with(body: body, headers: headers).
|
186
|
+
to_return(status: 200, body: load_fixture("grab_the_prize"), headers: {})
|
187
|
+
end
|
188
|
+
|
189
|
+
it "changes the game status" do
|
190
|
+
expect { game.nuke(5, 9) }.to change { game.status }.to "victory"
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'changes game prize' do
|
194
|
+
expect {
|
195
|
+
game.nuke(5, 9)
|
196
|
+
}.to change { game.prize }.to "You've got the prize!"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context "when game not started" do
|
201
|
+
before do
|
202
|
+
game.stub(:status).and_return "init"
|
203
|
+
end
|
204
|
+
it "raises GameNotStartedYetError" do
|
205
|
+
expect { game.nuke(1, 2) }.to raise_error Battle::GameNotStartedYetError
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "when game finished" do
|
210
|
+
before do
|
211
|
+
game.should_receive(:finished?).and_return true
|
212
|
+
end
|
213
|
+
it "raises GameAlreadyFinishedError" do
|
214
|
+
expect { game.nuke(1, 2) }.to raise_error Battle::GameAlreadyFinishedError
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "#finished?" do
|
220
|
+
context "when status is init" do
|
221
|
+
before { game.stub(:status).and_return "init" }
|
222
|
+
it { expect(game.finished?).to be_false }
|
223
|
+
end
|
224
|
+
|
225
|
+
context "when status is lost" do
|
226
|
+
before { game.stub(:status).and_return "lost" }
|
227
|
+
it { expect(game.finished?).to be_true }
|
228
|
+
end
|
229
|
+
|
230
|
+
context "when status is victory" do
|
231
|
+
before { game.stub(:status).and_return "victory" }
|
232
|
+
it { expect(game.finished?).to be_true }
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'battle'
|
2
|
+
|
3
|
+
describe Battle::Ship do
|
4
|
+
let(:battleship) { Battle::Ship.new 'Battleship' }
|
5
|
+
|
6
|
+
it 'stores ship name' do
|
7
|
+
expect(battleship.name).to eq 'Battleship'
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#is?' do
|
11
|
+
context 'when ask if ship is Battleship' do
|
12
|
+
it { expect(battleship.is? 'Battleship').to be_true }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when ask if ship is Submarine' do
|
16
|
+
it { expect(battleship.is? 'Submarine').to be_false }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'battle'
|
2
|
+
|
3
|
+
describe Battle do
|
4
|
+
describe '.ships' do
|
5
|
+
it 'contains proper ships list' do
|
6
|
+
expect(Battle.ships).to eq [
|
7
|
+
'Carrier',
|
8
|
+
'Battleship',
|
9
|
+
'Destroyer',
|
10
|
+
'Submarine',
|
11
|
+
'Submarine',
|
12
|
+
'Patrol Boat',
|
13
|
+
'Patrol Boat'
|
14
|
+
]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: battle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vitaly Tatarintsev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.7.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.9.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.9.0
|
97
|
+
description: Battle vs Platform45
|
98
|
+
email:
|
99
|
+
- Kalastiuz@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- battle.gemspec
|
110
|
+
- lib/battle.rb
|
111
|
+
- lib/battle/game.rb
|
112
|
+
- lib/battle/ship.rb
|
113
|
+
- lib/battle/version.rb
|
114
|
+
- spec/fixtures/error.json
|
115
|
+
- spec/fixtures/grab_the_prize.json
|
116
|
+
- spec/fixtures/loose.json
|
117
|
+
- spec/fixtures/nuke_hit_battleship.json
|
118
|
+
- spec/fixtures/nuke_miss.json
|
119
|
+
- spec/fixtures/register.json
|
120
|
+
- spec/lib/battle/game_spec.rb
|
121
|
+
- spec/lib/battle/ship_spec.rb
|
122
|
+
- spec/lib/battle_spec.rb
|
123
|
+
homepage: http://github.com/ck3g/battle
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.0.0
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Wrapper to Platform45 developer challenge API http://battle.platform45.com/
|
147
|
+
test_files:
|
148
|
+
- spec/fixtures/error.json
|
149
|
+
- spec/fixtures/grab_the_prize.json
|
150
|
+
- spec/fixtures/loose.json
|
151
|
+
- spec/fixtures/nuke_hit_battleship.json
|
152
|
+
- spec/fixtures/nuke_miss.json
|
153
|
+
- spec/fixtures/register.json
|
154
|
+
- spec/lib/battle/game_spec.rb
|
155
|
+
- spec/lib/battle/ship_spec.rb
|
156
|
+
- spec/lib/battle_spec.rb
|