testingbot 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -2
  3. data/LICENSE +1 -1
  4. data/README.md +137 -0
  5. data/bin/testingbot +4 -3
  6. data/lib/testingbot.rb +1 -5
  7. data/lib/testingbot/api.rb +91 -15
  8. data/lib/testingbot/version.rb +1 -1
  9. data/spec/integration/api_spec.rb +21 -15
  10. data/spec/spec_helper.rb +6 -3
  11. data/testingbot.gemspec +3 -3
  12. metadata +7 -52
  13. data/README.rdoc +0 -237
  14. data/examples/android.rb +0 -14
  15. data/examples/capybara.rb +0 -22
  16. data/examples/capybara_multiple_browsers.rb +0 -38
  17. data/examples/cucumber/README.rdoc +0 -15
  18. data/examples/cucumber/Rakefile +0 -20
  19. data/examples/cucumber/features/support/env.rb +0 -13
  20. data/examples/cucumber/features/youtube.feature +0 -10
  21. data/examples/cucumber/features/youtube_steps.rb +0 -15
  22. data/examples/test_rspec.rb +0 -17
  23. data/examples/test_rspec1.rb +0 -36
  24. data/examples/test_unit.rb +0 -30
  25. data/lib/testingbot/capybara.rb +0 -66
  26. data/lib/testingbot/config.rb +0 -125
  27. data/lib/testingbot/cucumber.rb +0 -35
  28. data/lib/testingbot/hooks.rb +0 -284
  29. data/lib/testingbot/jasmine.rb +0 -29
  30. data/lib/testingbot/jasmine/README.rdoc +0 -16
  31. data/lib/testingbot/jasmine/Rakefile +0 -35
  32. data/lib/testingbot/jasmine/public/javascripts/Player.js +0 -22
  33. data/lib/testingbot/jasmine/public/javascripts/Song.js +0 -7
  34. data/lib/testingbot/jasmine/runner.rb +0 -4
  35. data/lib/testingbot/jasmine/spec/javascripts/PlayerSpec.js +0 -58
  36. data/lib/testingbot/jasmine/spec/javascripts/helpers/SpecHelper.js +0 -9
  37. data/lib/testingbot/jasmine/spec/javascripts/support/jasmine.yml +0 -73
  38. data/lib/testingbot/jasmine/test/Rakefile +0 -9
  39. data/lib/testingbot/jasmine/test/public/javascripts/Player.js +0 -22
  40. data/lib/testingbot/jasmine/test/public/javascripts/Song.js +0 -7
  41. data/lib/testingbot/jasmine/test/spec/javascripts/PlayerSpec.js +0 -58
  42. data/lib/testingbot/jasmine/test/spec/javascripts/helpers/SpecHelper.js +0 -9
  43. data/lib/testingbot/jasmine/test/spec/javascripts/support/jasmine.yml +0 -73
  44. data/lib/testingbot/selenium.rb +0 -127
  45. data/lib/testingbot/tunnel.rb +0 -104
  46. data/spec/integration/selenium1_spec.rb +0 -53
  47. data/spec/integration/selenium2_spec.rb +0 -60
  48. data/spec/integration/tunnel_spec.rb +0 -84
  49. data/spec/unit/api_spec.rb +0 -17
  50. data/spec/unit/config_spec.rb +0 -73
  51. data/spec/unit/tunnel_spec.rb +0 -41
  52. data/vendor/Testingbot-Tunnel.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87a1ad54759fec9b5b5f8d61ee9701937b578b30
4
- data.tar.gz: ebf7766a47b4cb88fd3ac8881bdac927fa8cb97a
3
+ metadata.gz: 8aa6c0651947729f8124cb6b37c2c2d06a1fc623
4
+ data.tar.gz: c70cbfddb932e5cb39f19e186c63efd468e945ec
5
5
  SHA512:
6
- metadata.gz: 0d5593c04195e0e342376a496bcbc933d758cdd3a3196f00eb08a3efc29ff4ee4a16ccff165d4d0ef79ce543ace22b7eae23d289d975843f47a21222fde3a445
7
- data.tar.gz: 4d42d1999609784aaac998ab2a8279e85d0e0c22ce79f9510d0a36fae1adc7ed155351cc91edbf78a13db84550272100cbb3ad6dcf262bc161fff36c970d8228
6
+ metadata.gz: 44e00e76b7afb646894a7dda5c70fbc33c5dec05a25dc9a638969cb87a70e2971571c35777fd737c24ddd98126ada1d9fb507b53cfd9b9462c0cb630298595ac
7
+ data.tar.gz: 8a774bbca0819f5af90fcc5a640361f84272638f73cdc3e848f614899d5eb7b59072c0a54585899fb18ca8a0634b3152e575ae49b195ee7ae3104dd4a17e7b09
@@ -3,5 +3,4 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.1
6
- before_script: echo "travis:rocks" > ~/.testingbot
7
- script: bundle exec rspec -P "spec/unit/*.rb"
6
+ script: bundle exec rake spec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 TestingBot
1
+ Copyright (c) TestingBot
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,137 @@
1
+ [![Build Status](https://travis-ci.org/testingbot/testingbot_ruby.png)](https://travis-ci.org/testingbot/testingbot_ruby)
2
+
3
+ # Testingbot-Ruby
4
+
5
+ This is the TestingBot Ruby client which makes it easy to
6
+ interact with the [TestingBot API](https://testingbot.com/support/api)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'testingbot'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install testingbot
21
+
22
+
23
+ ## Configuration
24
+
25
+ You'll need a [TestingBot account](https://testingbot.com). TestingBot offers free trials.
26
+
27
+ ## Setup
28
+
29
+ Once you have a TestingBot account, you can retrieve your unique TestingBot Key and Secret from the [TestingBot dashboard](https://testingbot.com/members)
30
+
31
+ ## Usage
32
+
33
+ ```ruby
34
+ @api = TestingBot::Api.new(key, secret)
35
+ ```
36
+
37
+ #### Environment variables
38
+ You can set these environment variables to authenticate with our API:
39
+
40
+ ```bash
41
+ TB_KEY=Your TestingBot Key
42
+ TB_SECRET=Your TestingBot Secret
43
+ ```
44
+
45
+ ### get_browsers
46
+ Gets a list of browsers you can test on
47
+
48
+ ```ruby
49
+ @api.get_browsers
50
+ ```
51
+
52
+ ### get_user_info
53
+ Gets your user information
54
+
55
+ ```ruby
56
+ @api.get_user_info
57
+ ```
58
+
59
+ ### update_user_info
60
+ Updates your user information
61
+
62
+ ```ruby
63
+ @api.update_user_info({ "first_name" => 'my name' })
64
+ ```
65
+
66
+ ### update_test
67
+ Updates a Test with Meta-data to display on TestingBot.
68
+ For example, you can specify the test name and whether the test succeeded or failed:
69
+
70
+ ```ruby
71
+ @api.update_test(webdriver_session_id, { :name => new_name, :success => true })
72
+ ```
73
+
74
+ ### get_test
75
+ Gets meta information for a test/job by passing in the WebDriver sessionID of the test you ran on TestingBot:
76
+
77
+ ```ruby
78
+ @api.get_test(webdriver_session_id)
79
+ ```
80
+
81
+ ### get_tests
82
+ Gets a list of previous jobs/tests that you ran on TestingBot, order by last run:
83
+
84
+ ```ruby
85
+ @api.get_tests(0, 10)
86
+ ```
87
+
88
+ ### delete_test
89
+ Deletes a test from TestingBot
90
+
91
+ ```ruby
92
+ @api.delete_test(webdriver_session_id)
93
+ ```
94
+
95
+ ### stop_test
96
+ Stops a running test on TestingBot
97
+
98
+ ```ruby
99
+ @api.stop_test(webdriver_session_id)
100
+ ```
101
+
102
+ ### get_builds
103
+ Gets a list of builds that you ran on TestingBot, order by last run:
104
+
105
+ ```ruby
106
+ @api.get_builds(0, 10)
107
+ ```
108
+
109
+ ### get_build
110
+ Gets a build from TestingBot
111
+
112
+ ```ruby
113
+ @api.get_build(build_identifier)
114
+ ```
115
+
116
+ ### get_tunnels
117
+ Gets a list of active tunnels for your account.
118
+
119
+ ```ruby
120
+ @api.get_tunnels
121
+ ```
122
+
123
+ ### get_authentication_hash
124
+ Calculates the hash necessary to share tests with other people
125
+
126
+ ```ruby
127
+ @api.get_authentication_hash(identifier)
128
+ ```
129
+
130
+ ## Contributing
131
+
132
+ 1. Fork this repository
133
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
134
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
135
+ 4. Push to the branch (`git push origin my-new-feature`)
136
+ 5. Create new Pull Request
137
+
@@ -4,8 +4,9 @@ if ARGV.any?
4
4
  api_key, api_secret = ARGV.first.split(':')
5
5
  else
6
6
 
7
- p "This utility will help you set up your system to use testingbot.com's infrastructure."
8
- p "Once you have entered your api key and secret you will be ready to use our grid"
7
+ p "This utility will help you set up your system to use TestingBot's infrastructure."
8
+ p "Once you have entered your API key and secret you will be ready to use our grid"
9
+ p "You can get these credentials from the TestingBot dashboard: https://testingbot.com/members"
9
10
 
10
11
  p "Please enter your testingbot API KEY:"
11
12
  api_key = gets.chomp
@@ -15,4 +16,4 @@ end
15
16
 
16
17
  File.open(File.expand_path("~/.testingbot"), 'w') {|f| f.write("#{api_key}:#{api_secret}") }
17
18
 
18
- p "Your system is now ready to use testingbot.com's grid infrastructure."
19
+ p "Your system is now ready to use TestingBot's grid infrastructure."
@@ -1,5 +1 @@
1
- require "testingbot/version"
2
- require "testingbot/config"
3
- require "testingbot/selenium"
4
- require "testingbot/api"
5
- require "testingbot/hooks"
1
+ require "testingbot/api"
@@ -6,16 +6,36 @@ module TestingBot
6
6
  VERSION = 1
7
7
  API_URL = "https://api.testingbot.com"
8
8
 
9
- attr_reader :config
9
+ attr_reader :key, :secret, :options
10
+
11
+ def initialize(key = nil, secret = nil, options = {})
12
+ @key = key
13
+ @secret = secret
14
+ @options = {
15
+ :debug => false
16
+ }.merge(options)
17
+ if @key.nil? || @secret.nil?
18
+ cached_credentials = load_config_file
19
+ @key, @secret = cached_credentials unless cached_credentials.nil?
20
+ end
21
+
22
+ if @key.nil? || @secret.nil?
23
+ @key = ENV["TB_KEY"] if ENV["TB_KEY"]
24
+ @secret = ENV["TB_SECRET"] if ENV["TB_SECRET"]
25
+ end
10
26
 
11
- def initialize(opts = {})
12
- @config = TestingBot::Config.new(opts)
27
+ raise "Please supply a TestingBot Key" if @key.nil?
28
+ raise "Please supply a TestingBot Secret" if @secret.nil?
13
29
  end
14
30
 
15
31
  def get_user_info
16
32
  get("/user")
17
33
  end
18
34
 
35
+ def get_browsers
36
+ get("/browsers")
37
+ end
38
+
19
39
  def update_user_info(params = {})
20
40
  new_params = {}
21
41
  params.keys.each do |key|
@@ -29,7 +49,7 @@ module TestingBot
29
49
  get("/tests?offset=#{offset}&count=#{count}")
30
50
  end
31
51
 
32
- def get_single_test(test_id)
52
+ def get_test(test_id)
33
53
  get("/tests/#{test_id}")
34
54
  end
35
55
 
@@ -47,38 +67,83 @@ module TestingBot
47
67
  response["success"]
48
68
  end
49
69
 
70
+ def stop_test(test_id)
71
+ response = put("/tests/#{test_id}/stop")
72
+ response["success"]
73
+ end
74
+
75
+ def get_builds(offset = 0, count = 10)
76
+ get("/builds?offset=#{offset}&count=#{count}")
77
+ end
78
+
79
+ def get_build(build_identifier)
80
+ get("/builds/#{build_identifier}")
81
+ end
82
+
83
+ def get_tunnels
84
+ get("/tunnel/list")
85
+ end
86
+
87
+ def get_authentication_hash(identifier)
88
+ Digest::MD5.hexdigest("#{@key}:#{@secret}:#{identifier}")
89
+ end
90
+
50
91
  private
51
92
 
93
+ def load_config_file
94
+ is_windows = false
95
+
96
+ begin
97
+ require 'rbconfig'
98
+ is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
99
+ rescue
100
+ is_windows = (RUBY_PLATFORM =~ /w.*32/) || (ENV["OS"] && ENV["OS"] == "Windows_NT")
101
+ end
102
+
103
+ if is_windows
104
+ config_file = "#{ENV['HOMEDRIVE']}\\.testingbot"
105
+ else
106
+ config_file = File.expand_path("#{Dir.home}/.testingbot")
107
+ end
108
+
109
+ if File.exists?(config_file)
110
+ str = File.open(config_file) { |f| f.readline }.chomp
111
+ return str.split(':')
112
+ end
113
+
114
+ return nil
115
+ end
116
+
52
117
  def get(url)
53
118
  uri = URI(API_URL + '/v' + VERSION.to_s + url)
54
119
  req = Net::HTTP::Get.new(uri.request_uri)
55
- req.basic_auth @config[:client_key], @config[:client_secret]
120
+ req.basic_auth @key, @secret
56
121
  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) {|http|
57
122
  http.request(req)
58
123
  }
59
- p res.body
60
124
 
61
125
  parsed = JSON.parse(res.body)
62
-
63
- if !parsed["error"].nil? && !parsed["error"].empty?
126
+ p parsed if @options[:debug]
127
+
128
+ if !parsed.is_a?(Array) && !parsed["error"].nil? && !parsed["error"].empty?
64
129
  raise parsed["error"]
65
130
  end
66
-
67
131
  parsed
68
132
  end
69
133
 
70
134
  def put(url, params = {})
71
135
  uri = URI(API_URL + '/v' + VERSION.to_s + url)
72
136
  req = Net::HTTP::Put.new(uri.request_uri)
73
- req.basic_auth @config[:client_key], @config[:client_secret]
137
+ req.basic_auth @key, @secret
74
138
  req.set_form_data(params)
75
139
  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) {|http|
76
140
  http.request(req)
77
141
  }
78
142
 
79
143
  parsed = JSON.parse(res.body)
144
+ p parsed if @options[:debug]
80
145
 
81
- if !parsed["error"].nil? && !parsed["error"].empty?
146
+ if !parsed.is_a?(Array) && !parsed["error"].nil? && !parsed["error"].empty?
82
147
  raise parsed["error"]
83
148
  end
84
149
 
@@ -88,7 +153,7 @@ module TestingBot
88
153
  def delete(url, params = {})
89
154
  uri = URI(API_URL + '/v' + VERSION.to_s + url)
90
155
  req = Net::HTTP::Delete.new(uri.request_uri)
91
- req.basic_auth @config[:client_key], @config[:client_secret]
156
+ req.basic_auth @key, @secret
92
157
  req.set_form_data(params)
93
158
  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) {|http|
94
159
  http.request(req)
@@ -96,7 +161,9 @@ module TestingBot
96
161
 
97
162
  parsed = JSON.parse(res.body)
98
163
 
99
- if !parsed["error"].nil? && !parsed["error"].empty?
164
+ p parsed if @options[:debug]
165
+
166
+ if !parsed.is_a?(Array) && !parsed["error"].nil? && !parsed["error"].empty?
100
167
  raise parsed["error"]
101
168
  end
102
169
 
@@ -107,8 +174,17 @@ module TestingBot
107
174
  url = URI.parse(API_URL + '/v' + VERSION + url)
108
175
  http = Net::HTTP.new(url.host, url.port)
109
176
  http.use_ssl = true
110
- http.basic_auth @config[:client_key], @config[:client_secret]
111
- response = http.post(url.path, params.map { |k, v| "#{k.to_s}=#{v}" }.join("&"))
177
+ http.basic_auth @key, @secret
178
+ res = http.post(url.path, params.map { |k, v| "#{k.to_s}=#{v}" }.join("&"))
179
+ parsed = JSON.parse(res.body)
180
+
181
+ p parsed if @options[:debug]
182
+
183
+ if !parsed.is_a?(Array) && !parsed["error"].nil? && !parsed["error"].empty?
184
+ raise parsed["error"]
185
+ end
186
+
187
+ parsed
112
188
  end
113
189
  end
114
190
  end
@@ -1,3 +1,3 @@
1
1
  module Testingbot
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -4,23 +4,22 @@ require 'rspec'
4
4
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
5
5
 
6
6
  describe "Testingbot Api" do
7
-
8
7
  context "the API should return valid user information" do
9
8
  it "should return info for the current user" do
10
- @api = TestingBot::Api.new()
9
+ @api = TestingBot::Api.new
11
10
  @api.get_user_info.should_not be_empty
12
11
  @api.get_user_info["first_name"].should_not be_empty
13
12
  end
14
13
 
15
14
  it "should raise an error when wrong credentials are provided" do
16
- @api = TestingBot::Api.new({ :client_key => "bogus", :client_secret => "false" })
15
+ @api = TestingBot::Api.new("bogus", "false")
17
16
  lambda { @api.get_user_info }.should raise_error(RuntimeError, /^401 Unauthorized/)
18
17
  end
19
18
  end
20
19
 
21
20
  context "updating my user info via the API should work" do
22
21
  it "should allow me to update my own user info" do
23
- @api = TestingBot::Api.new()
22
+ @api = TestingBot::Api.new
24
23
  new_name = rand(36**9).to_s(36)
25
24
  @api.update_user_info({ "first_name" => new_name }).should == true
26
25
  @api.get_user_info["first_name"].should == new_name
@@ -29,59 +28,66 @@ describe "Testingbot Api" do
29
28
 
30
29
  context "retrieve my own tests" do
31
30
  it "should retrieve a list of my own tests" do
32
- @api = TestingBot::Api.new()
31
+ @api = TestingBot::Api.new
33
32
  @api.get_tests.include?("data").should == true
34
33
  end
35
34
 
36
35
  it "should provide info for a specific test" do
37
- @api = TestingBot::Api.new()
36
+ @api = TestingBot::Api.new
38
37
  data = @api.get_tests["data"]
39
38
  if data.length > 0
40
39
  test_id = data.first["id"]
41
40
 
42
- single_test = @api.get_single_test(test_id)
41
+ single_test = @api.get_test(test_id)
43
42
  single_test["id"].should == test_id
44
43
  end
45
44
  end
46
45
 
47
46
  it "should fail when trying to access a test that is not mine" do
48
- @api = TestingBot::Api.new()
49
- lambda { @api.get_single_test(123423423423423) }.should raise_error(RuntimeError, /^404 Not Found./)
47
+ @api = TestingBot::Api.new
48
+ lambda { @api.get_test(123423423423423) }.should raise_error(RuntimeError, /^404 Not Found./)
50
49
  end
51
50
  end
52
51
 
53
52
  context "update a test" do
54
53
  it "should update a test of mine" do
55
- @api = TestingBot::Api.new()
54
+ @api = TestingBot::Api.new
56
55
  data = @api.get_tests["data"]
57
56
  if data.length > 0
58
57
  test_id = data.first["id"]
59
58
  new_name = rand(36**9).to_s(36)
60
59
  @api.update_test(test_id, { :name => new_name }).should == true
61
- single_test = @api.get_single_test(test_id)
60
+ single_test = @api.get_test(test_id)
62
61
  single_test["name"].should == new_name
63
62
  end
64
63
  end
65
64
 
66
65
  it "should not update a test that is not mine" do
67
- @api = TestingBot::Api.new()
66
+ @api = TestingBot::Api.new
68
67
  lambda { @api.update_test(123423423423423, { :name => "testingbot" }) }.should raise_error(RuntimeError, /^404 Not Found./)
69
68
  end
70
69
  end
71
70
 
71
+ context "fetch browsers" do
72
+ it "should fetch a list of browsers" do
73
+ @api = TestingBot::Api.new
74
+ @api.get_browsers.should_not be_empty
75
+ end
76
+ end
77
+
72
78
  context "delete a test" do
73
79
  it "should delete a test of mine" do
74
- @api = TestingBot::Api.new()
80
+ @api = TestingBot::Api.new
75
81
  data = @api.get_tests["data"]
76
82
  if data.length > 0
77
83
  test_id = data.first["id"]
78
84
  @api.delete_test(test_id).should == true
79
- lambda { @api.get_single_test(test_id) }.should raise_error(RuntimeError, /^404 Not Found./)
85
+ lambda { @api.get_test(test_id) }.should raise_error(RuntimeError, /^404 Not Found./)
80
86
  end
81
87
  end
82
88
 
83
89
  it "should not delete a test that is not mine" do
84
- @api = TestingBot::Api.new()
90
+ @api = TestingBot::Api.new
85
91
  lambda { @api.delete_test(123423423423423) }.should raise_error(RuntimeError, /^404 Not Found./)
86
92
  end
87
93
  end