sauce_whisk 0.0.20 → 0.0.21

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.
@@ -1,140 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe SauceWhisk::Jobs do
4
- let(:auth) {"#{ENV["SAUCE_USERNAME"]}:#{ENV["SAUCE_ACCESS_KEY"]}"}
5
- let(:user) {ENV["SAUCE_USERNAME"]}
6
- describe "#all", :vcr => {:cassette_name => 'jobs'} do
7
-
8
- it "should return an enumerable" do
9
- expect( SauceWhisk::Jobs.all ).to be_an Enumerable
10
- end
11
-
12
- it "should return a set of jobs" do
13
- jobs_found = SauceWhisk::Jobs.all
14
- jobs_found.each {|job| expect( job ).to be_a SauceWhisk::Job}
15
- end
16
- end
17
-
18
- describe "##change_status", :vcr => {:cassette_name => "jobs"} do
19
- let(:pass_string) {{:passed => true}.to_json}
20
- it "exists" do
21
- SauceWhisk::Jobs.respond_to? :change_status
22
- end
23
-
24
- it "passes a test status to the REST api" do
25
- job_id = "bd9c43dd6b5549f1b942d1d581d98cac"
26
- SauceWhisk::Jobs.change_status job_id, true
27
- assert_requested :put, "https://#{auth}@saucelabs.com/rest/v1/#{user}/jobs/#{job_id}", :body => pass_string
28
- end
29
- end
30
-
31
- describe "##pass_job" do
32
- it "Calls the API and passes the given job" do
33
- job_id = "rerfreferf"
34
- expect( SauceWhisk::Jobs ).to receive(:change_status).with(job_id, true) {}
35
-
36
- SauceWhisk::Jobs.pass_job job_id
37
- end
38
- end
39
-
40
- describe "##fail_job" do
41
- it "Calls change_status to fail the job" do
42
- job_id = "rcercer"
43
- expect( SauceWhisk::Jobs ).to receive(:change_status).with(job_id, false) {}
44
-
45
- SauceWhisk::Jobs.fail_job job_id
46
- end
47
- end
48
-
49
- describe "##save", :vcr => {:cassette_name => "jobs"} do
50
- it "sends a put request" do
51
- job_id = "bd9c43dd6b5549f1b942d1d581d98cac"
52
- job = SauceWhisk::Job.new({:id => job_id})
53
- SauceWhisk::Jobs.save (job)
54
- assert_requested :put, "https://#{auth}@saucelabs.com/rest/v1/#{user}/jobs/#{job.id}", :body => anything
55
- end
56
-
57
- it "only sends updated information" do
58
- job_id = "bd9c43dd6b5549f1b942d1d581d98cac"
59
- job = SauceWhisk::Job.new({:id => job_id})
60
- job.name = "Updated Name"
61
- SauceWhisk::Jobs.save (job)
62
- expected_body = {:name => "Updated Name"}.to_json
63
- assert_requested :put, "https://#{auth}@saucelabs.com/rest/v1/#{user}/jobs/#{job.id}", :body => expected_body
64
- end
65
-
66
- it "sends custom-data with hyphen", :focus => true do
67
- job_id = "bd9c43dd6b5549f1b942d1d581d98cac"
68
- job = SauceWhisk::Job.new({:id => job_id})
69
- job.custom_data = {:key => "value"}
70
- SauceWhisk::Jobs.save (job)
71
- expected_body = {:'custom-data' => {:key => "value"}}.to_json
72
- assert_requested :put, "https://#{auth}@saucelabs.com/rest/v1/#{user}/jobs/#{job.id}", :body => expected_body
73
- end
74
- end
75
-
76
- describe "##fetch", :vcr => {:cassette_name => "jobs"} do
77
- context "for a completed job" do
78
- let(:job) {SauceWhisk::Jobs.fetch("bd9c43dd6b5549f1b942d1d581d98cac")}
79
-
80
- it "contains the list of screenshots for the job" do
81
- expect( job.screenshot_urls ).to be_a_kind_of Enumerable
82
- expect( job.screenshot_urls.length ).to_not be 0
83
- end
84
-
85
- it "returns a job when a valid one is fetched" do
86
- expect( job ).to be_an_instance_of SauceWhisk::Job
87
- end
88
- end
89
-
90
- context "for an incomplete job" do
91
- let(:job) {SauceWhisk::Jobs.fetch("1ca64b180cfa40e0a4aee5a4a482f271")}
92
-
93
- it "returns a job even when asset fetching fails" do
94
- expect( job ).to be_an_instance_of SauceWhisk::Job
95
- expect( job.screenshots ).to be_nil
96
- end
97
- end
98
- end
99
-
100
- describe "##fetch!", :vcr => {:cassette_name => "jobs"} do
101
- context "for a completed job" do
102
- let(:job) {SauceWhisk::Jobs.fetch! "bd9c43dd6b5549f1b942d1d581d98cac"}
103
-
104
- it "contains the list of screenshots for the job" do
105
- expect( job.screenshot_urls ).to be_a_kind_of Enumerable
106
- expect( job.screenshot_urls.length ).to_not be 0
107
- end
108
-
109
- it "returns a job when a valid one is fetched" do
110
- expect( job ).to be_an_instance_of SauceWhisk::Job
111
- end
112
- end
113
-
114
- context "for an incomplete job" do
115
- let(:job) {SauceWhisk::Jobs.fetch! "1ca64b180cfa40e0a4aee5a4a482f271" }
116
-
117
- it "raises an exception" do
118
- expect{
119
- job
120
- }.to raise_exception SauceWhisk::JobNotComplete
121
- end
122
- end
123
- end
124
-
125
- describe "##stop", :vcr => {:cassette_name => "jobs"} do
126
- it "calls the API correctly" do
127
- SauceWhisk::Jobs.stop "3edc8fe6d52645bf931b1003da65af1f"
128
- assert_requested :put, "https://#{auth}@saucelabs.com/rest/v1/#{user}/jobs/3edc8fe6d52645bf931b1003da65af1f/stop"
129
- end
130
-
131
- it "does something interesting when the job is already stopped" do
132
- SauceWhisk::Jobs.stop "9591ce8519f043f8b3bea0462923c883"
133
- end
134
-
135
- it "throws a ResourceNotFound error when the job isn't found" do
136
- expect {SauceWhisk::Jobs.stop("job_id")}.to raise_exception RestClient::ResourceNotFound
137
- end
138
-
139
- end
140
- end
@@ -1,167 +0,0 @@
1
- require "spec_helper"
2
- require "rest_client"
3
-
4
- describe SauceWhisk::RestRequestBuilder do
5
- let(:dummy_client) {
6
- Class.new do
7
- extend SauceWhisk::RestRequestBuilder
8
-
9
- def self.resource
10
- "dummy"
11
- end
12
- end
13
- }
14
-
15
- let(:dummy_client_without_resource) {
16
- Class.new do
17
- extend SauceWhisk::RestRequestBuilder
18
- end
19
- }
20
-
21
- let (:mock_auth) {{
22
- :user => ENV["SAUCE_USERNAME"],
23
- :password => ENV["SAUCE_ACCESS_KEY"]
24
- }}
25
-
26
- describe "#fully_qualified_resource" do
27
- context "with a resource defined" do
28
- it "should end with the resource" do
29
- expect( dummy_client.fully_qualified_resource ).to eq "#{SauceWhisk.base_url}/#{dummy_client.resource}"
30
- end
31
- end
32
-
33
- context "without a resource defined" do
34
- it "should return the base url" do
35
- expect( dummy_client_without_resource.fully_qualified_resource ).to eq SauceWhisk.base_url
36
- end
37
- end
38
- end
39
-
40
- describe "#auth_details" do
41
- it "should return the env vars" do
42
- expect( dummy_client.auth_details ).to eq mock_auth
43
- end
44
- end
45
-
46
- describe "#make_request" do
47
- before :all do
48
- VCR.insert_cassette 'rest_request_retry', :record => :new_episodes
49
- end
50
-
51
- after :all do
52
- VCR.eject_cassette
53
- end
54
-
55
- it "should retry 404'd methods n times" do
56
- expected_url = "#{SauceWhisk.base_url}/#{dummy_client.resource}"
57
- expected_params = {:method => :get, :url => expected_url}.merge mock_auth
58
- times = 0
59
- expect( RestClient::Request ).to receive(:execute) do |arg|
60
- expect(arg).to eq expected_params
61
- raise RestClient::ResourceNotFound.new if(times >= SauceWhisk.rest_retries)
62
- times += 1
63
- end
64
- dummy_client.get
65
- end
66
-
67
- end
68
-
69
- describe "#get" do
70
- before :all do
71
- VCR.insert_cassette 'rest_request', :record => :new_episodes
72
- end
73
- after :all do
74
- VCR.eject_cassette
75
- end
76
-
77
- it "should call the base URL with the resource name" do
78
- expected_url = "#{SauceWhisk.base_url}/#{dummy_client.resource}"
79
- expected_params = {:method => :get, :url => expected_url}.merge mock_auth
80
- expect( RestClient::Request ).to receive(:execute).with(expected_params)
81
- dummy_client.get
82
- end
83
- end
84
-
85
- describe "#delete", :vcr => {:cassette_name => 'jobs'} do
86
- let(:expected_url) {"#{SauceWhisk.base_url}/#{dummy_client.resource}/identifier"}
87
-
88
- it "calls the base URL with the delete method" do
89
- expected_params = {:method => :delete, :url => expected_url}.merge mock_auth
90
- expect( RestClient::Request ).to receive(:execute).with(expected_params)
91
- dummy_client.delete "identifier"
92
- end
93
- end
94
-
95
- begin
96
- describe "#post", :vcr => {:cassette_name => 'tunnels'} do
97
- let(:expected_payload) {{:tunnel_identifier => "KarlMarx"}}
98
- it "calls the base URL" do
99
- expected_url = "#{SauceWhisk.base_url}/#{dummy_client.resource}"
100
- expect( RestClient::Request ).to receive(:execute).with(hash_including({:url => expected_url}))
101
-
102
- dummy_client.post(:payload => expected_payload)
103
- end
104
-
105
- it "uses the correct method" do
106
- expect( RestClient::Request ).to receive(:execute).with(hash_including({:method => :post}))
107
- dummy_client.post(:payload => expected_payload)
108
- end
109
-
110
- it "includes the correct payload, in JSON" do
111
- expect( RestClient::Request ).to receive(:execute).with(hash_including({:payload => expected_payload.to_json}))
112
- dummy_client.post(:payload => expected_payload)
113
- end
114
-
115
- it "includes the correct content_type" do
116
- expect( RestClient::Request ).to receive(:execute).with(hash_including({:content_type => "application/json"}))
117
- dummy_client.post(:payload => expected_payload)
118
- end
119
-
120
- it "includes the correct length" do
121
- expected_length = expected_payload.to_json.length
122
- expect( RestClient::Request ).to receive(:execute).with(hash_including({:headers => {"Content-Length" => expected_length}}))
123
- dummy_client.post(:payload => expected_payload)
124
- end
125
-
126
- it "includes the authentication parameters" do
127
- expect( RestClient::Request ).to receive(:execute).with(hash_including(mock_auth))
128
- dummy_client.post(:payload => expected_payload)
129
- end
130
-
131
- it "allows for base resource additions" do
132
- expected_url = "#{SauceWhisk.base_url}/#{dummy_client.resource}/dummy_res"
133
- expect( RestClient::Request ).to receive(:execute).with(hash_including({:payload => expected_payload.to_json, :url => expected_url}))
134
-
135
- dummy_client.post(:payload => expected_payload, :resource =>"dummy_res")
136
- end
137
- end
138
- end
139
-
140
- describe "#put", :vcr => {:cassette_name => 'jobs'} do
141
- let(:expected_url) {"#{SauceWhisk.base_url}/#{dummy_client.resource}/something"}
142
- it "calls the base URL with the put method" do
143
- expect( RestClient::Request ).to receive(:execute).with(hash_including({:url => expected_url}))
144
- dummy_client.put "something", "another_thing"
145
- end
146
-
147
- it "includes the right method" do
148
- expect( RestClient::Request ).to receive(:execute).with(hash_including({:method => :put}))
149
- dummy_client.put "something", "another_thing"
150
- end
151
-
152
- it "includes the content length" do
153
- expect( RestClient::Request ).to receive(:execute).with(hash_including(:headers => {"Content-Length" => 13}))
154
- dummy_client.put "something", "another_thing"
155
- end
156
-
157
- it "includes authentication details" do
158
- expect( RestClient::Request ).to receive(:execute).with(hash_including(mock_auth))
159
- dummy_client.put "something", "another_thing"
160
- end
161
-
162
- it "sends the payload" do
163
- expect( RestClient::Request ).to receive(:execute).with(hash_including({:payload => "another_thing"}))
164
- dummy_client.put "something", "another_thing"
165
- end
166
- end
167
- end
@@ -1,139 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe SauceWhisk do
4
- describe "##base_url" do
5
- subject {SauceWhisk.base_url}
6
- it {should eq "https://saucelabs.com/rest/v1"}
7
-
8
- end
9
-
10
- describe "##username" do
11
- subject {SauceWhisk.username}
12
- it {should eq ENV["SAUCE_USERNAME"]}
13
-
14
- describe "when empty" do
15
- subject {lambda {SauceWhisk.username}}
16
-
17
- around do |spec|
18
- @un = ENV["SAUCE_USERNAME"]
19
- ENV.delete "SAUCE_USERNAME"
20
-
21
- spec.run
22
-
23
- ENV["SAUCE_USERNAME"] = @un
24
- end
25
-
26
- it {is_expected.to raise_exception}
27
- end
28
- end
29
-
30
- describe "##password" do
31
- subject {SauceWhisk.password}
32
- it {should eq ENV["SAUCE_ACCESS_KEY"]}
33
-
34
- describe "when empty" do
35
- subject {lambda {SauceWhisk.password}}
36
-
37
- around do |spec|
38
- @pw = ENV["SAUCE_ACCESS_KEY"]
39
- ENV.delete "SAUCE_ACCESS_KEY"
40
-
41
- spec.run
42
-
43
- ENV["SAUCE_ACCESS_KEY"] = @pw
44
- end
45
-
46
- it {is_expected.to raise_exception}
47
- end
48
- end
49
-
50
- describe "##pass_job" do
51
- it "should call #pass on the jobs object" do
52
- job_id = "0418999"
53
- expect( SauceWhisk::Jobs ).to receive(:pass_job).with(job_id) {true}
54
- SauceWhisk.pass_job job_id
55
- end
56
- end
57
-
58
- describe "##logger" do
59
- it "accepts a logger object" do
60
- dummy_logger = Object.new do
61
- def puts(input)
62
- end
63
- end
64
- SauceWhisk.logger = dummy_logger
65
- expect( SauceWhisk.logger ).to be dummy_logger
66
- end
67
-
68
- it "defaults to STDOUT" do
69
- SauceWhisk.logger = nil
70
- expect( SauceWhisk.logger ).to be_a_kind_of Logger
71
- end
72
- end
73
-
74
- describe "##asset_fetch_retries" do
75
- before :each do
76
- SauceWhisk.instance_variable_set(:@asset_fetch_retries, nil)
77
- end
78
-
79
- it "defaults to 1" do
80
- expect( SauceWhisk.asset_fetch_retries ).to equal 1
81
- end
82
-
83
- describe "when a Sauce.config is available" do
84
- before :each do
85
- SauceWhisk.instance_variable_set(:@asset_fetch_retries, nil)
86
- mock_config = Class.new(Hash) do
87
- def initialize
88
- self.store(:asset_fetch_retries, 3)
89
- end
90
- end
91
- stub_const "::Sauce::Config", mock_config
92
- end
93
-
94
- it "tries to read from Sauce.config" do
95
- expect( SauceWhisk.asset_fetch_retries ).to equal 3
96
- end
97
-
98
- it "favours values set directly" do
99
- SauceWhisk.asset_fetch_retries = 4
100
- expect( SauceWhisk.asset_fetch_retries ).to equal 4
101
- end
102
- end
103
-
104
- it "can be set directly" do
105
- SauceWhisk.asset_fetch_retries = 5
106
- expect( SauceWhisk.asset_fetch_retries ).to equal 5
107
- end
108
- end
109
-
110
- describe "##rest_retries" do
111
- it "defaults to 1" do
112
- SauceWhisk.instance_variable_set(:@rest_retries, nil)
113
- expect( SauceWhisk.rest_retries ).to equal 1
114
- end
115
-
116
- describe "when a Sauce.config is available" do
117
-
118
- before :each do
119
- SauceWhisk.instance_variable_set(:@rest_retries, nil)
120
- mock_config = Class.new(Hash) do
121
- def initialize
122
- self.store(:rest_retries, 3)
123
- end
124
- end
125
-
126
- stub_const "::Sauce::Config", mock_config
127
- end
128
-
129
- it "tries to read from Sauce.config" do
130
- expect( SauceWhisk.rest_retries ).to equal 3
131
- end
132
-
133
- it "favours values set directly" do
134
- SauceWhisk.rest_retries = 2
135
- expect( SauceWhisk.rest_retries ).to equal 2
136
- end
137
- end
138
- end
139
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SauceWhisk::Storage, :vcr => { :cassette_name => 'storage' } do
4
- before do
5
- @file_name = 'temp.apk'
6
- @temp_file = Tempfile.new @file_name
7
-
8
- begin
9
- @temp_file.write 'data'
10
- ensure
11
- @temp_file.close
12
- end
13
- end
14
-
15
- after do
16
- @temp_file.unlink
17
- end
18
-
19
- it 'uploads a file with username and key' do
20
- storage = SauceWhisk::Storage.new username: ENV['SAUCE_USERNAME'], key: ENV['SAUCE_ACCESS_KEY']
21
- storage.upload @temp_file
22
- end
23
-
24
- it 'uploads a file with implicit auth' do
25
- storage = SauceWhisk::Storage.new
26
- storage.upload @temp_file
27
- end
28
-
29
- it 'lists all uploaded files' do
30
- storage = SauceWhisk::Storage.new
31
- files = storage.files
32
- expect(files.length).to be > 1
33
-
34
- upload_successful = files.any? do |file|
35
- file['name'].include?(@file_name)
36
- end
37
- expect(upload_successful).to be true
38
- end
39
- end