testingbot 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Testingbot
2
- VERSION = "0.0.9"
3
- end
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,88 @@
1
+ require "uri"
2
+ require "net/http"
3
+ require 'rspec'
4
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
5
+
6
+ describe "Testingbot Api" do
7
+
8
+ context "the API should return valid user information" do
9
+ it "should return info for the current user" do
10
+ @api = TestingBot::Api.new()
11
+ @api.get_user_info.should_not be_empty
12
+ @api.get_user_info["first_name"].should_not be_empty
13
+ end
14
+
15
+ it "should raise an error when wrong credentials are provided" do
16
+ @api = TestingBot::Api.new({ :client_key => "bogus", :client_secret => "false" })
17
+ lambda { @api.get_user_info }.should raise_error(RuntimeError, /^401 Unauthorized/)
18
+ end
19
+ end
20
+
21
+ context "updating my user info via the API should work" do
22
+ it "should allow me to update my own user info" do
23
+ @api = TestingBot::Api.new()
24
+ new_name = rand(36**9).to_s(36)
25
+ @api.update_user_info({ "first_name" => new_name }).should == true
26
+ @api.get_user_info["first_name"].should == new_name
27
+ end
28
+ end
29
+
30
+ context "retrieve my own tests" do
31
+ it "should retrieve a list of my own tests" do
32
+ @api = TestingBot::Api.new()
33
+ @api.get_tests.include?("data").should == true
34
+ end
35
+
36
+ it "should provide info for a specific test" do
37
+ @api = TestingBot::Api.new()
38
+ data = @api.get_tests["data"]
39
+ if data.length > 0
40
+ test_id = data.first["id"]
41
+
42
+ single_test = @api.get_single_test(test_id)
43
+ single_test["id"].should == test_id
44
+ end
45
+ end
46
+
47
+ 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./)
50
+ end
51
+ end
52
+
53
+ context "update a test" do
54
+ it "should update a test of mine" do
55
+ @api = TestingBot::Api.new()
56
+ data = @api.get_tests["data"]
57
+ if data.length > 0
58
+ test_id = data.first["id"]
59
+ new_name = rand(36**9).to_s(36)
60
+ @api.update_test(test_id, { :name => new_name }).should == true
61
+ single_test = @api.get_single_test(test_id)
62
+ single_test["name"].should == new_name
63
+ end
64
+ end
65
+
66
+ it "should not update a test that is not mine" do
67
+ @api = TestingBot::Api.new()
68
+ lambda { @api.update_test(123423423423423, { :name => "testingbot" }) }.should raise_error(RuntimeError, /^404 Not Found./)
69
+ end
70
+ end
71
+
72
+ context "delete a test" do
73
+ it "should delete a test of mine" do
74
+ @api = TestingBot::Api.new()
75
+ data = @api.get_tests["data"]
76
+ if data.length > 0
77
+ test_id = data.first["id"]
78
+ @api.delete_test(test_id).should == true
79
+ lambda { @api.get_single_test(test_id) }.should raise_error(RuntimeError, /^404 Not Found./)
80
+ end
81
+ end
82
+
83
+ it "should not delete a test that is not mine" do
84
+ @api = TestingBot::Api.new()
85
+ lambda { @api.delete_test(123423423423423) }.should raise_error(RuntimeError, /^404 Not Found./)
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,53 @@
1
+ require "uri"
2
+ require "net/http"
3
+ require 'rspec'
4
+
5
+ @@success = true
6
+ @@check_api = true
7
+
8
+ # disabled until RSpec2 has append_after support
9
+ # ::RSpec.configuration.after :each do
10
+ # if @@check_api
11
+ # api = TestingBot::Api.new
12
+ # single_test = api.get_single_test(@selenium_driver.session_id)
13
+ # single_test["success"].should eql(@@success)
14
+ # single_test["extra"].should eql("just a test")
15
+ # end
16
+ # end
17
+
18
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
19
+
20
+ describe "Selenium RC test" do
21
+
22
+ before(:all) do
23
+ @selenium_driver = Selenium::Client::Driver.new \
24
+ :browser => "firefox",
25
+ :url => "http://testingbot.com",
26
+ :timeout_in_second => 60,
27
+ :platform => "WINDOWS",
28
+ :version => "10"
29
+ end
30
+ before(:each) do
31
+ @selenium_driver.start_new_browser_session({ :extra => "just a test" })
32
+ end
33
+
34
+ after(:each) do
35
+ @selenium_driver.close_current_browser_session
36
+ end
37
+
38
+ context "Connect and run successfully to the TestingBot Grid with Selenium 1 (RC)" do
39
+ it "should be able to run an RC test successfully" do
40
+ @check_api = false
41
+ @selenium_driver.open "/"
42
+ @selenium_driver.text?("TestingBot").should be_true
43
+ end
44
+ end
45
+
46
+ context "Check that we report the test status back successfully" do
47
+ it "should send a success status to TestingBot upon success of the test" do
48
+ @check_api = true
49
+ @selenium_driver.open "/"
50
+ @selenium_driver.text?("TestingBot").should be_true
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,60 @@
1
+ require "uri"
2
+ require "net/http"
3
+ require 'rspec'
4
+
5
+ @@success = true
6
+ @@check_api = true
7
+
8
+ # disabled until RSpec2 has append_after support
9
+ # ::RSpec.configuration.after :each do
10
+ # if @@check_api
11
+ # api = TestingBot::Api.new
12
+ # single_test = api.get_single_test(@selenium_driver.session_id)
13
+ # single_test["success"].should eql(@@success)
14
+ # end
15
+ # end
16
+
17
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
18
+
19
+
20
+ TestingBot::config do |config|
21
+ config[:desired_capabilities] = { :browserName => "firefox", :version => 9, :platform => "WINDOWS" }
22
+ end
23
+
24
+ describe "Selenium WebDriver test" do
25
+
26
+ before(:all) do
27
+ @selenium_driver = TestingBot::SeleniumWebdriver.new
28
+ end
29
+
30
+ after(:each) do
31
+ @selenium_driver.stop
32
+ end
33
+
34
+ context "Connect and run successfully to the TestingBot Grid with Selenium 2" do
35
+ it "should be able to run an RC test successfully" do
36
+ @check_api = false
37
+ @selenium_driver.navigate.to "http://testingbot.com"
38
+ @selenium_driver.title.should match /^Selenium Testing/
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "Selenium WebDriver test API" do
44
+
45
+ before(:all) do
46
+ @selenium_driver = TestingBot::SeleniumWebdriver.new
47
+ end
48
+
49
+ after(:each) do
50
+ @selenium_driver.stop
51
+ end
52
+
53
+ context "Check that we report the test status back successfully" do
54
+ it "should send a success status to TestingBot upon success of the test" do
55
+ @check_api = true
56
+ @selenium_driver.navigate.to "http://testingbot.com"
57
+ @selenium_driver.title.should match /^Selenium Testing/
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,84 @@
1
+ require 'rspec'
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe "Testingbot Tunnel" do
5
+ after :each do
6
+ @tunnel.stop if @tunnel.is_connected?
7
+ TestingBot.reset_config!
8
+ end
9
+
10
+ context "the tunnel should start and block until it's ready" do
11
+ it "should successfully start a tunnel connection" do
12
+ @tunnel = TestingBot::Tunnel.new()
13
+ @tunnel.start
14
+ @tunnel.is_connected?.should == true
15
+ end
16
+
17
+ it "should raise an exception when trying to stop a tunnel that has not been started yet" do
18
+ @tunnel = TestingBot::Tunnel.new()
19
+ lambda { @tunnel.stop }.should raise_error(RuntimeError, /not been started/)
20
+ end
21
+ end
22
+
23
+ context "the tunnel needs to handle proper credentials" do
24
+ it "should fail to start a tunnel connection when invalid credentials are supplied" do
25
+ @tunnel = TestingBot::Tunnel.new({ :client_key => "fake", :client_secret => "bogus" })
26
+ @tunnel.start
27
+ @tunnel.is_connected?.should == false
28
+ @tunnel.errors.should_not be_empty
29
+ @tunnel.kill
30
+ end
31
+
32
+ it "should try to fetch client_key and client_secret from the ~/.testingbot file when no credentials supplied" do
33
+ if File.exists?(File.expand_path("~/.testingbot"))
34
+ @tunnel = TestingBot::Tunnel.new()
35
+ @tunnel.start
36
+ @tunnel.is_connected?.should == true
37
+ end
38
+ end
39
+ end
40
+
41
+ context "the tunnel needs to accept extra options" do
42
+ it "should accept extra options" do
43
+ if File.exists?(File.expand_path("~/testingbot_ready.txt"))
44
+ File.delete(File.expand_path("~/testingbot_ready.txt"))
45
+ end
46
+
47
+ File.exists?(File.expand_path("~/testingbot_ready.txt")).should == false
48
+
49
+ @tunnel = TestingBot::Tunnel.new({ :options => ['-f ~/testingbot_ready.txt'] })
50
+ @tunnel.start
51
+ @tunnel.is_connected?.should == true
52
+
53
+ File.exists?(File.expand_path("~/testingbot_ready.txt")).should == true
54
+ end
55
+ end
56
+
57
+ context "there should only be one instance of a tunnel running" do
58
+ it "should check before starting that another tunnel is not yet running" do
59
+ @tunnel = TestingBot::Tunnel.new
60
+ @tunnel.start
61
+ @tunnel.is_connected?.should == true
62
+
63
+ clone = TestingBot::Tunnel.new
64
+ clone.start
65
+ clone.is_connected?.should == false
66
+ end
67
+
68
+ it "should not be possible to stop a tunnel that is not running" do
69
+ @tunnel = TestingBot::Tunnel.new
70
+ lambda { @tunnel.stop }.should raise_error(RuntimeError, /^Can't stop tunnel/)
71
+ end
72
+ end
73
+
74
+ context "When running a tunnel config values should be changed" do
75
+ it "should change the host and port in the config so that we connect to our tunnel instead of to the grid directly" do
76
+ @tunnel = TestingBot::Tunnel.new
77
+ @tunnel.start
78
+ @tunnel.is_connected?.should == true
79
+ @tunnel.instance_variable_get("@config")[:require_tunnel].should == true
80
+ @tunnel.instance_variable_get("@config")[:host].should eql("127.0.0.1")
81
+ @tunnel.instance_variable_get("@config")[:port].should eql(4445)
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/testingbot/config.rb')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/testingbot/tunnel.rb')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/testingbot/api.rb')
4
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/testingbot.rb')
@@ -0,0 +1,17 @@
1
+ require "rspec"
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib/testingbot/config.rb')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib/testingbot/api.rb')
4
+
5
+ describe TestingBot::Api do
6
+ describe "load config" do
7
+ it "should load the configuration in the constructor" do
8
+ api = TestingBot::Api.new
9
+ api.instance_variable_get("@config").should_not be_nil
10
+ end
11
+
12
+ it "should use the credentials passed in from the constructor, overwriting possible credentials from the config" do
13
+ api = TestingBot::Api.new({ :client_key => "fake" })
14
+ api.instance_variable_get("@config")[:client_key].should eql("fake")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,73 @@
1
+ require "rspec"
2
+ require 'selenium/webdriver'
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib/testingbot/config.rb')
4
+
5
+ describe TestingBot::Config do
6
+ describe '#[]' do
7
+ it "should return nil for options that don't exist" do
8
+ c = TestingBot::Config.new
9
+ c[:doesnotexist].should be_nil
10
+ end
11
+
12
+ it "should return a config value when being set from the constructor" do
13
+ c = TestingBot::Config.new({ :client_secret => "secret!!" })
14
+ c[:client_secret].should == "secret!!"
15
+ end
16
+ end
17
+
18
+ describe '#[]=' do
19
+ it "should successfully set a config value" do
20
+ c = TestingBot::Config.new
21
+ value = rand * 1000
22
+ c[:client_key] = value
23
+ c[:client_key].should == value
24
+ end
25
+ end
26
+
27
+ describe "read config file" do
28
+ it "should read values from the .testingbot config file" do
29
+ if File.exists?(File.expand_path("~/.testingbot"))
30
+ c = TestingBot::Config.new
31
+ client_key, client_secret = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp.split(":")
32
+ c[:client_key].should == client_key
33
+ end
34
+ end
35
+
36
+ it "should use the options I pass in the constructor, even if I have a config file" do
37
+ if File.exists?(File.expand_path("~/.testingbot"))
38
+ c = TestingBot::Config.new({ :client_key => "pickme" })
39
+ client_key, client_secret = File.open(File.expand_path("~/.testingbot")) { |f| f.readline }.chomp.split(":")
40
+ c[:client_key].should == "pickme"
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "config values" do
46
+ it "should specify a default desired capability if the user did not specify any" do
47
+ c = TestingBot::Config.new
48
+ c.desired_capabilities.should_not be_empty
49
+ end
50
+
51
+ it "should be possible to use a Selenium::WebDriver::Remote::Capabilities object for the desired capabilities" do
52
+ c = TestingBot::Config.new
53
+ c[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.firefox
54
+ c.desired_capabilities[:browserName].should eql("firefox")
55
+ end
56
+ end
57
+
58
+ describe "usage" do
59
+ it "should use the TestingBot.get_config as a singleton" do
60
+ c = TestingBot.get_config
61
+ c.should eql(TestingBot.get_config)
62
+ end
63
+
64
+ it "should be possible to reset the configuration" do
65
+ c = TestingBot.get_config
66
+ c.add_options({ :randomKey => "lol" })
67
+
68
+ TestingBot.reset_config!
69
+ c = TestingBot.get_config
70
+ c[:randomKey].should be_nil
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,41 @@
1
+ require "rspec"
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib/testingbot/config.rb')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib/testingbot/tunnel.rb')
4
+
5
+ describe TestingBot::Tunnel do
6
+ describe "load config" do
7
+ it "should load the configuration in the constructor" do
8
+ tunnel = TestingBot::Tunnel.new
9
+ tunnel.instance_variable_get("@config").should_not be_nil
10
+ end
11
+
12
+ it "should should not overwrite the config with arguments supplied in the constructor" do
13
+ tunnel = TestingBot::Tunnel.new({ :client_key => "fake" })
14
+ tunnel.instance_variable_get("@config")[:client_key].should_not eql("fake")
15
+ end
16
+
17
+ it "should allow for extra options to be specified, which will be passed to the jar's argument list" do
18
+ tunnel = TestingBot::Tunnel.new({ :options => ["-f readyfile.txt", "-F *.com"] })
19
+ tunnel.extra_options.should eql("-f readyfile.txt -F *.com")
20
+ end
21
+ end
22
+
23
+ describe "before starting the tunnel" do
24
+ it "should have 0 errors" do
25
+ tunnel = TestingBot::Tunnel.new
26
+ tunnel.errors.should be_empty
27
+ end
28
+
29
+ it "should not be connected" do
30
+ tunnel = TestingBot::Tunnel.new
31
+ tunnel.is_connected?.should == false
32
+ end
33
+ end
34
+
35
+ describe "before stopping the tunnel" do
36
+ it "should check if the tunnel has been started yet" do
37
+ tunnel = TestingBot::Tunnel.new
38
+ lambda { tunnel.stop }.should raise_error(RuntimeError, /^Can't stop tunnel/)
39
+ end
40
+ end
41
+ end
data/testingbot.gemspec CHANGED
@@ -5,7 +5,7 @@ require "testingbot/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "testingbot"
7
7
  s.version = Testingbot::VERSION
8
- s.authors = ["Jochen"]
8
+ s.authors = ["Jochen Delabie"]
9
9
  s.email = ["info@testingbot.com"]
10
10
  s.homepage = "http://www.testingbot.com"
11
11
  s.summary = "Ruby Gem to be used with testingbot.com"
@@ -17,4 +17,9 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
+ s.add_dependency "json"
21
+ s.add_dependency "net-http-persistent"
22
+ s.add_dependency "selenium-webdriver"
23
+ s.add_development_dependency "rspec", [">= 2.9.0"]
24
+ s.add_development_dependency "rake"
20
25
  end