sauce_whisk 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,9 +20,9 @@ describe SauceWhisk::Assets do
20
20
 
21
21
  it "initializes the asset properly" do
22
22
  asset = SauceWhisk::Assets.fetch job_id, asset_name
23
- asset.name.should eq asset_name
24
- asset.job.should eq job_id
25
- asset.asset_type.should eq :screenshot
23
+ expect( asset.name ).to eq asset_name
24
+ expect( asset.job ).to eq job_id
25
+ expect( asset.asset_type ).to eq :screenshot
26
26
  end
27
27
 
28
28
  context "for an invalid asset" do
@@ -43,4 +43,19 @@ describe SauceWhisk::Assets do
43
43
  end
44
44
  end
45
45
  end
46
+
47
+ describe "#delete", :vcr => {:cassette_name => "assets"} do
48
+ let(:asset_job_id) {"f7bcec8f706f4910ba128f48e0b8c6c7"}
49
+ it "can delete a job" do
50
+ SauceWhisk::Assets.delete(asset_job_id).should be_an_instance_of SauceWhisk::Asset
51
+ end
52
+ end
53
+
54
+ describe "#already_deleted_asset", :vcr => {:cassette_name => "assets"} do
55
+ let(:asset_job_id) {"651c7d737b7547e994678d981dcc433c"}
56
+ it "returns nil for already deleted assets" do
57
+ SauceWhisk::Assets.delete(asset_job_id).should be_an_instance_of SauceWhisk::Asset
58
+ end
59
+ end
60
+
46
61
  end
@@ -8,12 +8,12 @@ describe "SauceWhisk::Sauce", :vcr => {:cassette_name => "info"} do
8
8
  end
9
9
 
10
10
  it "returns a hash" do
11
- SauceWhisk::Sauce.service_status.should be_a_kind_of Hash
11
+ expect( SauceWhisk::Sauce.service_status ).to be_a_kind_of Hash
12
12
  end
13
13
 
14
14
  it "symbolizes the keys" do
15
15
  SauceWhisk::Sauce.service_status.each do |k,v|
16
- k.should be_an_instance_of Symbol
16
+ expect( k ).to be_an_instance_of Symbol
17
17
  end
18
18
  end
19
19
  end
@@ -25,7 +25,7 @@ describe "SauceWhisk::Sauce", :vcr => {:cassette_name => "info"} do
25
25
  end
26
26
 
27
27
  it "returns an integer" do
28
- SauceWhisk::Sauce.total_job_count.should be_a_kind_of Integer
28
+ expect( SauceWhisk::Sauce.total_job_count ).to be_a_kind_of Integer
29
29
  end
30
30
  end
31
31
 
@@ -44,7 +44,7 @@ describe "SauceWhisk::Sauce", :vcr => {:cassette_name => "info"} do
44
44
 
45
45
  it "returns an array" do
46
46
  platforms = SauceWhisk::Sauce.platforms
47
- platforms.should be_a_kind_of Array
47
+ expect( platforms ).to be_a_kind_of Array
48
48
  end
49
49
 
50
50
  context "when called with true" do
@@ -60,7 +60,7 @@ describe "SauceWhisk::Sauce", :vcr => {:cassette_name => "info"} do
60
60
 
61
61
  describe "operational?" do
62
62
  it "returns true when the service is running" do
63
- SauceWhisk::Sauce.operational?.should be_true
63
+ expect( SauceWhisk::Sauce.operational? ).to be true
64
64
  end
65
65
  end
66
66
  end
@@ -37,19 +37,19 @@ describe SauceWhisk::Job do
37
37
 
38
38
  it "tracks changes to methods" do
39
39
  subject.name = "ANewName"
40
- subject.updated_fields.should include :name
40
+ expect( subject.updated_fields ).to include :name
41
41
 
42
42
  subject.visibility = true
43
- subject.updated_fields.should include :visibility
43
+ expect( subject.updated_fields ).to include :visibility
44
44
  end
45
45
 
46
46
  it "does not track unchanged methods" do
47
- subject.updated_fields.should_not include :build
47
+ expect( subject.updated_fields ).to_not include :build
48
48
  end
49
49
 
50
50
  it "has empty updated_fields for new instances" do
51
51
  new_job = SauceWhisk::Job.new(params)
52
- new_job.updated_fields.should eq []
52
+ expect( new_job.updated_fields ).to eq []
53
53
  end
54
54
 
55
55
  describe "#save" do
@@ -61,7 +61,7 @@ describe SauceWhisk::Job do
61
61
  end
62
62
 
63
63
  it "calls the save method of the SauceWhisk::Jobs object" do
64
- SauceWhisk::Jobs.should_receive(:save).with(subject)
64
+ expect( SauceWhisk::Jobs ).to receive(:save).with(subject)
65
65
  subject.save
66
66
  end
67
67
  end
@@ -93,30 +93,44 @@ describe SauceWhisk::Job do
93
93
  subject.send("#{param}=", "TOTALLYDIFFERENT")
94
94
  }.to raise_exception
95
95
 
96
- subject.send(param).should_not eq "TOTALLYDIFFERENT"
96
+ expect( subject.send(param) ).not_to eq "TOTALLYDIFFERENT"
97
97
  end
98
98
  end
99
99
  end
100
100
  end
101
101
 
102
- context "fetched from the API" do
103
- subject {SauceWhisk::Jobs.fetch "bd9c43dd6b5549f1b942d1d581d98cac"}
102
+ context "fetched from the API", :vcr => {:cassette_name => "assets"} do
103
+ context "with all asset details" do
104
+ subject {SauceWhisk::Jobs.fetch "bd9c43dd6b5549f1b942d1d581d98cac"}
104
105
 
105
- describe "#screenshots", :vcr => {:cassette_name => "assets"} do
106
- it "contains all the screenshots for that job" do
107
- subject.screenshots.length.should be 4
106
+ it "will set has_all_asset_names true" do
107
+ expect( subject.has_all_asset_names? ).to be true
108
108
  end
109
109
 
110
- it "contains actual screenshots" do
111
- subject.screenshots.first.should be_a_kind_of SauceWhisk::Asset
112
- subject.screenshots.first.asset_type.should eq :screenshot
110
+ describe "#screenshots" do
111
+ it "contains all the screenshots for that job" do
112
+ expect( subject.screenshots.length ).to be 4
113
+ end
114
+
115
+ it "contains actual screenshots" do
116
+ expect( subject.screenshots.first ).to be_a_kind_of SauceWhisk::Asset
117
+ expect( subject.screenshots.first.asset_type ).to eq :screenshot
118
+ end
119
+ end
120
+
121
+ describe "#video", :vcr => {:cassette_name => "assets"} do
122
+ it "should be a video asset" do
123
+ expect( subject.video ).to be_a_kind_of SauceWhisk::Asset
124
+ expect( subject.video.asset_type ).to eq :video
125
+ end
113
126
  end
114
127
  end
115
128
 
116
- describe "#video", :vcr => {:cassette_name => "assets"} do
117
- it "should be a video asset" do
118
- subject.video.should be_a_kind_of SauceWhisk::Asset
119
- subject.video.asset_type.should eq :video
129
+ context "without asset details" do
130
+ subject {SauceWhisk::Jobs.fetch "1ca64b180cfa40e0a4aee5a4a482f271" }
131
+
132
+ it "will set has_all_asset_names false" do
133
+ expect( subject.has_all_asset_names? ).to be false
120
134
  end
121
135
  end
122
136
  end
@@ -6,12 +6,12 @@ describe SauceWhisk::Jobs do
6
6
  describe "#all", :vcr => {:cassette_name => 'jobs'} do
7
7
 
8
8
  it "should return an enumerable" do
9
- SauceWhisk::Jobs.all.should be_an Enumerable
9
+ expect( SauceWhisk::Jobs.all ).to be_an Enumerable
10
10
  end
11
11
 
12
12
  it "should return a set of jobs" do
13
13
  jobs_found = SauceWhisk::Jobs.all
14
- jobs_found.each {|job| job.should be_a SauceWhisk::Job}
14
+ jobs_found.each {|job| expect( job ).to be_a SauceWhisk::Job}
15
15
  end
16
16
  end
17
17
 
@@ -31,7 +31,7 @@ describe SauceWhisk::Jobs do
31
31
  describe "##pass_job" do
32
32
  it "Calls the API and passes the given job" do
33
33
  job_id = "rerfreferf"
34
- SauceWhisk::Jobs.should_receive(:change_status).with(job_id, true) {}
34
+ expect( SauceWhisk::Jobs ).to receive(:change_status).with(job_id, true) {}
35
35
 
36
36
  SauceWhisk::Jobs.pass_job job_id
37
37
  end
@@ -40,7 +40,7 @@ describe SauceWhisk::Jobs do
40
40
  describe "##fail_job" do
41
41
  it "Calls change_status to fail the job" do
42
42
  job_id = "rcercer"
43
- SauceWhisk::Jobs.should_receive(:change_status).with(job_id, false) {}
43
+ expect( SauceWhisk::Jobs ).to receive(:change_status).with(job_id, false) {}
44
44
 
45
45
  SauceWhisk::Jobs.fail_job job_id
46
46
  end
@@ -65,15 +65,51 @@ describe SauceWhisk::Jobs do
65
65
  end
66
66
 
67
67
  describe "##fetch", :vcr => {:cassette_name => "jobs"} do
68
- let(:job) {SauceWhisk::Jobs.fetch("bd9c43dd6b5549f1b942d1d581d98cac")}
68
+ context "for a completed job" do
69
+ let(:job) {SauceWhisk::Jobs.fetch("bd9c43dd6b5549f1b942d1d581d98cac")}
69
70
 
70
- it "contains the list of screenshots for the job" do
71
- job.screenshot_urls.should be_a_kind_of Enumerable
72
- job.screenshot_urls.length.should_not be 0
71
+ it "contains the list of screenshots for the job" do
72
+ expect( job.screenshot_urls ).to be_a_kind_of Enumerable
73
+ expect( job.screenshot_urls.length ).to_not be 0
74
+ end
75
+
76
+ it "returns a job when a valid one is fetched" do
77
+ expect( job ).to be_an_instance_of SauceWhisk::Job
78
+ end
79
+ end
80
+
81
+ context "for an incomplete job" do
82
+ let(:job) {SauceWhisk::Jobs.fetch("1ca64b180cfa40e0a4aee5a4a482f271")}
83
+
84
+ it "returns a job even when asset fetching fails" do
85
+ expect( job ).to be_an_instance_of SauceWhisk::Job
86
+ expect( job.screenshots ).to be_nil
87
+ end
88
+ end
89
+ end
90
+
91
+ describe "##fetch!", :vcr => {:cassette_name => "jobs"} do
92
+ context "for a completed job" do
93
+ let(:job) {SauceWhisk::Jobs.fetch! "bd9c43dd6b5549f1b942d1d581d98cac"}
94
+
95
+ it "contains the list of screenshots for the job" do
96
+ expect( job.screenshot_urls ).to be_a_kind_of Enumerable
97
+ expect( job.screenshot_urls.length ).to_not be 0
98
+ end
99
+
100
+ it "returns a job when a valid one is fetched" do
101
+ expect( job ).to be_an_instance_of SauceWhisk::Job
102
+ end
73
103
  end
74
104
 
75
- it "returns a job when a valid one is fetched" do
76
- job.should be_an_instance_of SauceWhisk::Job
105
+ context "for an incomplete job" do
106
+ let(:job) {SauceWhisk::Jobs.fetch! "1ca64b180cfa40e0a4aee5a4a482f271" }
107
+
108
+ it "raises an exception" do
109
+ expect{
110
+ job
111
+ }.to raise_exception SauceWhisk::JobNotComplete
112
+ end
77
113
  end
78
114
  end
79
115
 
@@ -26,23 +26,46 @@ describe SauceWhisk::RestRequestBuilder do
26
26
  describe "#fully_qualified_resource" do
27
27
  context "with a resource defined" do
28
28
  it "should end with the resource" do
29
- dummy_client.fully_qualified_resource.should eq "#{SauceWhisk.base_url}/#{dummy_client.resource}"
29
+ expect( dummy_client.fully_qualified_resource ).to eq "#{SauceWhisk.base_url}/#{dummy_client.resource}"
30
30
  end
31
31
  end
32
32
 
33
33
  context "without a resource defined" do
34
34
  it "should return the base url" do
35
- dummy_client_without_resource.fully_qualified_resource.should eq SauceWhisk.base_url
35
+ expect( dummy_client_without_resource.fully_qualified_resource ).to eq SauceWhisk.base_url
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
40
  describe "#auth_details" do
41
41
  it "should return the env vars" do
42
- dummy_client.auth_details.should eq mock_auth
42
+ expect( dummy_client.auth_details ).to eq mock_auth
43
43
  end
44
44
  end
45
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
+
46
69
  describe "#get" do
47
70
  before :all do
48
71
  VCR.insert_cassette 'rest_request', :record => :new_episodes
@@ -54,7 +77,7 @@ describe SauceWhisk::RestRequestBuilder do
54
77
  it "should call the base URL with the resource name" do
55
78
  expected_url = "#{SauceWhisk.base_url}/#{dummy_client.resource}"
56
79
  expected_params = {:method => :get, :url => expected_url}.merge mock_auth
57
- RestClient::Request.should_receive(:execute).with(expected_params)
80
+ expect( RestClient::Request ).to receive(:execute).with(expected_params)
58
81
  dummy_client.get
59
82
  end
60
83
  end
@@ -64,7 +87,7 @@ describe SauceWhisk::RestRequestBuilder do
64
87
 
65
88
  it "calls the base URL with the delete method" do
66
89
  expected_params = {:method => :delete, :url => expected_url}.merge mock_auth
67
- RestClient::Request.should_receive(:execute).with(expected_params)
90
+ expect( RestClient::Request ).to receive(:execute).with(expected_params)
68
91
  dummy_client.delete "identifier"
69
92
  end
70
93
  end
@@ -74,40 +97,40 @@ begin
74
97
  let(:expected_payload) {{:tunnel_identifier => "KarlMarx"}}
75
98
  it "calls the base URL" do
76
99
  expected_url = "#{SauceWhisk.base_url}/#{dummy_client.resource}"
77
- RestClient::Request.should_receive(:execute).with(hash_including({:url => expected_url}))
100
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:url => expected_url}))
78
101
 
79
102
  dummy_client.post(:payload => expected_payload)
80
103
  end
81
104
 
82
105
  it "uses the correct method" do
83
- RestClient::Request.should_receive(:execute).with(hash_including({:method => :post}))
106
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:method => :post}))
84
107
  dummy_client.post(:payload => expected_payload)
85
108
  end
86
109
 
87
110
  it "includes the correct payload, in JSON" do
88
- RestClient::Request.should_receive(:execute).with(hash_including({:payload => expected_payload.to_json}))
111
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:payload => expected_payload.to_json}))
89
112
  dummy_client.post(:payload => expected_payload)
90
113
  end
91
114
 
92
115
  it "includes the correct content_type" do
93
- RestClient::Request.should_receive(:execute).with(hash_including({:content_type => "application/json"}))
116
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:content_type => "application/json"}))
94
117
  dummy_client.post(:payload => expected_payload)
95
118
  end
96
119
 
97
120
  it "includes the correct length" do
98
121
  expected_length = expected_payload.to_json.length
99
- RestClient::Request.should_receive(:execute).with(hash_including({:headers => {"Content-Length" => expected_length}}))
122
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:headers => {"Content-Length" => expected_length}}))
100
123
  dummy_client.post(:payload => expected_payload)
101
124
  end
102
125
 
103
126
  it "includes the authentication parameters" do
104
- RestClient::Request.should_receive(:execute).with(hash_including(mock_auth))
127
+ expect( RestClient::Request ).to receive(:execute).with(hash_including(mock_auth))
105
128
  dummy_client.post(:payload => expected_payload)
106
129
  end
107
130
 
108
131
  it "allows for base resource additions" do
109
132
  expected_url = "#{SauceWhisk.base_url}/#{dummy_client.resource}/dummy_res"
110
- RestClient::Request.should_receive(:execute).with(hash_including({:payload => expected_payload.to_json, :url => expected_url}))
133
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:payload => expected_payload.to_json, :url => expected_url}))
111
134
 
112
135
  dummy_client.post(:payload => expected_payload, :resource =>"dummy_res")
113
136
  end
@@ -117,32 +140,32 @@ end
117
140
  describe "#put", :vcr => {:cassette_name => 'jobs'} do
118
141
  let(:expected_url) {"#{SauceWhisk.base_url}/#{dummy_client.resource}/something"}
119
142
  it "calls the base URL with the put method" do
120
- RestClient::Request.should_receive(:execute).with(hash_including({:url => expected_url}))
143
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:url => expected_url}))
121
144
  dummy_client.put "something", "another_thing"
122
145
  end
123
146
 
124
147
  it "includes the right content_type" do
125
- RestClient::Request.should_receive(:execute).with(hash_including({:content_type => "application/json"}))
148
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:content_type => "application/json"}))
126
149
  dummy_client.put "something", "another_thing"
127
150
  end
128
151
 
129
152
  it "includes the right method" do
130
- RestClient::Request.should_receive(:execute).with(hash_including({:method => :put}))
153
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:method => :put}))
131
154
  dummy_client.put "something", "another_thing"
132
155
  end
133
156
 
134
157
  it "includes the content length" do
135
- RestClient::Request.should_receive(:execute).with(hash_including(:headers => {"Content-Length" => 13}))
158
+ expect( RestClient::Request ).to receive(:execute).with(hash_including(:headers => {"Content-Length" => 13}))
136
159
  dummy_client.put "something", "another_thing"
137
160
  end
138
161
 
139
162
  it "includes authentication details" do
140
- RestClient::Request.should_receive(:execute).with(hash_including(mock_auth))
163
+ expect( RestClient::Request ).to receive(:execute).with(hash_including(mock_auth))
141
164
  dummy_client.put "something", "another_thing"
142
165
  end
143
166
 
144
167
  it "sends the payload" do
145
- RestClient::Request.should_receive(:execute).with(hash_including({:payload => "another_thing"}))
168
+ expect( RestClient::Request ).to receive(:execute).with(hash_including({:payload => "another_thing"}))
146
169
  dummy_client.put "something", "another_thing"
147
170
  end
148
171
  end
@@ -20,7 +20,7 @@ describe SauceWhisk do
20
20
  describe "##pass_job" do
21
21
  it "should call #pass on the jobs object" do
22
22
  job_id = "0418999"
23
- SauceWhisk::Jobs.should_receive(:pass_job).with(job_id) {true}
23
+ expect( SauceWhisk::Jobs ).to receive(:pass_job).with(job_id) {true}
24
24
  SauceWhisk.pass_job job_id
25
25
  end
26
26
  end
@@ -32,16 +32,16 @@ describe SauceWhisk do
32
32
  end
33
33
  end
34
34
  SauceWhisk.logger = dummy_logger
35
- SauceWhisk.logger.should be dummy_logger
35
+ expect( SauceWhisk.logger ).to be dummy_logger
36
36
  end
37
37
 
38
- it "defaults to STDIN" do
38
+ it "defaults to STDOUT" do
39
39
  SauceWhisk.logger = nil
40
- SauceWhisk.logger.should be STDOUT
40
+ expect( SauceWhisk.logger ).to be_a_kind_of Logger
41
41
  end
42
42
  end
43
43
 
44
- describe "##retries" do
44
+ describe "##asset_fetch_retries" do
45
45
  it "tries to read from Sauce.config" do
46
46
  SauceWhisk.instance_variable_set(:@asset_fetch_retries, nil)
47
47
  mock_config = Class.new(Hash) do
@@ -51,7 +51,26 @@ describe SauceWhisk do
51
51
  end
52
52
 
53
53
  stub_const "::Sauce::Config", mock_config
54
- SauceWhisk.asset_fetch_retries.should equal 3
54
+ expect( SauceWhisk.asset_fetch_retries ).to equal 3
55
+ end
56
+ end
57
+
58
+ describe "##rest_retries" do
59
+ it "defaults to 1" do
60
+ SauceWhisk.instance_variable_set(:@rest_retries, nil)
61
+ expect( SauceWhisk.rest_retries ).to equal 1
62
+ end
63
+
64
+ it "tries to read from Sauce.config" do
65
+ SauceWhisk.instance_variable_set(:@rest_retries, nil)
66
+ mock_config = Class.new(Hash) do
67
+ def initialize
68
+ self.store(:rest_retries, 3)
69
+ end
70
+ end
71
+
72
+ stub_const "::Sauce::Config", mock_config
73
+ expect( SauceWhisk.rest_retries ).to equal 3
55
74
  end
56
75
  end
57
76
  end