battle-on 0.0.3 → 0.0.4

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.
data/README.md CHANGED
@@ -23,7 +23,7 @@ Now you're ready to attack!
23
23
  When you're in the middle of game of Battleship you want to focus on
24
24
  your attack - we help you do that.
25
25
 
26
- First, require 'battle-on'
26
+ First, require 'battle_on'
27
27
 
28
28
  require 'battle_on'
29
29
 
@@ -3,12 +3,6 @@ require 'rest_client'
3
3
 
4
4
  module BattleOn
5
5
 
6
- #Start the game
7
- #
8
- #mandatory parameters
9
- #name: My Name
10
- #email: my@email.com
11
-
12
6
  class RegisterGame
13
7
  attr_reader :name, :email
14
8
 
@@ -17,7 +11,8 @@ module BattleOn
17
11
  end
18
12
 
19
13
  def initialize(name, email)
20
- @name, @email = name, email
14
+ @name = name or raise ArgumentError, "Missing your name"
15
+ @email = email or raise ArgumentError, "Missing your email"
21
16
  end
22
17
 
23
18
  def execute
@@ -2,17 +2,8 @@ require 'JSON'
2
2
 
3
3
  module BattleOn
4
4
 
5
- #mandatory parameters:
6
- #
7
- #game_id: this relates to the id Plaform45's API
8
- #provides when you launch your attack.
9
- #
10
- #and the attack the at you want to send
11
- #x and y as keys, for example
12
- #{:x => 4, :y => 5}
13
-
14
5
  class SendAttack
15
- attr_reader :game_id, :args, :x_axis, :y_axis
6
+ attr_reader :game_id, :args, :x, :y
16
7
 
17
8
  def self.execute(game_id, args)
18
9
  new(game_id, args).execute
@@ -20,8 +11,8 @@ module BattleOn
20
11
 
21
12
  def initialize(game_id, args)
22
13
  @game_id = game_id
23
- @x_axis = args[:x_axis] #get_x(args)
24
- @y_axis = args[:y_axis] #get_y(args)
14
+ @x = args[:x] or raise ArgumentError, "Must pass 'x' attack"
15
+ @y = args[:y] or raise ArgumentError, "Must pass 'y' attack"
25
16
  end
26
17
 
27
18
  def execute
@@ -35,13 +26,7 @@ module BattleOn
35
26
  end
36
27
 
37
28
  def attack_params
38
- { x: x_axis, y: y_axis, id: game_id}.to_json
39
- end
40
-
41
- def get_x(args)
42
- end
43
-
44
- def get_y(args)
29
+ { x: x, y: y, id: game_id}.to_json
45
30
  end
46
31
 
47
32
  end
@@ -1,3 +1,3 @@
1
1
  module BattleOn
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -50,5 +50,28 @@ describe BattleOn::RegisterGame do
50
50
  end
51
51
 
52
52
  end
53
+
54
+ context "request is formatted incorrectly" do
55
+
56
+ let(:name_only) { "henry thornton" }
57
+
58
+ context "email is missing" do
59
+
60
+ it "raises an ArgumentError" do
61
+ expect { begin_battle.execute(name_only, nil) }.to raise_error(ArgumentError, /Missing your email/)
62
+ end
63
+
64
+ end
65
+
66
+ let(:email_only) { "henry@thethornton.com" }
67
+
68
+ context "name is missing" do
69
+
70
+ it "raises an ArgumentError" do
71
+ expect { begin_battle.execute(nil, email_only) }.to raise_error(ArgumentError, /Missing your name/)
72
+ end
73
+
74
+ end
75
+ end
53
76
  end
54
77
  end
@@ -11,7 +11,7 @@ describe BattleOn::SendAttack do
11
11
  let(:coordinates) { {:x => 5, :y => 9} }
12
12
  let(:send_attack) { BattleOn::SendAttack }
13
13
 
14
- context "responds to the attack" do
14
+ context "attack is formatted correctly" do
15
15
 
16
16
  it "response is a hash" do
17
17
  #given
@@ -39,7 +39,7 @@ describe BattleOn::SendAttack do
39
39
  #expect
40
40
  response.should include("x")
41
41
  end
42
-
42
+
43
43
  it "response contains a 'y'" do
44
44
  #given
45
45
  stubbed_request
@@ -50,5 +50,29 @@ describe BattleOn::SendAttack do
50
50
  end
51
51
 
52
52
  end
53
+
54
+ context "attack is formatted incorrectly" do
55
+
56
+ let(:x_only) { {:x => 1} }
57
+
58
+ context "attack is missing 'y' coordinate" do
59
+
60
+ it "raises an ArgumentError" do
61
+ expect { send_attack.execute(game, x_only) }.to raise_error(ArgumentError, /Must pass 'y' attack/)
62
+ end
63
+
64
+ end
65
+
66
+ let(:y_only) { {:y => 1} }
67
+
68
+ context "attack is missing 'x' coordinate" do
69
+
70
+ it "raises an ArgumentError" do
71
+ expect { send_attack.execute(game, y_only) }.to raise_error(ArgumentError, /Must pass 'x' attack/)
72
+ end
73
+
74
+ end
75
+
76
+ end
53
77
  end
54
78
  end
@@ -1,7 +1,7 @@
1
1
  module SendAttackSpecHelper
2
2
 
3
3
  def stubbed_request
4
- stub_request(:post, "http://battle.platform45.com/nuke").with(:body => "{\"x\":null,\"y\":null,\"id\":100}", :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'28', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => { :status=>"hit", :x => 0, :y => 4 }.to_json, :headers => {})
4
+ stub_request(:post, "http://battle.platform45.com/nuke").with(:body => "{\"x\":5,\"y\":9,\"id\":100}", :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'22', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => {:status => "hit", :x => 0, :y => 4}.to_json, :headers => {})
5
5
  end
6
6
 
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: battle-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec