geordi 0.4.6 → 0.5.0

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.
data/bin/cuc CHANGED
@@ -1,4 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + "/../lib/geordi/setup_firefox_for_selenium"
3
+
4
+ def exec_with_shell_expansion(*args)
5
+ escaped_args = args.collect do |arg|
6
+ arg.gsub(/([\\ "])/) { |match| "\\#{$1}" }
7
+ end
8
+ exec escaped_args.join(' ')
9
+ end
2
10
 
3
11
  # Print some whitespace
4
12
  4.times { puts }
@@ -14,9 +22,11 @@ parallel_tests_available = ['rake', 'parallel:spec'] if File.exists?('Gemfile')
14
22
 
15
23
  use_parallel_tests = parallel_tests_available && (ARGV[0] == nil)
16
24
 
25
+ use_firefox_for_selenium = "PATH=#{Geordi::SetupFirefoxForSelenium::FIREFOX_FOR_SELENIUM_PATH}:$PATH"
26
+
17
27
  if use_parallel_tests
18
28
  puts "Using parallel_tests ...\n\n"
19
- exec *['b', 'rake', 'parallel:features', ARGV].flatten
29
+ exec_with_shell_expansion *[use_firefox_for_selenium, 'b', 'rake', 'parallel:features', ARGV].flatten
20
30
  else
21
- exec *["b", "cucumber", format_args, ARGV].flatten
22
- end
31
+ exec_with_shell_expansion *[use_firefox_for_selenium, "b", "cucumber", format_args, ARGV].flatten
32
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + "/../lib/geordi/setup_firefox_for_selenium"
3
+ require 'tempfile'
4
+
5
+ Geordi::SetupFirefoxForSelenium.run
@@ -0,0 +1,118 @@
1
+ module Geordi
2
+ class SetupFirefoxForSelenium
3
+
4
+ FIREFOX_FOR_SELENIUM_PATH = '/opt/firefox-for-selenium'
5
+ FIREFOX_FOR_SELENIUM_BINARY = "#{FIREFOX_FOR_SELENIUM_PATH}/firefox"
6
+ ORIGINAL_FIREFOX_BINARY = "#{FIREFOX_FOR_SELENIUM_PATH}/firefox-original"
7
+ FIREFOX_FOR_SELENIUM_PROFILE_NAME = 'firefox-for-selenium'
8
+
9
+ class << self
10
+
11
+ def execute_command(cmd)
12
+ system(cmd) or raise "Error while executing command: #{cmd}"
13
+ end
14
+
15
+ def run_firefox_for_selenium(args = '')
16
+ execute_command("PATH=#{FIREFOX_FOR_SELENIUM_PATH}:$PATH firefox #{args}")
17
+ end
18
+
19
+ def say_hello
20
+ execute_command('clear')
21
+ puts "Whenever Firefox updates, Selenium breaks. This is annoying."
22
+ puts "This script will help you create an unchanging version of Firefox for your Selenium tests."
23
+ puts
24
+ puts "In particular, this new copy of Firefox will have the following properties:"
25
+ puts
26
+ puts "- It won't update itself with a newer version"
27
+ puts "- It can co-exist with your regular Firefox installation (which you can update at will)"
28
+ puts "- It will use a profile separate from the one you use for regular Firefox browsing"
29
+ puts "- It will not try to re-use existing Firefox windows"
30
+ puts "- It will automatically be used for your Selenium scenarios if you run your Cucumber using the cuc binary from the geordi gem."
31
+ puts "- It will live in #{FIREFOX_FOR_SELENIUM_PATH}"
32
+ puts
33
+ puts "At some point, this script will ask you for your user password, because some operations need to be run as root."
34
+ puts
35
+ puts "Press ENTER when you're ready to begin."
36
+ gets
37
+ end
38
+
39
+ def check_if_run_before
40
+ if File.exists?(ORIGINAL_FIREFOX_BINARY)
41
+ puts "It looks like you have run this script before. No good can come from running this script a second time on the same copy of Firefox."
42
+ puts "Press ENTER to continue anyway or press CTRL+C to abort."
43
+ gets
44
+ end
45
+ end
46
+
47
+ def download_old_firefox
48
+ puts "Please download an old version of Firefox from ftp://ftp.mozilla.org/pub/firefox/releases/5.0.1/ and unpack it to #{FIREFOX_FOR_SELENIUM_PATH}"
49
+ puts
50
+ puts "Press ENTER when you're done."
51
+ gets
52
+ File.file?(FIREFOX_FOR_SELENIUM_BINARY) or raise "Could not find #{FIREFOX_FOR_SELENIUM_BINARY}"
53
+ end
54
+
55
+ def create_separate_profile
56
+ puts "Creating a separate profile named '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}' so your own profile will be safe..."
57
+ # don't use the patched firefox binary for this, we don't want to give a -p parameter here
58
+ execute_command("PATH=#{FIREFOX_FOR_SELENIUM_PATH}:$PATH firefox -no-remote -CreateProfile #{FIREFOX_FOR_SELENIUM_PROFILE_NAME}")
59
+ puts
60
+ end
61
+
62
+ def patch_old_firefox
63
+ puts "Patching #{FIREFOX_FOR_SELENIUM_BINARY} so it uses the new profile and never re-uses windows from other Firefoxes..."
64
+ execute_command("sudo mv #{FIREFOX_FOR_SELENIUM_BINARY} #{ORIGINAL_FIREFOX_BINARY}")
65
+ execute_command("sudo mv #{FIREFOX_FOR_SELENIUM_BINARY}-bin #{ORIGINAL_FIREFOX_BINARY}-bin")
66
+ patched_binary = Tempfile.new('firefox')
67
+ patched_binary.write <<eos
68
+ #!/usr/bin/env ruby
69
+ exec('#{ORIGINAL_FIREFOX_BINARY}', '-no-remote', '-P', '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}', *ARGV)
70
+ eos
71
+ patched_binary.close
72
+ execute_command("sudo mv #{patched_binary.path} #{FIREFOX_FOR_SELENIUM_BINARY}")
73
+ execute_command("sudo chmod +x #{FIREFOX_FOR_SELENIUM_BINARY}")
74
+ execute_command("sudo chmod +x #{FIREFOX_FOR_SELENIUM_BINARY}")
75
+ puts
76
+ end
77
+
78
+ def configure_old_firefox
79
+ puts "This script will now open the patched copy of Firefox."
80
+ puts
81
+ puts "Please perform the following steps manually:"
82
+ puts
83
+ puts "- Disable the default browser check when Firefox launches"
84
+ puts "- Check that the version number is that of the old Firefox version you copied to #{FIREFOX_FOR_SELENIUM_PATH}"
85
+ puts "- Disable all automatic updates under Edit / Preferences / Advanced / Update (do this quickly or Firefox will already have updated)"
86
+ puts "- You should not see your bookmarks, addons, plugins from your regular Firefox profile"
87
+ puts
88
+ puts "Press ENTER when you're ready to open Firefox and perform these steps."
89
+ gets
90
+ run_firefox_for_selenium
91
+ end
92
+
93
+ def kkthxbb
94
+ puts "Congratulations, you're done!"
95
+ puts
96
+ puts "Your patched copy of Firefox will be used when you run Cucumber using the cuc binary that comes with the geordi gem."
97
+ puts "If you prefer to run Cucumber on your own, you must call it like this:"
98
+ puts
99
+ puts " PATH=#{FIREFOX_FOR_SELENIUM_PATH}:$PATH cucumber"
100
+ puts
101
+ puts "Enjoy!"
102
+ puts
103
+ end
104
+
105
+ def run
106
+ say_hello
107
+ check_if_run_before
108
+ download_old_firefox
109
+ create_separate_profile # do this before the patching because the patched binary calls firefox with a profile that does not yet exist
110
+ patch_old_firefox
111
+ configure_old_firefox
112
+ kkthxbb
113
+ end
114
+
115
+ end
116
+ end
117
+ end
118
+
@@ -1,3 +1,3 @@
1
1
  module Geordi
2
- VERSION = '0.4.6'
2
+ VERSION = '0.5.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: 3
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 6
10
- version: 0.4.6
8
+ - 5
9
+ - 0
10
+ version: 0.5.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: 2011-08-11 00:00:00 +02:00
18
+ date: 2011-09-07 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -37,6 +37,7 @@ executables:
37
37
  - remotify-local-branch
38
38
  - remove-executable-flags
39
39
  - rs
40
+ - setup-firefox-for-selenium
40
41
  - shell-for
41
42
  - tests
42
43
  extensions: []
@@ -62,10 +63,12 @@ files:
62
63
  - bin/remotify-local-branch
63
64
  - bin/remove-executable-flags
64
65
  - bin/rs
66
+ - bin/setup-firefox-for-selenium
65
67
  - bin/shell-for
66
68
  - bin/tests
67
69
  - geordi.gemspec
68
70
  - lib/geordi.rb
71
+ - lib/geordi/setup_firefox_for_selenium.rb
69
72
  - lib/geordi/version.rb
70
73
  has_rdoc: true
71
74
  homepage: http://makandra.com
@@ -97,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
100
  requirements: []
98
101
 
99
102
  rubyforge_project: geordi
100
- rubygems_version: 1.6.0
103
+ rubygems_version: 1.3.9.2
101
104
  signing_key:
102
105
  specification_version: 3
103
106
  summary: Collection of command line tools we use in our daily work with Ruby, Rails and Linux at makandra.