hanoi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,120 @@
1
+ # Automated jQuery tests with QUnit
2
+
3
+ ## Installation
4
+
5
+ (sudo) gem install hanoi
6
+
7
+ ## Crash Course
8
+
9
+ hanoi # prepare the target directory
10
+ rake test:js # run the tests
11
+
12
+ ## How To Use
13
+
14
+ Prepare the target directory, you can use **one** of the following options:
15
+
16
+ hanoi
17
+ hanoi .
18
+ hanoi /path/to/project
19
+
20
+ You need a valid [Rake](http://rake.rubyforge.org/) installation to run your tests:
21
+
22
+ rake test:js
23
+
24
+ You can specify to run the test against one or more browsers:
25
+
26
+ rake test:js BROWSERS=firefox,ie,safari
27
+
28
+ You can specify to run only certain tests:
29
+
30
+ rake test:js TESTS=path/to/first_test.js,path/to/second_test.js
31
+
32
+ You can combine both `BROWSERS` and `TESTS` configurations.
33
+
34
+ ## Structure
35
+
36
+ The `hanoi` executable will create the following structure:
37
+
38
+ Rakefile
39
+ test/
40
+ javascript/
41
+ assets/
42
+ jquery.js
43
+ testrunner.js
44
+ testsuite.css
45
+ example_test.js
46
+ fixtures/
47
+ example_fixtures.html
48
+ templates/
49
+ test_case.erb
50
+
51
+ * `Rakefile` creates a fresh Rake file, **you have to edit** it according to your setup
52
+ * `test` Hanoi creates it if missing, otherwise will choose between existing `test` or `spec` paths
53
+ * `javascript` is the root directory of your tests
54
+ * `assets` contains the [jQuery](http://jquery.com) and [QUnit](http://docs.jquery.com/QUnit) source file and a css.
55
+ Place your assets in this directory, it's mapped as root path `/`.
56
+ * `example_test.js` is a sample of a real test case.
57
+ * `templates` contains the template file for your tests. You shouldn't edit it, if you don't know the risk.
58
+ * `fixtures` contains all the HTML fixtures, each file will be injected into the proper case.
59
+
60
+ By convention, your `test/javascript` folder **should reflect** the structure of your source directory,
61
+ appending the `_test.js` suffix to each test case and the `_fixtures.html` to each fixture file.
62
+
63
+ Example:
64
+
65
+ src/
66
+ directory_a/
67
+ directory_b/
68
+ file_3.js
69
+ file_2.js
70
+ file_1.js
71
+ test/
72
+ javascript/
73
+ directory_a/
74
+ directory_b/
75
+ file_3_test.js
76
+ file_2_test.js
77
+ file_1_test.js
78
+ fixtures/
79
+ directory_a/
80
+ directory_b/
81
+ file_3_fixtures.html
82
+ file_1_fixtures.html
83
+
84
+ You have probably noticed that `file_2_fixtures.html` is missing, this because **fixtures are optional**.
85
+
86
+ ## Browsers & Platforms
87
+
88
+ ### Platforms:
89
+
90
+ * Mac OS X
91
+ * Windows
92
+ * Linux
93
+
94
+ ### Browsers:
95
+
96
+ * Chrome (Mac OS X and Windows)
97
+ * Firefox
98
+ * Internet Explorer (Windows)
99
+ * Konqueror (Linux)
100
+ * Opera
101
+ * Safari (Mac OS X and Windows)
102
+ * Webkit (Mac OS X and Windows)
103
+
104
+ #### Webkit on Mac OS X
105
+
106
+ To solve the annoying start page issue run: `defaults write org.webkit.nightly.WebKit StartPageDisabled -bool YES`
107
+
108
+ ## Acknowledgements
109
+
110
+ The Ruby libraries of Hanoi are a customization of the `jsblib.rb`, courtesy of the [Prototype](http://prototypejs.org) team.
111
+
112
+ Hanoi runs a customized version of `QUnit`, courtesy of the [jQuery](http://jquery.com) team.
113
+
114
+ ## Repository
115
+
116
+ git clone git://github.com/jodosha/hanoi.git
117
+
118
+ ## Copyright
119
+
120
+ (c) 2009 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/testtask'
5
5
  require 'rake/rdoctask'
6
6
  require 'spec/rake/spectask'
7
7
 
8
- HANOI_VERSION = "0.0.1"
8
+ HANOI_VERSION = "0.0.2"
9
9
 
10
10
  task :default => :spec
11
11
 
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hanoi"
3
- s.version = "0.0.1"
4
- s.date = "2009-06-09"
3
+ s.version = "0.0.2"
4
+ s.date = "2009-12-26"
5
5
  s.summary = "Automated jQuery tests with QUnit"
6
6
  s.author = "Luca Guidi"
7
7
  s.email = "guidi.luca@gmail.com"
8
8
  s.description = "Automated jQuery tests with QUnit"
9
9
  s.has_rdoc = true
10
10
  s.executables = [ 'hanoi' ]
11
- s.files = ["MIT-LICENSE", "README.textile", "Rakefile", "bin/hanoi", "hanoi.gemspec", "lib/hanoi.rb", "lib/hanoi/browser.rb", "lib/hanoi/browsers/firefox.rb", "lib/hanoi/browsers/internet_explorer.rb", "lib/hanoi/browsers/konqueror.rb", "lib/hanoi/browsers/opera.rb", "lib/hanoi/browsers/safari.rb", "lib/hanoi/javascript_test_task.rb", "lib/hanoi/test_case.rb", "lib/hanoi/test_results.rb", "lib/hanoi/test_suite_results.rb", "lib/hanoi/webrick.rb", "spec/browser_spec.rb", "spec/browsers/firefox_spec.rb", "spec/browsers/internet_explorer_spec.rb", "spec/browsers/konqueror_spec.rb", "spec/browsers/opera_spec.rb", "spec/browsers/safari_spec.rb", "spec/spec_helper.rb", "templates/assets/jquery.js", "templates/assets/testrunner.js", "templates/assets/testsuite.css", "templates/example_fixtures.html", "templates/example_test.js", "templates/fresh_rakefile", "templates/test_case.erb"]
12
- s.test_files = ["spec/browser_spec.rb", "spec/browsers/firefox_spec.rb", "spec/browsers/internet_explorer_spec.rb", "spec/browsers/konqueror_spec.rb", "spec/browsers/opera_spec.rb", "spec/browsers/safari_spec.rb"]
13
- s.extra_rdoc_files = ['README.textile']
14
- end
11
+ s.files = ["MIT-LICENSE", "README.md", "Rakefile", "bin/hanoi", "hanoi.gemspec", "lib/hanoi.rb", "lib/hanoi/browser.rb", "lib/hanoi/browsers/chrome.rb", "lib/hanoi/browsers/firefox.rb", "lib/hanoi/browsers/internet_explorer.rb", "lib/hanoi/browsers/konqueror.rb", "lib/hanoi/browsers/opera.rb", "lib/hanoi/browsers/safari.rb", "lib/hanoi/browsers/webkit.rb", "lib/hanoi/javascript_test_task.rb", "lib/hanoi/test_case.rb", "lib/hanoi/test_results.rb", "lib/hanoi/test_suite_results.rb", "lib/hanoi/webrick.rb", "spec/browser_spec.rb", "spec/browsers/chrome_spec.rb", "spec/browsers/firefox_spec.rb", "spec/browsers/internet_explorer_spec.rb", "spec/browsers/konqueror_spec.rb", "spec/browsers/opera_spec.rb", "spec/browsers/safari_spec.rb", "spec/browsers/webkit_spec.rb", "spec/spec_helper.rb", "templates/assets/jquery.js", "templates/assets/testrunner.js", "templates/assets/testsuite.css", "templates/example_fixtures.html", "templates/example_test.js", "templates/fresh_rakefile", "templates/test_case.erb"]
12
+ s.test_files = ["spec/browser_spec.rb", "spec/browsers/chrome_spec.rb", "spec/browsers/firefox_spec.rb", "spec/browsers/internet_explorer_spec.rb", "spec/browsers/konqueror_spec.rb", "spec/browsers/opera_spec.rb", "spec/browsers/safari_spec.rb", "spec/browsers/webkit_spec.rb"]
13
+ s.extra_rdoc_files = ["README.md"]
14
+ end
@@ -3,9 +3,11 @@ require "webrick"
3
3
  require "rake/tasklib"
4
4
  require "hanoi/webrick"
5
5
  require "hanoi/browser"
6
+ require "hanoi/browsers/chrome"
6
7
  require "hanoi/browsers/firefox"
7
8
  require "hanoi/browsers/internet_explorer"
8
9
  require "hanoi/browsers/konqueror"
10
+ require "hanoi/browsers/webkit"
9
11
  require "hanoi/browsers/safari"
10
12
  require "hanoi/browsers/opera"
11
13
  require "hanoi/test_case"
@@ -21,8 +21,34 @@ class Browser
21
21
  host.include?('linux')
22
22
  end
23
23
 
24
- def applescript(script)
25
- raise "Can't run AppleScript on #{host}" unless macos?
26
- system "osascript -e '#{script}' 2>&1 >/dev/null"
24
+ def visit(url)
25
+ if macos?
26
+ system("open -g -a #{path} '#{url}'")
27
+ elsif windows?
28
+ system("#{path} #{url}")
29
+ elsif linux?
30
+ system("#{name} #{url}")
31
+ end
27
32
  end
33
+
34
+ def name
35
+ n = self.class.name.split('::').last
36
+ linux? ? n.downcase : n
37
+ end
38
+
39
+ def escaped_name
40
+ name.gsub(' ', '\ ')
41
+ end
42
+
43
+ def path
44
+ if macos?
45
+ File.expand_path("/Applications/#{escaped_name}.app")
46
+ else
47
+ @path
48
+ end
49
+ end
50
+
51
+ def to_s
52
+ name
53
+ end
28
54
  end
@@ -0,0 +1,21 @@
1
+ class Chrome < Browser
2
+ def initialize(path = nil)
3
+ @path = path || File.join(
4
+ ENV['UserPath'] || ENV['UserProfile'] || "C:/Documents and Settings/Administrator",
5
+ "Local Settings",
6
+ "Application Data",
7
+ "Google",
8
+ "Chrome",
9
+ "Application",
10
+ "chrome.exe"
11
+ )
12
+ end
13
+
14
+ def supported?
15
+ windows? || macos?
16
+ end
17
+
18
+ def name
19
+ "Google Chrome"
20
+ end
21
+ end
@@ -2,14 +2,4 @@ class Firefox < Browser
2
2
  def initialize(path = File.join(ENV['ProgramFiles'] || 'c:\Program Files', '\Mozilla Firefox\firefox.exe'))
3
3
  @path = path
4
4
  end
5
-
6
- def visit(url)
7
- system("open -a Firefox '#{url}'") if macos?
8
- system("#{@path} #{url}") if windows?
9
- system("firefox #{url}") if linux?
10
- end
11
-
12
- def to_s
13
- "Firefox"
14
- end
15
5
  end
@@ -16,7 +16,7 @@ class InternetExplorer < Browser
16
16
  end
17
17
  end
18
18
 
19
- def to_s
19
+ def name
20
20
  "Internet Explorer"
21
21
  end
22
22
  end
@@ -14,14 +14,4 @@ class Opera < Browser
14
14
  }
15
15
  end
16
16
  end
17
-
18
- def visit(url)
19
- applescript('tell application "Opera" to GetURL "' + url + '"') if macos?
20
- system("#{@path} #{url}") if windows?
21
- system("opera #{url}") if linux?
22
- end
23
-
24
- def to_s
25
- "Opera"
26
- end
27
17
  end
@@ -1,21 +1,5 @@
1
- class Safari < Browser
2
- def supported?
3
- macos? || windows?
4
- end
5
-
6
- def setup
7
- applescript('tell application "Safari" to make new document')
8
- end
9
-
10
- def visit(url)
11
- applescript('tell application "Safari" to set URL of front document to "' + url + '"')
12
- end
13
-
14
- def teardown
15
- #applescript('tell application "Safari" to close front document')
16
- end
17
-
18
- def to_s
19
- "Safari"
1
+ class Safari < Webkit
2
+ def initialize(path = File.join(ENV['ProgramFiles'] || 'c:\Program Files', '\Safari\Safari.exe'))
3
+ @path = path
20
4
  end
21
5
  end
@@ -0,0 +1,27 @@
1
+ class Webkit < Browser
2
+ def supported?
3
+ macos? || windows?
4
+ end
5
+
6
+ def setup
7
+ applescript(%(tell application "#{name}" to make new document)) if macos?
8
+ end
9
+
10
+ def visit(url)
11
+ if macos?
12
+ applescript(%(tell application "#{name}" to set URL of front document to "#{url}"))
13
+ elsif windows?
14
+ system("#{path} #{url}")
15
+ end
16
+ end
17
+
18
+ def teardown
19
+ #applescript('tell application "Safari" to close front document')
20
+ end
21
+
22
+ private
23
+ def applescript(script)
24
+ raise "Can't run AppleScript on #{host}" unless macos?
25
+ system "osascript -e '#{script}' 2>&1 >/dev/null"
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  class JavaScriptTestTask < ::Rake::TaskLib
2
- BROWSERS = %w( safari firefox ie konqueror opera ).freeze
2
+ BROWSERS = %w( chrome safari firefox ie konqueror opera webkit ).freeze
3
3
  attr_reader :sources_directory
4
4
 
5
5
  def initialize(name = :test)
@@ -88,6 +88,8 @@ class JavaScriptTestTask < ::Rake::TaskLib
88
88
  def browser(browser)
89
89
  browser =
90
90
  case(browser)
91
+ when :chrome
92
+ Chrome.new
91
93
  when :firefox
92
94
  Firefox.new
93
95
  when :safari
@@ -98,6 +100,8 @@ class JavaScriptTestTask < ::Rake::TaskLib
98
100
  Konqueror.new
99
101
  when :opera
100
102
  Opera.new
103
+ when :webkit
104
+ Webkit.new
101
105
  else
102
106
  browser
103
107
  end
@@ -185,6 +189,12 @@ END
185
189
  end
186
190
 
187
191
  def assets_directory
188
- @assets_directory ||= File.expand_path(current_directory + "/test/javascript/assets").freeze
192
+ @assets_directory ||= begin
193
+ path = File.expand_path(current_directory + "/test/javascript/assets")
194
+ return path if File.directory?(path)
195
+ path = File.expand_path(current_directory + "/spec/javascript/assets")
196
+ return path if File.directory?(path)
197
+ raise "Cannot find:\n\t#{File.expand_path(current_directory + "/test/javascript/assets")} or\n\t#{File.expand_path(current_directory + "/spec/javascript/assets")}"
198
+ end
189
199
  end
190
200
  end
@@ -10,7 +10,7 @@ class TestCase
10
10
  end
11
11
 
12
12
  def target
13
- "/javascripts/#{relative_path.gsub('_test', '')}"
13
+ "/javascripts/#{relative_path.gsub(/(_test|_spec)/, '')}"
14
14
  end
15
15
 
16
16
  def content
@@ -39,7 +39,7 @@ class TestCase
39
39
 
40
40
  def html_fixtures
41
41
  path = File.dirname(File.expand_path(@path).gsub(@test_directory, "#{@test_directory}/fixtures"))
42
- path = File.expand_path(path + "/#{name.gsub('_test', '_fixtures.html')}")
42
+ path = File.expand_path(path + "/#{name.gsub(/(_test|_spec)/, '_fixtures.html')}")
43
43
  File.new(path).read rescue ""
44
44
  end
45
45
  end
@@ -0,0 +1,55 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+
3
+ describe "Chrome" do
4
+ before(:each) do
5
+ @browser = Chrome.new
6
+ @url = "http://localhost"
7
+ end
8
+
9
+ describe "Cross OS Chrome", :shared => true do
10
+ it "should be supported" do
11
+ @browser.should be_supported
12
+ end
13
+
14
+ it "return name" do
15
+ @browser.name.should == "Google Chrome"
16
+ end
17
+ end
18
+
19
+ describe "Mac OS X" do
20
+ it_should_behave_like "Cross OS Chrome"
21
+
22
+ it "should have a path" do
23
+ expected = File.expand_path("/Applications/#{@browser.escaped_name}.app")
24
+ @browser.path.should == expected
25
+ end
26
+
27
+ it "should visit a given url" do
28
+ Kernel.expects(:system).with("open -a #{@browser.name} '#{@url}'")
29
+ @browser.visit(@url)
30
+ end
31
+ end if macos?
32
+
33
+ describe "Windows" do
34
+ it_should_behave_like "Cross OS Chrome"
35
+
36
+ it "should have a path" do
37
+ @browser.path.should == File.join(ENV['ProgramFiles'] || 'c:\Program Files', '\Mozilla Chrome\firefox.exe')
38
+ end
39
+
40
+ it "should visit a given url" do
41
+ Kernel.expects(:system).with("#{@browser.path} #{@url}")
42
+ @browser.visit(@url)
43
+ end
44
+ end if windows?
45
+
46
+ describe "Linux" do
47
+ it "return name" do
48
+ @browser.name.should == "Google Chrome"
49
+ end
50
+
51
+ it "should not be supported" do
52
+ @browser.should_not be_supported
53
+ end
54
+ end if linux?
55
+ end
@@ -3,20 +3,65 @@ require File.join(File.dirname(__FILE__), "/../spec_helper")
3
3
  describe "Firefox" do
4
4
  before(:each) do
5
5
  @browser = Firefox.new
6
+ @url = "http://localhost"
6
7
  end
7
8
 
8
- it "should have a path" do
9
- @browser.path.should == File.join(ENV['ProgramFiles'] || 'c:\Program Files', '\Mozilla Firefox\firefox.exe')
9
+ describe "Cross OS Firefox", :shared => true do
10
+ it "should be supported" do
11
+ @browser.should be_supported
12
+ end
10
13
  end
11
14
 
12
- # TODO cleanup
13
- it "should visit a given url" do
14
- url = "http://localhost"
15
- command = "open -a Firefox '#{url}'" if @browser.macos?
16
- command = "#{@path} #{url}" if @browser.windows?
17
- command = "firefox #{url}" if @browser.linux?
15
+ describe "Mac OS X" do
16
+ it_should_behave_like "Cross OS Firefox"
18
17
 
19
- Kernel.expects(:system).with(command)
20
- @browser.visit(url)
21
- end
22
- end
18
+ it "should have a path" do
19
+ expected = File.expand_path("/Applications/#{@browser.escaped_name}.app")
20
+ @browser.path.should == expected
21
+ end
22
+
23
+ it "return name" do
24
+ @browser.name.should == "Firefox"
25
+ end
26
+
27
+ it "should visit a given url" do
28
+ Kernel.expects(:system).with("open -a #{@browser.name} '#{@url}'")
29
+ @browser.visit(@url)
30
+ end
31
+ end if macos?
32
+
33
+ describe "Windows" do
34
+ it_should_behave_like "Cross OS Firefox"
35
+
36
+ it "should have a path" do
37
+ @browser.path.should == File.join(ENV['ProgramFiles'] || 'c:\Program Files', '\Mozilla Firefox\firefox.exe')
38
+ end
39
+
40
+ it "return name" do
41
+ @browser.name.should == "Firefox"
42
+ end
43
+
44
+ it "should visit a given url" do
45
+ Kernel.expects(:system).with("#{@browser.path} #{@url}")
46
+ @browser.visit(@url)
47
+ end
48
+ end if windows?
49
+
50
+ describe "Linux" do
51
+ it_should_behave_like "Cross OS Firefox"
52
+
53
+ it "should have a path" do
54
+ path = "/usr/bin/#{@browser.name}"
55
+ Firefox.new(path).path.should == path
56
+ end
57
+
58
+ it "should visit a given url" do
59
+ Kernel.expects(:system).with("#{@browser.name} #{@url}")
60
+ @browser.visit(@url)
61
+ end
62
+
63
+ it "return name" do
64
+ @browser.name.should == "firefox"
65
+ end
66
+ end if linux?
67
+ end
@@ -1,22 +1,43 @@
1
1
  require File.join(File.dirname(__FILE__), "/../spec_helper")
2
2
 
3
3
  describe "InternetExplorer" do
4
- before(:each) do
4
+ before :each do
5
5
  @browser = InternetExplorer.new
6
6
  end
7
7
 
8
- it "should be supported on Windows" do
9
- supported = !!(@browser.windows?)
10
- @browser.supported?.should == supported
8
+ describe "Cross OS Internet Explorer", :shared => true do
9
+ it "should not be supported" do
10
+ @browser.should_not be_supported
11
+ end
12
+
13
+ it "return name" do
14
+ @browser.name.should == "Internet Explorer"
15
+ end
11
16
  end
12
17
 
13
- it "should setup" do
14
- if @browser.windows?
18
+ describe "Mac OS X" do
19
+ it_should_behave_like "Cross OS Internet Explorer"
20
+ end if macos?
21
+
22
+ describe "Windows" do
23
+ it "return name" do
24
+ @browser.name.should == "Internet Explorer"
25
+ end
26
+
27
+ it "should be supported" do
28
+ @browser.should be_supported
29
+ end
30
+
31
+ it "should setup" do
15
32
  # TODO test on windows
16
33
  # Kernel.expects(:require).with('win32ole')
17
34
  lambda { @browser.setup }.should_not raise_error
18
35
  end
19
- end
20
36
 
21
- it "should visit a given url"
22
- end
37
+ it "should visit a given url"
38
+ end if windows?
39
+
40
+ describe "Linux" do
41
+ it_should_behave_like "Cross OS Internet Explorer"
42
+ end if linux?
43
+ end
@@ -1,18 +1,41 @@
1
1
  require File.join(File.dirname(__FILE__), "/../spec_helper")
2
2
 
3
3
  describe "Konqueror" do
4
- before(:each) do
4
+ before :each do
5
5
  @browser = Konqueror.new
6
6
  end
7
7
 
8
- it "should be supported on Linux" do
9
- supported = !!@browser.linux?
10
- @browser.supported?.should == supported
11
- end
8
+ describe "Cross OS Konqueror", :shared => true do
9
+ it "return name" do
10
+ @browser.name.should == "Konqueror"
11
+ end
12
12
 
13
- it "should visit a given url" do
14
- url = "http://localhost"
15
- Kernel.expects(:system).with("kfmclient openURL #{url}")
16
- @browser.visit(url)
13
+ it "should not be supported" do
14
+ @browser.should_not be_supported
15
+ end
17
16
  end
17
+
18
+ describe "Mac OS X" do
19
+ it_should_behave_like "Cross OS Konqueror"
20
+ end if macos?
21
+
22
+ describe "Windows" do
23
+ it_should_behave_like "Cross OS Konqueror"
24
+ end if windows?
25
+
26
+ describe "Linux" do
27
+ it "return name" do
28
+ @browser.name.should == "konqueror"
29
+ end
30
+
31
+ it "should be supported" do
32
+ @browser.should be_supported
33
+ end
34
+
35
+ it "should visit a given url" do
36
+ url = "http://localhost"
37
+ Kernel.expects(:system).with("kfmclient openURL #{url}")
38
+ @browser.visit(url)
39
+ end
40
+ end if linux?
18
41
  end
@@ -1,25 +1,67 @@
1
1
  require File.join(File.dirname(__FILE__), "/../spec_helper")
2
2
 
3
3
  describe "Opera" do
4
- before(:each) do
4
+ before :each do
5
5
  @browser = Opera.new
6
+ @url = "http://localhost"
6
7
  end
7
8
 
8
- it "should have a path" do
9
- @browser.path.should == 'c:\Program Files\Opera\Opera.exe'
9
+ describe "Cross OS Opera", :shared => true do
10
+ it "should be supported" do
11
+ @browser.should be_supported
12
+ end
10
13
  end
11
14
 
12
- it "should visit a given url" do
13
- url = "http://localhost"
15
+ describe "Mac OS X" do
16
+ it_should_behave_like "Cross OS Opera"
14
17
 
15
- if @browser.macos?
16
- @browser.expects(:applescript).with('tell application "Opera" to GetURL "' + url + '"')
17
- elsif @browser.windows?
18
- Kernel.expects(:system).with("#{@browser.path} #{url}")
19
- else
20
- Kernel.expects(:system).with("opera #{url}")
18
+ it "return name" do
19
+ @browser.name.should == "Opera"
21
20
  end
22
21
 
23
- @browser.visit(url)
24
- end
25
- end
22
+ it "should have a path" do
23
+ expected = File.expand_path("/Applications/#{@browser.escaped_name}.app")
24
+ @browser.path.should == expected
25
+ end
26
+
27
+ it "should visit a given url" do
28
+ @browser.expects(:applescript).with(%(tell application "#{@browser.name}" to GetURL "#{@url}"))
29
+ @browser.visit(@url)
30
+ end
31
+ end if macos?
32
+
33
+ describe "Windows" do
34
+ it_should_behave_like "Cross OS Opera"
35
+
36
+ it "return name" do
37
+ @browser.name.should == "Opera"
38
+ end
39
+
40
+ it "should have a path" do
41
+ @browser.path.should == 'c:\Program Files\Opera\Opera.exe'
42
+ end
43
+
44
+ it "should visit a given url" do
45
+ Kernel.expects(:system).with("#{@browser.path} #{@url}")
46
+ @browser.visit(@url)
47
+ end
48
+ end if windows?
49
+
50
+ describe "Linux" do
51
+ it_should_behave_like "Cross OS Opera"
52
+
53
+ it "return name" do
54
+ @browser.name.should == "opera"
55
+ end
56
+
57
+ it "should have a path" do
58
+ path = "/usr/bin/#{@browser.name}"
59
+ Opera.new(path).path.should == path
60
+ end
61
+
62
+ it "should visit a given url" do
63
+ Kernel.expects(:system).with("#{@browser.name} #{@url}")
64
+ @browser.visit(@url)
65
+ end
66
+ end if linux?
67
+ end
@@ -1,23 +1,39 @@
1
1
  require File.join(File.dirname(__FILE__), "/../spec_helper")
2
2
 
3
3
  describe "Safari" do
4
- before(:each) do
4
+ before :each do
5
5
  @browser = Safari.new
6
6
  end
7
7
 
8
- it "should be supported on Windows and MacOS" do
9
- supported = !!(@browser.macos? || @browser.windows?)
10
- @browser.supported?.should == supported
11
- end
8
+ describe "Cross OS Safari", :shared => true do
9
+ it "should be supported" do
10
+ @browser.should be_supported
11
+ end
12
12
 
13
- it "should setup" do
14
- @browser.expects(:applescript).with('tell application "Safari" to make new document')
15
- @browser.setup
16
- end
13
+ it "return name" do
14
+ @browser.name.should == "Safari"
15
+ end
17
16
 
18
- it "should visit a given url" do
19
- url = "http://localhost"
20
- @browser.expects(:applescript).with('tell application "Safari" to set URL of front document to "' + url + '"')
21
- @browser.visit(url)
17
+ it "should be kind of Webkit" do
18
+ @browser.should be_kind_of(Webkit)
19
+ end
22
20
  end
23
- end
21
+
22
+ describe "Mac OS X" do
23
+ it_should_behave_like "Cross OS Safari"
24
+ end if macos?
25
+
26
+ describe "Windows" do
27
+ it_should_behave_like "Cross OS Safari"
28
+ end if windows?
29
+
30
+ describe "Linux" do
31
+ it "return name" do
32
+ @browser.name.should == "safari"
33
+ end
34
+
35
+ it "should not be supported" do
36
+ @browser.should_not be_supported
37
+ end
38
+ end if linux?
39
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+
3
+ describe "Webkit" do
4
+ before :each do
5
+ @browser = Webkit.new
6
+ end
7
+
8
+ describe "Cross OS Webkit", :shared => true do
9
+ it "should be supported" do
10
+ @browser.should be_supported
11
+ end
12
+ end
13
+
14
+ describe "Mac OS X" do
15
+ it_should_behave_like "Cross OS Webkit"
16
+
17
+ it "return name" do
18
+ @browser.name.should == "Webkit"
19
+ end
20
+
21
+ it "should setup" do
22
+ @browser.expects(:applescript).with(%(tell application "#{@browser.name}" to make new document))
23
+ @browser.setup
24
+ end
25
+
26
+ it "should visit a given url" do
27
+ url = "http://localhost"
28
+ @browser.expects(:applescript).with(%(tell application "#{@browser.name}" to set URL of front document to "#{url}"))
29
+ @browser.visit(url)
30
+ end
31
+ end if macos?
32
+
33
+ describe "Windows" do
34
+ it_should_behave_like "Cross OS Webkit"
35
+
36
+ it "return name" do
37
+ @browser.name.should == "Webkit"
38
+ end
39
+
40
+ it "should setup" do
41
+ @browser.should_not_receive(:applescript)
42
+ @browser.setup
43
+ end
44
+
45
+ it "should visit a given url" do
46
+ Kernel.expects(:system).with("#{@browser.path} #{@url}")
47
+ @browser.visit(@url)
48
+ end
49
+ end if windows?
50
+
51
+ describe "Linux" do
52
+ it "return name" do
53
+ @browser.name.should == "webkit"
54
+ end
55
+
56
+ it "should not be supported" do
57
+ @browser.should_not be_supported
58
+ end
59
+ end if linux?
60
+ end
@@ -9,4 +9,15 @@ module Kernel
9
9
  end
10
10
  end
11
11
 
12
- class Browser; attr_reader :path end
12
+ # TODO delegation
13
+ def macos?
14
+ Browser.new.macos?
15
+ end
16
+
17
+ def windows?
18
+ Browser.new.windows?
19
+ end
20
+
21
+ def linux?
22
+ Browser.new.linux?
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanoi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-09 00:00:00 +02:00
12
+ date: 2009-12-26 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,31 +20,35 @@ executables:
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README.textile
23
+ - README.md
24
24
  files:
25
25
  - MIT-LICENSE
26
- - README.textile
26
+ - README.md
27
27
  - Rakefile
28
28
  - bin/hanoi
29
29
  - hanoi.gemspec
30
30
  - lib/hanoi.rb
31
31
  - lib/hanoi/browser.rb
32
+ - lib/hanoi/browsers/chrome.rb
32
33
  - lib/hanoi/browsers/firefox.rb
33
34
  - lib/hanoi/browsers/internet_explorer.rb
34
35
  - lib/hanoi/browsers/konqueror.rb
35
36
  - lib/hanoi/browsers/opera.rb
36
37
  - lib/hanoi/browsers/safari.rb
38
+ - lib/hanoi/browsers/webkit.rb
37
39
  - lib/hanoi/javascript_test_task.rb
38
40
  - lib/hanoi/test_case.rb
39
41
  - lib/hanoi/test_results.rb
40
42
  - lib/hanoi/test_suite_results.rb
41
43
  - lib/hanoi/webrick.rb
42
44
  - spec/browser_spec.rb
45
+ - spec/browsers/chrome_spec.rb
43
46
  - spec/browsers/firefox_spec.rb
44
47
  - spec/browsers/internet_explorer_spec.rb
45
48
  - spec/browsers/konqueror_spec.rb
46
49
  - spec/browsers/opera_spec.rb
47
50
  - spec/browsers/safari_spec.rb
51
+ - spec/browsers/webkit_spec.rb
48
52
  - spec/spec_helper.rb
49
53
  - templates/assets/jquery.js
50
54
  - templates/assets/testrunner.js
@@ -83,8 +87,10 @@ specification_version: 3
83
87
  summary: Automated jQuery tests with QUnit
84
88
  test_files:
85
89
  - spec/browser_spec.rb
90
+ - spec/browsers/chrome_spec.rb
86
91
  - spec/browsers/firefox_spec.rb
87
92
  - spec/browsers/internet_explorer_spec.rb
88
93
  - spec/browsers/konqueror_spec.rb
89
94
  - spec/browsers/opera_spec.rb
90
95
  - spec/browsers/safari_spec.rb
96
+ - spec/browsers/webkit_spec.rb
@@ -1,114 +0,0 @@
1
- h1. Automated jQuery tests with QUnit
2
-
3
- h2. Installation
4
-
5
- (sudo) gem install jodosha-hanoi -s http://gems.github.com
6
-
7
- h2. Crash Course
8
-
9
- hanoi # prepare the target directory
10
- rake test:js # run the tests
11
-
12
- h2. How To Use
13
-
14
- Prepare the target directory, you can use one of the following options:
15
-
16
- hanoi
17
- hanoi .
18
- hanoi /path/to/project
19
-
20
- You need a valid "Rake":http://rake.rubyforge.org/ installation to run your tests:
21
-
22
- rake test:js
23
-
24
- You can specify to run the test against one or more browsers:
25
-
26
- rake test:js BROWSERS=firefox,ie,safari
27
-
28
- You can specify to run only certain tests:
29
-
30
- rake test:js TESTS=path/to/first_test.js,path/to/second_test.js
31
-
32
- You can combine both @BROWSERS@ and @TESTS@ configurations.
33
-
34
- h2. Structure
35
-
36
- The @hanoi@ executable will create the following structure:
37
-
38
- Rakefile
39
- test/
40
- javascript/
41
- assets/
42
- jquery.js
43
- testrunner.js
44
- testsuite.css
45
- example_test.js
46
- fixtures/
47
- example_fixtures.html
48
- templates/
49
- test_case.erb
50
-
51
- * @Rakefile@ creates a fresh rakefile, *you have to edit* it according to your setup
52
- * @test@ Hanoi creates it if missing, otherwise will choose between existing @test@ or @spec@ paths
53
- * @javascript@ is the root directory of your tests
54
- * @assets@ contains the jQuery and QUnit source file and a css.
55
- Place your assets in this directory, it's mapped as root path @/@.
56
- * @example_test.js@ is a sample of a real test case.
57
- * @templates@ contains the template file for your tests. You shouldn't edit it, if you don't know the risk.
58
- * @fixtures@ contains all the HTML fixtures, each file will be injected into the proper case.
59
-
60
- By convention, your @test/javascript@ folder *should reflect* the structure of your source directory,
61
- appending the @_test.js@ suffix to each test case and the @_fixtures.html@ to each fixture file.
62
-
63
- Example:
64
-
65
- src/
66
- directory_a/
67
- directory_b/
68
- file_3.js
69
- file_2.js
70
- file_1.js
71
- test/
72
- javascript/
73
- directory_a/
74
- directory_b/
75
- file_3_test.js
76
- file_2_test.js
77
- file_1_test.js
78
- fixtures/
79
- directory_a/
80
- directory_b/
81
- file_3_fixtures.html
82
- file_1_fixtures.html
83
-
84
- You have probably noticed that @file_2_fixtures.html@ is missing, this because *fixtures are optional*.
85
-
86
- h2. Browsers & Platforms
87
-
88
- h3. Platforms:
89
-
90
- * MacOS
91
- * Windows
92
- * Linux
93
-
94
- h3. Browsers:
95
-
96
- * Firefox
97
- * Safari
98
- * Internet Explorer
99
- * Opera
100
- * Konqueror
101
-
102
- h2. Acknowledgements
103
-
104
- The Ruby libraries of Hanoi are a customization of the jsblib.rb, courtesy of the "Prototype":http://prototypejs.org team.
105
-
106
- Hanoi runs a customized version of QUnit, courtesy of the "jQuery":http://jquery.com team.
107
-
108
- h2. Repository
109
-
110
- git clone git://github.com/jodosha/hanoi.git
111
-
112
- h2. Copyright
113
-
114
- (c) 2009 Luca Guidi - "http://lucaguidi.com":http://lucaguidi.com, released under the MIT license