zfben_hanoi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,45 @@
1
+ class TestCase
2
+ attr_reader :path
3
+
4
+ def initialize(path, test_directory)
5
+ @path, @test_directory = path, test_directory
6
+ end
7
+
8
+ def name
9
+ @name ||= File.basename(@path, '.js')
10
+ end
11
+
12
+ def target
13
+ "/javascripts/#{relative_path.gsub(/(_test|_spec)/, '')}"
14
+ end
15
+
16
+ def content
17
+ File.new(@path).read
18
+ end
19
+
20
+ def exist?
21
+ File.exist?(path)
22
+ end
23
+
24
+ def relative_path
25
+ @relative_path ||= @path.gsub("#{@test_directory}/", "")
26
+ end
27
+
28
+ def url
29
+ "/test/#{relative_path.gsub('.js', '')}.html"
30
+ end
31
+
32
+ def create_temp_directory
33
+ FileUtils.mkdir_p temp_directory
34
+ end
35
+
36
+ def temp_directory
37
+ @temp_directory ||= File.dirname(File.expand_path(@path).gsub(@test_directory, "#{@test_directory}/tmp"))
38
+ end
39
+
40
+ def html_fixtures
41
+ path = File.dirname(File.expand_path(@path).gsub(@test_directory, "#{@test_directory}/fixtures"))
42
+ path = File.expand_path(path + "/#{name.gsub(/(_test|_spec)/, '_fixtures.html')}")
43
+ File.new(path).read rescue ""
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ class TestResults
2
+ attr_reader :modules, :tests, :assertions, :failures, :errors, :filename
3
+ def initialize(query, filename)
4
+ @modules = query['modules'].to_i
5
+ @tests = query['tests'].to_i
6
+ @assertions = query['assertions'].to_i
7
+ @failures = query['failures'].to_i
8
+ @errors = query['errors'].to_i
9
+ @filename = filename
10
+ end
11
+
12
+ def error?
13
+ @errors > 0
14
+ end
15
+
16
+ def failure?
17
+ @failures > 0
18
+ end
19
+
20
+ def to_s
21
+ return "E" if error?
22
+ return "F" if failure?
23
+ "."
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ class TestSuiteResults
2
+ def initialize
3
+ @modules = 0
4
+ @tests = 0
5
+ @assertions = 0
6
+ @failures = 0
7
+ @errors = 0
8
+ @error_files = []
9
+ @failure_files = []
10
+ end
11
+
12
+ def <<(result)
13
+ @modules += result.modules
14
+ @tests += result.tests
15
+ @assertions += result.assertions
16
+ @failures += result.failures
17
+ @errors += result.errors
18
+ @error_files.push(result.filename) if result.error?
19
+ @failure_files.push(result.filename) if result.failure?
20
+ end
21
+
22
+ def error?
23
+ @errors > 0
24
+ end
25
+
26
+ def failure?
27
+ @failures > 0
28
+ end
29
+
30
+ def to_s
31
+ str = ""
32
+ str << "\n Failures: #{@failure_files.join(', ')}" if failure?
33
+ str << "\n Errors: #{@error_files.join(', ')}" if error?
34
+ "#{str}\n#{summary}\n\n"
35
+ end
36
+
37
+ def summary
38
+ "#{@modules} modules, #{@tests} tests, #{@assertions} assertions, #{@failures} failures, #{@errors} errors."
39
+ end
40
+ end
@@ -0,0 +1,103 @@
1
+ # shut up, webrick :-)
2
+ class ::WEBrick::HTTPServer
3
+ def access_log(config, req, res)
4
+ # nop
5
+ end
6
+ end
7
+
8
+ class ::WEBrick::BasicLog
9
+ def log(level, data)
10
+ # nop
11
+ end
12
+ end
13
+
14
+ class WEBrick::HTTPResponse
15
+ alias send send_response
16
+ def send_response(socket)
17
+ send(socket) unless fail_silently?
18
+ end
19
+
20
+ def fail_silently?
21
+ @fail_silently
22
+ end
23
+
24
+ def fail_silently
25
+ @fail_silently = true
26
+ end
27
+ end
28
+
29
+ class WEBrick::HTTPRequest
30
+ def to_json
31
+ headers = []
32
+ each { |k, v| headers.push "#{k.inspect}: #{v.inspect}" }
33
+ headers = "{" << headers.join(', ') << "}"
34
+ %({ "headers": #{headers}, "body": #{body.inspect}, "method": #{request_method.inspect} })
35
+ end
36
+ end
37
+
38
+ class WEBrick::HTTPServlet::AbstractServlet
39
+ def prevent_caching(res)
40
+ res['ETag'] = nil
41
+ res['Last-Modified'] = Time.now + 100**4
42
+ res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
43
+ res['Pragma'] = 'no-cache'
44
+ res['Expires'] = Time.now - 100**4
45
+ end
46
+ end
47
+
48
+ class BasicServlet < WEBrick::HTTPServlet::AbstractServlet
49
+ def do_GET(req, res)
50
+ prevent_caching(res)
51
+ res['Content-Type'] = "text/plain"
52
+
53
+ req.query.each do |k, v|
54
+ res[k] = v unless k == 'responseBody'
55
+ end
56
+ res.body = req.query["responseBody"]
57
+
58
+ raise WEBrick::HTTPStatus::OK
59
+ end
60
+
61
+ def do_POST(req, res)
62
+ do_GET(req, res)
63
+ end
64
+ end
65
+
66
+ class SlowServlet < BasicServlet
67
+ def do_GET(req, res)
68
+ sleep(2)
69
+ super
70
+ end
71
+ end
72
+
73
+ class DownServlet < BasicServlet
74
+ def do_GET(req, res)
75
+ res.fail_silently
76
+ end
77
+ end
78
+
79
+ class InspectionServlet < BasicServlet
80
+ def do_GET(req, res)
81
+ prevent_caching(res)
82
+ res['Content-Type'] = "application/json"
83
+ res.body = req.to_json
84
+ raise WEBrick::HTTPStatus::OK
85
+ end
86
+ end
87
+
88
+ class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler
89
+ def do_GET(req, res)
90
+ super
91
+ set_default_content_type(res, req.path)
92
+ prevent_caching(res)
93
+ end
94
+
95
+ def set_default_content_type(res, path)
96
+ res['Content-Type'] = case path
97
+ when /\.js$/ then 'text/javascript'
98
+ when /\.html$/ then 'text/html'
99
+ when /\.css$/ then 'text/css'
100
+ else 'text/plain'
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,16 @@
1
+ require "erb"
2
+ require "webrick"
3
+ require "rake/tasklib"
4
+ require "hanoi/webrick"
5
+ require "hanoi/browser"
6
+ require "hanoi/browsers/chrome"
7
+ require "hanoi/browsers/firefox"
8
+ require "hanoi/browsers/internet_explorer"
9
+ require "hanoi/browsers/konqueror"
10
+ require "hanoi/browsers/webkit"
11
+ require "hanoi/browsers/safari"
12
+ require "hanoi/browsers/opera"
13
+ require "hanoi/test_case"
14
+ require "hanoi/test_results"
15
+ require "hanoi/test_suite_results"
16
+ require "hanoi/javascript_test_task"
@@ -0,0 +1,68 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe "Browser" do
4
+ before(:each) do
5
+ @browser = Browser.new
6
+ end
7
+
8
+ it "should be supported by default" do
9
+ @browser.should be_supported
10
+ end
11
+
12
+ it "should recognize the current platform" do
13
+ method = case @browser.host
14
+ when /darwin/
15
+ :macos?
16
+ when /mswin/, /mingw/
17
+ :windows?
18
+ when /linux/
19
+ :linux?
20
+ end
21
+
22
+ @browser.send(method).should be_true
23
+ end
24
+
25
+ describe "Cross OS Browser", :shared => true do
26
+ it "should check if installed" do
27
+ File.should_receive(:exist?).and_return true
28
+ @browser.should be_installed
29
+
30
+ File.should_receive(:exist?).and_return false
31
+ @browser.should_not be_installed
32
+ end
33
+
34
+ it "should check if runnable" do
35
+ File.should_receive(:exist?).and_return true
36
+ @browser.should be_runnable
37
+
38
+ File.should_receive(:exist?).and_return false
39
+ @browser.should_not be_runnable
40
+ end
41
+ end
42
+
43
+ describe "Mac Os X" do
44
+ it_should_behave_like "Cross OS Browser"
45
+ end if macos?
46
+
47
+ describe "Windows" do
48
+ it_should_behave_like "Cross OS Browser"
49
+ end if windows?
50
+
51
+ describe "Linux" do
52
+ it "should check if installed" do
53
+ Kernel.should_receive(:system).with("which browser").and_return true
54
+ @browser.should be_installed
55
+
56
+ Kernel.should_receive(:system).with("which browser").and_return false
57
+ @browser.should_not be_installed
58
+ end
59
+
60
+ it "should check if runnable" do
61
+ Kernel.should_receive(:system).with("which browser").and_return true
62
+ @browser.should be_runnable
63
+
64
+ Kernel.should_receive(:system).with("which browser").and_return false
65
+ @browser.should_not be_runnable
66
+ end
67
+ end if linux?
68
+ end
@@ -0,0 +1,65 @@
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
+ expected = File.join(
38
+ ENV['UserPath'] || ENV['UserProfile'] || "C:/Documents and Settings/Administrator",
39
+ "AppData",
40
+ "Local",
41
+ "Google",
42
+ "Chrome",
43
+ "Application",
44
+ "chrome.exe"
45
+ )
46
+
47
+ @browser.path.should == expected
48
+ end
49
+
50
+ it "should visit a given url" do
51
+ Kernel.expects(:system).with("#{@browser.path} #{@url}")
52
+ @browser.visit(@url)
53
+ end
54
+ end if windows?
55
+
56
+ describe "Linux" do
57
+ it "return name" do
58
+ @browser.name.should == "Google Chrome"
59
+ end
60
+
61
+ it "should not be supported" do
62
+ @browser.should_not be_supported
63
+ end
64
+ end if linux?
65
+ end
@@ -0,0 +1,67 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+
3
+ describe "Firefox" do
4
+ before(:each) do
5
+ @browser = Firefox.new
6
+ @url = "http://localhost"
7
+ end
8
+
9
+ describe "Cross OS Firefox", :shared => true do
10
+ it "should be supported" do
11
+ @browser.should be_supported
12
+ end
13
+ end
14
+
15
+ describe "Mac OS X" do
16
+ it_should_behave_like "Cross OS Firefox"
17
+
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
@@ -0,0 +1,50 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+
3
+ describe "InternetExplorer" do
4
+ before :each do
5
+ @browser = InternetExplorer.new
6
+ @url = "http://localhost"
7
+ end
8
+
9
+ describe "Cross OS Internet Explorer", :shared => true do
10
+ it "should not be supported" do
11
+ @browser.should_not be_supported
12
+ end
13
+
14
+ it "return name" do
15
+ @browser.name.should == "Internet Explorer"
16
+ end
17
+ end
18
+
19
+ describe "Mac OS X" do
20
+ it_should_behave_like "Cross OS Internet Explorer"
21
+ end if macos?
22
+
23
+ describe "Windows" do
24
+ it "return name" do
25
+ @browser.name.should == "Internet Explorer"
26
+ end
27
+
28
+ it "should be supported" do
29
+ @browser.should be_supported
30
+ end
31
+
32
+ it "should be runnable" do
33
+ @browser.should be_runnable
34
+ end
35
+
36
+ it "should setup" do
37
+ Kernel.expects(:require).with('win32ole')
38
+ lambda { @browser.setup }.should_not raise_error
39
+ end
40
+
41
+ it "should visit a given url" do
42
+ Kernel.expects(:system).with("#{@browser.path} #{@url}")
43
+ @browser.visit(@url)
44
+ end
45
+ end if windows?
46
+
47
+ describe "Linux" do
48
+ it_should_behave_like "Cross OS Internet Explorer"
49
+ end if linux?
50
+ end