diff --git a/Rakefile b/Rakefile index 601fac3..2498171 100644 --- a/Rakefile +++ b/Rakefile @@ -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" diff --git a/lib/webrat/core/page.rb b/lib/webrat/core/page.rb index 6b7f44a..ce964b1 100644 --- a/lib/webrat/core/page.rb +++ b/lib/webrat/core/page.rb @@ -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 diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 30876dc..6bcf3ee 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -1,6 +1,10 @@ module Webrat class Session + def doc_root + nil + end + def saved_page_dir File.expand_path(".") end diff --git a/lib/webrat/rails/rails_session.rb b/lib/webrat/rails/rails_session.rb index 960fc71..0396ba6 100644 --- a/lib/webrat/rails/rails_session.rb +++ b/lib/webrat/rails/rails_session.rb @@ -4,6 +4,10 @@ module Webrat def initialize(integration_session) @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")) diff --git a/spec/api/reloads_spec.rb b/spec/api/reloads_spec.rb index 5a0861d..129a9d8 100644 --- a/spec/api/reloads_spec.rb +++ b/spec/api/reloads_spec.rb @@ -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 diff --git a/spec/api/save_and_open_spec.rb b/spec/api/save_and_open_spec.rb index 6750116..1a5a689 100644 --- a/spec/api/save_and_open_spec.rb +++ b/spec/api/save_and_open_spec.rb @@ -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 - - - -

Hello world

- - + + + + + +

Hello world

+ + + 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 diff --git a/spec/api/visits_spec.rb b/spec/api/visits_spec.rb index df50c96..5b37327 100644 --- a/spec/api/visits_spec.rb +++ b/spec/api/visits_spec.rb @@ -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 diff --git a/spec/fakes/test_session.rb b/spec/fakes/test_session.rb index e173092..dd4efb3 100644 --- a/spec/fakes/test_session.rb +++ b/spec/fakes/test_session.rb @@ -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