Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11419: patch.txt

File patch.txt, 3.7 kB (added by grosser, 6 months ago)

patch

Line 
1 Index: C:/Users/Admin/Desktop/short/vendor/plugins/javascript_test/lib/javascript_test.rb
2 ===================================================================
3 --- C:/Users/Admin/Desktop/short/vendor/plugins/javascript_test/lib/javascript_test.rb  (revision 74)
4 +++ C:/Users/Admin/Desktop/short/vendor/plugins/javascript_test/lib/javascript_test.rb  (working copy)
5 @@ -5,6 +5,14 @@
6  class JavaScriptTest
7    
8    class Browser
9 +    def initialize(path='')
10 +      @path = path
11 +    end
12 +   
13 +    def validate_path
14 +      raise "Not found #{@path}" if windows? && !File.exists?(@path)
15 +    end
16 +   
17      def supported?; true; end
18      def setup ; end
19      def open(url) ; end
20 @@ -35,12 +43,13 @@
21    
22    class FirefoxBrowser < Browser
23      def initialize(path='c:\Program Files\Mozilla Firefox\firefox.exe')
24 -      @path = path
25 +      super path
26 +       validate_path
27      end
28 @@ -73,7 +82,8 @@
29    
30    class IEBrowser < Browser
31      def initialize(path='C:\Program Files\Internet Explorer\IEXPLORE.EXE')
32 -      @path = path
33 +      super path
34 +       validate_path
35      end
36      
37      def setup
38 @@ -149,8 +159,9 @@
39        @queue = Queue.new
40    
41        result = []
42
43 -      @server = WEBrick::HTTPServer.new(:Port => 4711) # TODO: make port configurable
44 +     
45 +      @port = 4711# TODO: make port configurable
46 +      @server = WEBrick::HTTPServer.new(:Port => @port)
47        @server.mount_proc("/results") do |req, res|
48          @queue.push(req.query['result'])
49          res.body = "OK"
50 @@ -165,7 +176,7 @@
51      end
52    
53      def define
54 -      trap("INT") { @server.shutdown }
55 +      trap_init {@server.shutdown}
56        t = Thread.new { @server.start }
57        
58        # run all combinations of browsers and tests
59 @@ -173,12 +184,15 @@
60          if browser.supported?
61            browser.setup
62            @tests.each do |test|
63 -            browser.visit("http://localhost:4711#{test}?resultsURL=http://localhost:4711/results&t=" + ("%.6f" % Time.now.to_f))
64 -            result = @queue.pop
65 -            puts "#{test} on #{browser}: #{result}"
66 +             puts "#{test} on #{browser}:"
67 +           
68 +             #run test
69 +             browser.visit("http://localhost:#{@port}#{test}?resultsURL=http://localhost:#{@port}/results&t=" + ("%.6f" % Time.now.to_f))
70 +             result = @queue.pop
71 +           
72 +             puts result
73              @result = false unless result == 'SUCCESS'
74            end
75 -          browser.teardown
76          else
77            puts "Skipping #{browser}, not supported on this OS"
78          end
79 @@ -188,6 +202,19 @@
80        @server.shutdown
81        t.join
82      end
83 +   
84 +    def trap_init
85 +       trap("INT") do
86 +         exit if @int_received_once
87 +       
88 +        @int_received_once = true
89 +        puts %{
90 +          Shutting down, please wait...
91 +          Hitting ctr+c again will exit the process but leave the server running!
92 +        }
93 +        yield
94 +      end 
95 +    end
96    
97      def mount(path, dir=nil)
98        dir ||= (Dir.pwd + path)
99 @@ -203,23 +230,15 @@
100        end
101        @tests << url
102      end
103 +
104 +    def browser(browser,path='')
105 +      begin
106 +         browser = eval("#{browser.to_s.capitalize}Browser.new" + (path.empty? ? '':' path'))
107 +        @browsers<<browser
108 +      rescue
109 +         puts $!
110 +      end
111    
112 -    def browser(browser)
113 -      browser =
114 -        case(browser)
115 -          when :firefox
116 -            FirefoxBrowser.new
117 -          when :safari
118 -            SafariBrowser.new
119 -          when :ie
120 -            IEBrowser.new
121 -          when :konqueror
122 -            KonquerorBrowser.new
123 -          else
124 -            browser
125 -        end
126
127 -      @browsers<<browser
128      end
129    end
130