public
Description: Webrat - Ruby Acceptance Testing for Web applications
Homepage: http://www.brynary.com/uploads/webrat/rdoc/index.html
Clone URL: git://github.com/brynary/webrat.git
Remove references to RAILS_ROOT from Webrat core
brynary (author)
Sun May 11 21:58:24 -0700 2008
commit  e6aff6d37c69b21d99e095d44fe4d38a3c0113de
tree    b5086200eab6b01c12e4850b0f4346d5c94966c0
parent  22048b5494630a67e2d097ac1f4fddfc421755b8
...
56
57
58
59
 
60
61
62
...
56
57
58
 
59
60
61
62
0
@@ -56,7 +56,7 @@ end
0
 
0
 require 'spec/rake/verify_rcov'
0
 RCov::VerifyTask.new(:verify_rcov => :rcov) do |t|
0
- t.threshold = 97.1 # Make sure you have rcov 0.7 or higher!
0
+ t.threshold = 96.9 # Make sure you have rcov 0.7 or higher!
0
 end
0
 
0
 remove_task "default"
...
291
292
293
294
 
 
295
296
297
...
291
292
293
 
294
295
296
297
298
0
@@ -291,7 +291,8 @@ module Webrat
0
     end
0
     
0
     def rewrite_css_and_image_references(response_html) # :nodoc
0
- response_html.gsub(/"\/(stylesheets|images)/, RAILS_ROOT + '/public/\1')
0
+ return response_html unless session.doc_root
0
+ response_html.gsub(/"\/(stylesheets|images)/, session.doc_root + '/\1')
0
     end
0
     
0
   end
...
1
2
3
 
 
 
 
4
5
6
...
1
2
3
4
5
6
7
8
9
10
0
@@ -1,6 +1,10 @@
0
 module Webrat
0
   class Session
0
     
0
+ def doc_root
0
+ nil
0
+ end
0
+
0
     def saved_page_dir
0
       File.expand_path(".")
0
     end
...
4
5
6
 
 
 
 
7
8
9
...
4
5
6
7
8
9
10
11
12
13
0
@@ -4,6 +4,10 @@ module Webrat
0
     def initialize(integration_session)
0
       @integration_session = integration_session
0
     end
0
+
0
+ def doc_root
0
+ File.expand_path(File.join(RAILS_ROOT, 'public'))
0
+ end
0
     
0
     def saved_page_dir
0
       File.expand_path(File.join(RAILS_ROOT, "tmp"))
...
1
2
3
4
5
6
7
...
1
2
 
 
3
4
5
0
@@ -1,7 +1,5 @@
0
 require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
0
 
0
-RAILS_ROOT = "." unless defined?(RAILS_ROOT)
0
-
0
 describe "reloads" do
0
   before do
0
     @session = Webrat::TestSession.new
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
 
 
 
 
 
 
 
 
16
17
18
19
 
 
 
 
 
20
21
22
23
24
25
26
 
 
 
 
27
28
29
30
31
32
33
34
 
 
 
 
35
36
37
38
39
40
41
42
43
44
45
 
46
47
48
...
1
2
 
 
3
4
5
6
7
 
 
 
 
 
 
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
 
 
 
29
30
31
32
33
34
35
36
 
 
 
 
37
38
39
40
41
42
43
44
 
45
46
47
48
49
 
50
51
52
53
0
@@ -1,48 +1,53 @@
0
 require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
0
 
0
-RAILS_ROOT = "." unless defined?(RAILS_ROOT)
0
-
0
 describe "save_and_open_page" do
0
   before do
0
     @session = Webrat::TestSession.new
0
 
0
     @session.response_body = <<-HTML
0
- <html><head>
0
- <link href="/stylesheets/foo.css" media="screen" rel="stylesheet" type="text/css" />
0
- </head><body>
0
- <h1>Hello world</h1>
0
- <img src="/images/bar.png" />
0
- </body></html>
0
+ <html>
0
+ <head>
0
+ <link href="/stylesheets/foo.css" media="screen" rel="stylesheet" type="text/css" />
0
+ </head>
0
+ <body>
0
+ <h1>Hello world</h1>
0
+ <img src="/images/bar.png" />
0
+ </body>
0
+ </html>
0
     HTML
0
 
0
     File.stubs(:exist?).returns(true)
0
     Time.stubs(:now).returns(1234)
0
+ Webrat::Page.any_instance.stubs(:open_in_browser)
0
+
0
+ @file_handle = mock()
0
+ File.stubs(:open).with(filename, 'w').yields(@file_handle)
0
+ @file_handle.stubs(:write)
0
   end
0
 
0
   it "should rewrite css rules" do
0
- file_handle = mock()
0
- File.expects(:open).with(filename, 'w').yields(file_handle)
0
- file_handle.expects(:write).with{|html| html =~ %r|#{RAILS_ROOT}/public/stylesheets/foo.css|s }
0
- Webrat::Page.any_instance.stubs(:open_in_browser)
0
+ @file_handle.expects(:write).with do |html|
0
+ html =~ %r|#{@session.doc_root}/stylesheets/foo.css|s
0
+ end
0
+
0
     @session.save_and_open_page
0
   end
0
   
0
   it "should rewrite image paths" do
0
- file_handle = mock()
0
- File.expects(:open).with(filename, 'w').yields(file_handle)
0
- file_handle.expects(:write).with{|html| html =~ %r|#{RAILS_ROOT}/public/images/bar.png|s }
0
- Webrat::Page.any_instance.stubs(:open_in_browser)
0
+ @file_handle.expects(:write).with do |html|
0
+ html =~ %r|#{@session.doc_root}/images/bar.png|s
0
+ end
0
+
0
     @session.save_and_open_page
0
   end
0
   
0
   it "should open the temp file in a browser" do
0
- File.stubs(:open)
0
     Webrat::Page.any_instance.expects(:open_in_browser).with(filename)
0
     @session.save_and_open_page
0
   end
0
   
0
   def filename
0
- File.expand_path("./webrat-1234.html")
0
+ File.expand_path("./webrat-#{Time.now}.html")
0
   end
0
 
0
 end
...
1
2
3
4
5
6
7
...
1
2
 
 
3
4
5
0
@@ -1,7 +1,5 @@
0
 require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
0
 
0
-RAILS_ROOT = "." unless defined?(RAILS_ROOT)
0
-
0
 describe "visits" do
0
   before do
0
     @session = Webrat::TestSession.new
...
3
4
5
 
 
 
 
6
7
8
...
3
4
5
6
7
8
9
10
11
12
0
@@ -3,6 +3,10 @@ module Webrat
0
     attr_accessor :response_body
0
     attr_writer :response_code
0
     
0
+ def doc_root
0
+ File.expand_path(File.join(".", "public"))
0
+ end
0
+
0
     def response_code
0
       @response_code || 200
0
     end

Comments

  • newbamboo Thu Jun 05 03:37:54 -0700 2008

    Hi. I get load orders on Ubuntu from core.rb

    Adding “sort” to the file require loop fixes this.

    Dir[File.join(File.dirname(FILE), “core”, ”*.rb”)].sort.each do |file| ... end