Remove references to RAILS_ROOT from Webrat core

This commit is contained in:
Bryan Helmkamp 2008-05-12 00:58:24 -04:00
parent 22048b5494
commit e6aff6d37c
8 changed files with 38 additions and 24 deletions

View File

@ -56,7 +56,7 @@ end
require 'spec/rake/verify_rcov'
RCov::VerifyTask.new(:verify_rcov => :rcov) do |t|
t.threshold = 97.1 # Make sure you have rcov 0.7 or higher!
t.threshold = 96.9 # Make sure you have rcov 0.7 or higher!
end
remove_task "default"

View File

@ -291,7 +291,8 @@ module Webrat
end
def rewrite_css_and_image_references(response_html) # :nodoc
response_html.gsub(/"\/(stylesheets|images)/, RAILS_ROOT + '/public/\1')
return response_html unless session.doc_root
response_html.gsub(/"\/(stylesheets|images)/, session.doc_root + '/\1')
end
end

View File

@ -1,6 +1,10 @@
module Webrat
class Session
def doc_root
nil
end
def saved_page_dir
File.expand_path(".")
end

View File

@ -5,6 +5,10 @@ module Webrat
@integration_session = integration_session
end
def doc_root
File.expand_path(File.join(RAILS_ROOT, 'public'))
end
def saved_page_dir
File.expand_path(File.join(RAILS_ROOT, "tmp"))
end

View File

@ -1,7 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
RAILS_ROOT = "." unless defined?(RAILS_ROOT)
describe "reloads" do
before do
@session = Webrat::TestSession.new

View File

@ -1,48 +1,53 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
RAILS_ROOT = "." unless defined?(RAILS_ROOT)
describe "save_and_open_page" do
before do
@session = Webrat::TestSession.new
@session.response_body = <<-HTML
<html><head>
<link href="/stylesheets/foo.css" media="screen" rel="stylesheet" type="text/css" />
</head><body>
<h1>Hello world</h1>
<img src="/images/bar.png" />
</body></html>
<html>
<head>
<link href="/stylesheets/foo.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Hello world</h1>
<img src="/images/bar.png" />
</body>
</html>
HTML
File.stubs(:exist?).returns(true)
Time.stubs(:now).returns(1234)
Webrat::Page.any_instance.stubs(:open_in_browser)
@file_handle = mock()
File.stubs(:open).with(filename, 'w').yields(@file_handle)
@file_handle.stubs(:write)
end
it "should rewrite css rules" do
file_handle = mock()
File.expects(:open).with(filename, 'w').yields(file_handle)
file_handle.expects(:write).with{|html| html =~ %r|#{RAILS_ROOT}/public/stylesheets/foo.css|s }
Webrat::Page.any_instance.stubs(:open_in_browser)
@file_handle.expects(:write).with do |html|
html =~ %r|#{@session.doc_root}/stylesheets/foo.css|s
end
@session.save_and_open_page
end
it "should rewrite image paths" do
file_handle = mock()
File.expects(:open).with(filename, 'w').yields(file_handle)
file_handle.expects(:write).with{|html| html =~ %r|#{RAILS_ROOT}/public/images/bar.png|s }
Webrat::Page.any_instance.stubs(:open_in_browser)
@file_handle.expects(:write).with do |html|
html =~ %r|#{@session.doc_root}/images/bar.png|s
end
@session.save_and_open_page
end
it "should open the temp file in a browser" do
File.stubs(:open)
Webrat::Page.any_instance.expects(:open_in_browser).with(filename)
@session.save_and_open_page
end
def filename
File.expand_path("./webrat-1234.html")
File.expand_path("./webrat-#{Time.now}.html")
end
end

View File

@ -1,7 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
RAILS_ROOT = "." unless defined?(RAILS_ROOT)
describe "visits" do
before do
@session = Webrat::TestSession.new

View File

@ -3,6 +3,10 @@ module Webrat
attr_accessor :response_body
attr_writer :response_code
def doc_root
File.expand_path(File.join(".", "public"))
end
def response_code
@response_code || 200
end