hollandaise 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,10 +8,7 @@ $: << File.expand_path('../../lib', __FILE__)
8
8
  require 'hollandaise'
9
9
  require 'hollandaise/cli'
10
10
 
11
- begin
12
- load File.join(Dir.pwd, 'hollandaise.rb')
13
- rescue LoadError => e
14
- end
11
+ Hollandaise.load_config!
15
12
 
16
13
  Hollandaise::CLI.start
17
14
 
@@ -19,5 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency 'capybara'
20
20
  gem.add_dependency 'thor'
21
21
  gem.add_dependency 'arbre'
22
+ gem.add_dependency 'rainbow'
23
+ gem.add_dependency 'rack-proxy'
22
24
  end
23
25
 
@@ -3,6 +3,8 @@ require 'hollandaise/browsers'
3
3
  require 'hollandaise/project'
4
4
  require 'hollandaise/browser'
5
5
 
6
+ require 'hollandaise/railtie' if defined?(Rails::Railtie)
7
+
6
8
  module Hollandaise
7
9
  class << self
8
10
  attr_accessor :url, :browsers, :delay
@@ -12,6 +14,17 @@ module Hollandaise
12
14
  yield self
13
15
  end
14
16
 
17
+ def self.load_config!
18
+ begin
19
+ load File.join(Dir.pwd, 'hollandaise.rb')
20
+ rescue LoadError => e
21
+ begin
22
+ load File.join(Dir.pwd, 'config/hollandaise.rb')
23
+ rescue LoadError => e
24
+ end
25
+ end
26
+ end
27
+
15
28
  def self.project(name)
16
29
  project = Project.new(name)
17
30
  projects << project
@@ -3,12 +3,12 @@ module Hollandaise
3
3
  class Base
4
4
  attr_reader :browser
5
5
 
6
- def run_and_take_screenshot(url)
6
+ def run_and_take_screenshot(url, screen_size = [ 1280, 1024 ])
7
7
  @url = url
8
8
 
9
9
  selenium.navigate.to url
10
10
  sleep @options[:delay].to_i
11
- selenium.execute_script %{window.resizeTo(1280, 1024)}
11
+ selenium.manage.window.resize_to(*screen_size)
12
12
  take_screenshot
13
13
  end
14
14
 
@@ -12,8 +12,30 @@ module Hollandaise
12
12
  @selenium ||= ::Sauce::Selenium2.new(info)
13
13
  end
14
14
 
15
+ def run_and_take_screenshot(url, *args)
16
+ self.class.start_tunnel if URI(url).host == 'localhost'
17
+
18
+ super
19
+ end
20
+
21
+ def self.start_tunnel
22
+ return @tunnel if @tunnel
23
+
24
+ @tunnel = ::Sauce::Connect.new
25
+ @tunnel.connect
26
+ @tunnel.wait_until_ready
27
+
28
+ at_exit do
29
+ @tunnel.disconnect
30
+ end
31
+ end
32
+
15
33
  def target
16
- dir.join(@os.to_s).join("#{@browser} #{@version}.png")
34
+ dir.join(@os.to_s).join("#{@browser} #{@version || 'latest'}.png")
35
+ end
36
+
37
+ def name
38
+ "#{@browser} #{@version} #{@os}"
17
39
  end
18
40
 
19
41
  def info
@@ -11,6 +11,10 @@ module Hollandaise
11
11
  @selenium ||= ::Selenium::WebDriver.for(@browser)
12
12
  end
13
13
 
14
+ def name
15
+ @browser
16
+ end
17
+
14
18
  def target
15
19
  dir.join("#{@browser}.png")
16
20
  end
@@ -1,4 +1,7 @@
1
1
  require 'uri'
2
+ require 'rainbow'
3
+ require 'rack/proxy'
4
+ require 'base64'
2
5
 
3
6
  module Hollandaise
4
7
  class Project
@@ -7,7 +10,51 @@ module Hollandaise
7
10
  end
8
11
 
9
12
  def root(root)
10
- @root = URI(root)
13
+ @root = root
14
+ end
15
+
16
+ def port
17
+ 32516
18
+ end
19
+
20
+ def proxy_root(root)
21
+ uri = URI(root)
22
+
23
+ @userinfo = uri.userinfo
24
+ @host = uri.host
25
+ @port = uri.port
26
+
27
+ @root = "http://localhost:#{port}#{uri.path}"
28
+ end
29
+
30
+ def with_proxy
31
+ if !@host
32
+ yield
33
+ else
34
+ proxy = Class.new(Rack::Proxy) do
35
+ def initialize(userinfo, host, port)
36
+ @userinfo, @host, @port = userinfo, host, port
37
+ end
38
+
39
+ def rewrite_env(env)
40
+ env['HTTP_HOST'] = @host
41
+ env['SERVER_PORT'] = @port
42
+ env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64(@userinfo)}"
43
+
44
+ env
45
+ end
46
+ end
47
+
48
+ server = Thread.new do
49
+ Rack::Handler.default.run(proxy.new(@userinfo, @host, @port), :Port => port) do |server|
50
+ Thread.current[:server] = server
51
+ end
52
+ end
53
+
54
+ yield
55
+
56
+ server[:server].stop
57
+ end
11
58
  end
12
59
 
13
60
  def screenshot(name, uri)
@@ -20,11 +67,21 @@ module Hollandaise
20
67
  @browsers = browsers
21
68
  end
22
69
 
70
+ def screen_size(size)
71
+ @screen_size = size.split('x').collect(&:to_i)
72
+ end
73
+
23
74
  def run
24
- urls.each do |url, name|
25
- Hollandaise.chdir "#{@project_name}/#{name}" do
26
- browser_objects.run do |browser|
27
- browser.run_and_take_screenshot(url)
75
+ puts "Running #{@project_name}".foreground(:green)
76
+ with_proxy do
77
+ urls.each do |url, name|
78
+ puts "... #{name} (#{url})".foreground(:yellow)
79
+
80
+ Hollandaise.chdir "#{@project_name}/#{name}" do
81
+ browser_objects.run do |browser|
82
+ puts " ... #{browser.name}".foreground(:white)
83
+ browser.run_and_take_screenshot(url, @screen_size)
84
+ end
28
85
  end
29
86
  end
30
87
  end
@@ -33,7 +90,7 @@ module Hollandaise
33
90
  private
34
91
  def urls
35
92
  @screenshots.collect do |name, uri|
36
- [ @root.merge(URI(uri)), name ]
93
+ [ File.join(@root, uri), name ]
37
94
  end
38
95
  end
39
96
 
@@ -0,0 +1,12 @@
1
+ module Hollandaise
2
+ class Railtie < ::Rails::Railtie
3
+ rake_tasks do
4
+ desc "Take screenshots from Hollandaise configuration"
5
+ task :take_screenshots do
6
+ Hollandaise.load_config!
7
+
8
+ Hollandaise.projects.each(&:run)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Hollandaise
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hollandaise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -75,6 +75,38 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rainbow
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rack-proxy
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
78
110
  description: Get delicious screenshots from Sauce Labs, easily
79
111
  email:
80
112
  - john@coswellproductions.com
@@ -99,6 +131,7 @@ files:
99
131
  - lib/hollandaise/browsers.rb
100
132
  - lib/hollandaise/cli.rb
101
133
  - lib/hollandaise/project.rb
134
+ - lib/hollandaise/railtie.rb
102
135
  - lib/hollandaise/version.rb
103
136
  - skel/hollandaise.rb.tt
104
137
  homepage: ''