geordi 0.13.3 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/cuc-show ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../lib/geordi/cuc')
3
+
4
+ Geordi::Cucumber.new.launch_vnc_viewer
data/bin/cuc-vnc-setup ADDED
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class String
4
+ # colorization
5
+ def colorize(color_code)
6
+ "\e[#{color_code}m#{self}\e[0m"
7
+ end
8
+
9
+ def red
10
+ colorize(31)
11
+ end
12
+
13
+ def green
14
+ colorize(32)
15
+ end
16
+
17
+ def yellow
18
+ colorize(33)
19
+ end
20
+ end
21
+
22
+ def pause
23
+ puts
24
+ puts "[ENTER] to continue".yellow
25
+ gets
26
+ puts
27
+ end
28
+
29
+ def say(text)
30
+ text =~ /^( *)./
31
+ level = $1 ? $1.size : 0
32
+ text.gsub!(/^ {#{level}}/, '')
33
+ puts text
34
+ end
35
+
36
+ def installed?(app)
37
+ `which #{app}`
38
+ $?.success?
39
+ end
40
+
41
+
42
+ `clear`
43
+
44
+ say <<-TEXT
45
+
46
+ This script will help you install a VNC server and a VNC viewer.
47
+
48
+ With those you will be able to use #{"cuc".green} without being disturbed by
49
+ focus-stealing selenium windows.
50
+
51
+ All windows will insteads open inside a VNC session. You can still inspect
52
+ everything by using the #{"cuc-show".green} command.
53
+ TEXT
54
+ pause
55
+
56
+ say <<-TEXT
57
+ #{"Please open a second shell to execute any commands.".red}
58
+ TEXT
59
+ pause
60
+
61
+ if installed?("vncsever")
62
+ say <<-TEXT
63
+ It appears #{"you already have a VNC server installed".green}. Good job.
64
+ TEXT
65
+ pause
66
+ else
67
+ say <<-TEXT
68
+ We are going to install and configure a VNC server.
69
+
70
+ Please run:
71
+ #{"sudo apt-get install vnc4server".red}
72
+ TEXT
73
+ pause
74
+
75
+ say <<-TEXT
76
+ We will now set a password for your VNC server. #{"Please choose a secure password.".red}
77
+
78
+ When running the #{"cuc".green} script, you will not actually need this password,
79
+ and there is no security risk. However if you start a vncserver without
80
+ #{"cuc".green}, a user with this password can connect to your machine.
81
+
82
+ Please run:
83
+ #{"vncserver :20".red}
84
+ #{"and enter a password".red}
85
+ TEXT
86
+ pause
87
+
88
+ say <<-TEXT
89
+ We will now stop the server again.
90
+
91
+ Please run:
92
+ #{"vncserver -kill :20".red}
93
+ TEXT
94
+ pause
95
+ end
96
+
97
+ if installed?("vncvieer")
98
+ say <<-TEXT
99
+ It appears #{"you already have a VNC viewer installed".green}. Good job.
100
+ TEXT
101
+ pause
102
+ else
103
+ say <<-TEXT
104
+ We are going to install and configure a VNC viewer.
105
+
106
+ Please run:
107
+ #{"sudo apt-get install xtightvncviewer".red}
108
+ TEXT
109
+ pause
110
+ end
111
+
112
+ say <<-TEXT
113
+ All done. #{"cuc".green} will automatically use this from now on.
114
+
115
+ #{"Happy cuking!".green}
116
+ TEXT
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '../lib/geordi/cuc')
3
+
4
+ require 'rubygems'
5
+ require 'launchy'
6
+
7
+ Geordi::Cucumber.new.restore_env
8
+
9
+ Launchy.open(ARGV.first)
data/lib/geordi/cuc.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  require "rubygems"
2
- require 'geordi/setup_firefox_for_selenium'
2
+ require File.join(File.dirname(__FILE__), 'setup_firefox_for_selenium')
3
+ require 'tempfile'
3
4
 
4
5
  module Geordi
5
6
  class Cucumber
6
7
 
8
+ VNC_DISPLAY = ':17'
9
+ VNC_SERVER_COMMAND = "vncserver #{VNC_DISPLAY} -localhost -nolisten tcp -SecurityTypes None -geometry 1280x1024"
10
+ VNC_VIEWER_COMMAND = "vncviewer #{VNC_DISPLAY}"
11
+ VNC_ENV_VARIABLES = %w[DISPLAY BROWSER LAUNCHY_BROWSER]
12
+
7
13
  def run
8
14
  4.times { puts }
9
15
  puts "Running Cucumber tests..."
@@ -12,6 +18,8 @@ module Geordi
12
18
  consolidate_rerun_txt_files
13
19
  show_features_to_run
14
20
 
21
+ setup_vnc
22
+
15
23
  command = use_parallel_tests? ? parallel_execution_command : serial_execution_command
16
24
 
17
25
  if argv.include? "-v"
@@ -23,6 +31,29 @@ module Geordi
23
31
  exec command
24
32
  end
25
33
 
34
+ def launch_vnc_viewer
35
+ fork {
36
+ error = capture_stderr do
37
+ system(VNC_VIEWER_COMMAND)
38
+ end
39
+ unless $?.success?
40
+ if $?.exitstatus == 127
41
+ puts "VNC viewer not found. Install it using cuc-setup-vnc."
42
+ else
43
+ puts "VNC viewer could not be opened:"
44
+ puts error
45
+ end
46
+ end
47
+ }
48
+ end
49
+
50
+ def restore_env
51
+ VNC_ENV_VARIABLES.each do |variable|
52
+ ENV[variable] = ENV["OUTER_#{variable}"]
53
+ end
54
+ end
55
+
56
+ private
26
57
 
27
58
  attr_writer :argv
28
59
  def argv
@@ -174,5 +205,55 @@ module Geordi
174
205
  parallel_tests_available? && features_can_run_with_parallel_tests?(features_to_run) && features_to_run.size != 1
175
206
  end
176
207
 
208
+ def setup_vnc
209
+ if try_and_start_vnc
210
+ VNC_ENV_VARIABLES.each do |variable|
211
+ ENV["OUTER_#{variable}"] = ENV[variable] if ENV[variable]
212
+ end
213
+ ENV["BROWSER"] = ENV["LAUNCHY_BROWSER"] = File.expand_path(File.join(File.dirname(__FILE__), '../../bin/launchy_browser'))
214
+ ENV["DISPLAY"] = VNC_DISPLAY
215
+
216
+ puts
217
+ puts "Selenium is running in a VNC window. Use cuc-show to view it."
218
+ end
219
+ end
220
+
221
+ def try_and_start_vnc
222
+ # check if vnc is already running
223
+ #return true if vnc_server_running?
224
+ error = capture_stderr do
225
+ system(VNC_SERVER_COMMAND)
226
+ end
227
+ case $?.exitstatus
228
+ when 0,
229
+ 98 # was already running after all
230
+ true
231
+ when 127 # not installed
232
+ puts "Could not launch VNC server. Install it by running cuc-setup-vnc."
233
+ puts
234
+ puts
235
+ false
236
+ else
237
+ puts "Starting VNC failed:"
238
+ puts error
239
+ puts
240
+ puts
241
+ false
242
+ end
243
+ end
244
+
245
+ def capture_stderr
246
+ old_stderr = $stderr.dup
247
+ io = Tempfile.new('cuc')
248
+ $stderr.reopen(io)
249
+ yield
250
+ io.rewind
251
+ io.read
252
+ ensure
253
+ io.close
254
+ io.unlink
255
+ $stderr.reopen(old_stderr)
256
+ end
257
+
177
258
  end
178
259
  end
@@ -1,3 +1,3 @@
1
1
  module Geordi
2
- VERSION = '0.13.3'
2
+ VERSION = '0.14.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geordi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 45
4
+ hash: 39
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 13
9
- - 3
10
- version: 0.13.3
8
+ - 14
9
+ - 0
10
+ version: 0.14.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Henning Koch
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-29 00:00:00 Z
18
+ date: 2012-10-05 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Collection of command line tools we use in our daily work with Ruby, Rails and Linux at makandra.
@@ -27,12 +27,15 @@ executables:
27
27
  - cleanup-directory
28
28
  - console-for
29
29
  - cuc
30
+ - cuc-show
31
+ - cuc-vnc-setup
30
32
  - deploy-to-production
31
33
  - dump-for
32
34
  - dumple
33
35
  - gitpt
34
36
  - install-gems-remotely
35
37
  - install-gems-remotely.sh
38
+ - launchy_browser
36
39
  - load-dump
37
40
  - migrate-all
38
41
  - power-deploy
@@ -57,12 +60,15 @@ files:
57
60
  - bin/cleanup-directory
58
61
  - bin/console-for
59
62
  - bin/cuc
63
+ - bin/cuc-show
64
+ - bin/cuc-vnc-setup
60
65
  - bin/deploy-to-production
61
66
  - bin/dump-for
62
67
  - bin/dumple
63
68
  - bin/gitpt
64
69
  - bin/install-gems-remotely
65
70
  - bin/install-gems-remotely.sh
71
+ - bin/launchy_browser
66
72
  - bin/load-dump
67
73
  - bin/migrate-all
68
74
  - bin/power-deploy
@@ -108,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
114
  requirements: []
109
115
 
110
116
  rubyforge_project: geordi
111
- rubygems_version: 1.8.21
117
+ rubygems_version: 1.8.24
112
118
  signing_key:
113
119
  specification_version: 3
114
120
  summary: Collection of command line tools we use in our daily work with Ruby, Rails and Linux at makandra.