Permalink
Browse files

Implement the first parts of the auto-play page

  • Loading branch information...
1 parent 73eaf77 commit f9b4716d356d4f3a11a720b9ee3ba8f1630d2105 @rtyler committed Aug 6, 2012
View
@@ -0,0 +1,14 @@
+Feature: Auto-play videos
+ As an authenticated Sauce Labs user
+ I should be able to auto-play past videos
+ So that I can waste electricity and have a fancy office dashboard of Selenium tests
+
+ Background: Ensure we're always logged in
+ Given I have a valid Sauce Labs username and API key
+
+ @wip
+ Scenario: Auto-play the most recent 10 videos
+ Given I have recent jobs
+ And I am logged in
+ When I start the auto-player
+ Then the oldest job should start playing
@@ -0,0 +1,14 @@
+Given /^I am logged in$/ do
+ login!
+end
+
+When /^I start the auto\-player$/ do
+ page.should have_content('Auto-Play')
+ click_link 'Auto-Play'
+end
+
+Then /^the oldest job should start playing$/ do
+ last_job = jobs[-1]
+ page.should have_content "Now watching: #{last_job['name']}"
+end
+
@@ -13,17 +13,18 @@
end
Given /^I have recent jobs$/ do
- SauceTV::API.any_instance.stub(:recent_jobs).and_return([{'id' => 'test'}])
+ SauceTV::API.any_instance.stub(:recent_jobs).and_return(jobs)
+ jobs.each do |job|
+ SauceTV::API.any_instance.stub(:info_for).with(job['id']).and_return(job)
+ end
end
When /^I try to watch videos$/ do
visit '/watch'
end
When /^I enter my credentials$/ do
- fill_in 'username', :with => username
- fill_in 'api_key', :with => api_key
- click_button 'Log in'
+ login!
end
Then /^I should be given a list of jobs$/ do
@@ -20,6 +20,13 @@ def username
def api_key
@credentials['api_key'] || 'anonymous'
end
+
+ def login!
+ visit '/login'
+ fill_in 'username', :with => username
+ fill_in 'api_key', :with => api_key
+ click_button 'Log in'
+ end
end
World(UserCredentials)
View
@@ -0,0 +1,14 @@
+
+
+module FakeData
+ def jobs
+ jobs = []
+ 10.times do |i|
+ jobs << {'id' => "cuke-#{i}",
+ 'name' => "Cucumber Job #{i}"}
+ end
+ jobs
+ end
+end
+
+World(FakeData)
View
@@ -53,5 +53,18 @@ def recent_jobs
response.parsed_response
end
end
+
+ def info_for(job_id)
+ raise SauceTV::BadAPIParameters if job_id.nil?
+ response = {}
+
+ begin
+ response = get("/v1/#{username}/jobs/#{job_id}")
+ rescue Timeout::Error => e
+ return {}
+ end
+
+ return response.parsed_response
+ end
end
end
View
@@ -1,6 +1,7 @@
require 'rubygems'
require 'haml'
+require 'hmac'
require 'sinatra'
require 'saucetv/api'
require 'saucetv/errors'
@@ -13,6 +14,12 @@ def authenticated?
session[:username] && session[:api_key]
end
+ helpers do
+ def api_for_session
+ SauceTV::API.new(session[:username], session[:api_key])
+ end
+ end
+
get '/' do
'Welcome to SauceLabs.tv'
end
@@ -28,12 +35,27 @@ def authenticated?
redirect to('/watch')
end
+ get '/watch/:id' do |id|
+ unless authenticated?
+ redirect to('/login')
+ end
+
+ api = api_for_session
+ info = api.info_for(id)
+
+ haml :player, :locals => {
+ :session => session[:username],
+ :id => id,
+ :info => info
+ }
+ end
+
get '/watch' do
unless authenticated?
redirect to('/login')
end
- api = SauceTV::API.new(session[:username], session[:api_key])
+ api = api_for_session
jobs = []
begin
View
@@ -1,4 +1,5 @@
module SauceTV
class InvalidUserCredentials < Exception; end
+ class BadAPIParameters < Exception; end
end
@@ -0,0 +1,7 @@
+%html
+ %head
+ %title
+ SauceLabs.tv
+ %body
+ Now watching: #{info['name']}
+
@@ -5,8 +5,15 @@
%body
Welcome #{username}
+
+ - unless jobs.empty?
+ %a{:href => "/watch/#{jobs[-1]['id']}"}
+ Auto-Play
+
%ul#jobs
- - jobs.each do |job|
- %li.job
- #{job['id']}
+ - jobs.compact.each do |job|
+ %li.job{:id => "job_#{job['id']}"}
+ %a{:href => "https://saucelabs.com/jobs/#{job['id']}"}
+ = job['name']
+ &middot;
View
@@ -46,6 +46,27 @@
end
end
+ describe :info_for do
+ it 'should raise if the `job_id` is bad' do
+ expect {
+ subject.info_for(nil)
+ }.to raise_error(SauceTV::BadAPIParameters)
+ end
+
+ context 'when Sauce is timing out' do
+ before :each do
+ subject.class.should_receive(:get) do
+ raise Timeout::Error
+ end
+ end
+
+ it 'should return an empty Hash' do
+ info = subject.info_for('foo')
+ info.should_not be_nil
+ info.should be_instance_of Hash
+ end
+ end
+ end
end
View
@@ -4,4 +4,4 @@
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')
require 'saucetv/api'
-
+require 'saucetv/errors'

0 comments on commit f9b4716

Please sign in to comment.