brazenhead 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,17 @@
1
1
  When /^I attempt to call a method that does not exist$/ do
2
- @driver.should_not_exist_at_all
2
+ begin
3
+ @driver.should_not_exist_at_all
4
+ rescue Exception => e
5
+ @last_exception = e
6
+ end
3
7
  end
4
8
 
5
9
  Then /^I should receive an internal server error$/ do
6
- @driver.last_response.code.should eq '500'
10
+ @last_exception.should_not be_nil
7
11
  end
8
12
 
9
13
  Then /^the exception should have detailed information$/ do
10
- json = JSON.parse(@driver.last_response.body)
14
+ json = JSON.parse(@last_exception.message)
11
15
  json["exception"].should match ".*CommandNotFoundException"
12
16
  json["errorMessage"].should match "The \\w+\\(.*\\) method was not found on .*Solo\\."
13
17
  end
@@ -14,9 +14,10 @@ module Brazenhead
14
14
  $stderr.puts "Failed to send the command #{message} #{retries} times..."
15
15
  raise
16
16
  end
17
+ raise Exception, @last_response.body unless @last_response.code == "200"
17
18
  @last_response
18
19
  end
19
-
20
+
20
21
  def stop
21
22
  http.post '/kill', ''
22
23
  end
@@ -30,6 +31,6 @@ module Brazenhead
30
31
  def http
31
32
  @http ||= Net::HTTP.new '127.0.0.1', 7777
32
33
  end
33
-
34
+
34
35
  end
35
36
  end
@@ -1,3 +1,3 @@
1
1
  module Brazenhead
2
- VERSION = "0.4"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -3,9 +3,13 @@ require 'spec_helper'
3
3
  describe Brazenhead::Device do
4
4
  let(:device) { Brazenhead::Device.new }
5
5
  let(:http_mock) { double("http_mock") }
6
+ let(:http_response) { double("http_response") }
6
7
 
7
8
  before(:each) do
8
9
  Net::HTTP.stub(:new).and_return(http_mock)
10
+ device.stub(:sleep)
11
+ http_mock.stub(:post).and_return(http_response)
12
+ http_response.stub(:code).and_return('200')
9
13
  end
10
14
 
11
15
  it "should retry the http call if it fails the first time" do
@@ -24,4 +28,10 @@ describe Brazenhead::Device do
24
28
  http_mock.should_receive(:post).with('/kill', '')
25
29
  device.stop
26
30
  end
31
+
32
+ it "should raise if the status code is not ok" do
33
+ http_response.should_receive(:code).and_return('500')
34
+ http_response.stub(:body).and_return("the error message")
35
+ expect { device.send "blah" }.to raise_error(Exception, "the error message")
36
+ end
27
37
  end
@@ -8,10 +8,13 @@ describe Brazenhead do
8
8
 
9
9
  let(:driver) { Driver.new }
10
10
  let(:http_mock) { double("http_mock") }
11
+ let(:http_response) { double("http_response").as_null_object }
11
12
 
12
13
  context "when calling a method directly on the module" do
13
14
  before(:each) do
14
15
  Net::HTTP.stub(:new).and_return(http_mock)
16
+ http_mock.stub(:post).and_return(http_response)
17
+ http_response.stub(:code).and_return('200')
15
18
  end
16
19
 
17
20
  it "should convert method name to camel case with first letter lowercase" do
@@ -26,7 +29,8 @@ describe Brazenhead do
26
29
  end
27
30
 
28
31
  it "should make the result of the call available for inspection" do
29
- http_mock.should_receive(:post).with('/', "commands=[{\"name\":\"fooBar\"}]").and_return("Success")
32
+ http_response.stub(:body).and_return("Success")
33
+ http_mock.should_receive(:post).with('/', "commands=[{\"name\":\"fooBar\"}]")
30
34
  result = driver.foo_bar
31
35
  driver.last_response.should == result
32
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brazenhead
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-20 00:00:00.000000000 Z
13
+ date: 2012-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: childprocess
@@ -67,7 +67,7 @@ dependencies:
67
67
  requirements:
68
68
  - - ! '>='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.5.2
70
+ version: 0.5.4
71
71
  type: :development
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -75,7 +75,7 @@ dependencies:
75
75
  requirements:
76
76
  - - ! '>='
77
77
  - !ruby/object:Gem::Version
78
- version: 0.5.2
78
+ version: 0.5.4
79
79
  description: Driver that accepts remote json requests and invokes methods inside Android
80
80
  emulator / device.
81
81
  email: