Save and open page directory specified via configuration
This commit is contained in:
parent
db168bedec
commit
71dcfb327d
|
@ -1,3 +1,7 @@
|
|||
* Minor enhancements
|
||||
|
||||
* Save and open page directory specified via configuration (Noah Davis)
|
||||
|
||||
* Bug fixes
|
||||
|
||||
* Make "should contain" ignore extra whitespace when doing string comparisons (Noah Davis)
|
||||
|
|
|
@ -15,10 +15,6 @@ module Webrat
|
|||
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
||||
end
|
||||
|
||||
def saved_page_dir
|
||||
File.expand_path(File.join(RAILS_ROOT, "tmp"))
|
||||
end
|
||||
|
||||
def get(url, data, headers = nil)
|
||||
do_request(:get, url, data, headers)
|
||||
end
|
||||
|
|
|
@ -26,6 +26,9 @@ module Webrat
|
|||
# Save and open pages with error status codes (500-599) in a browser? Defualts to true.
|
||||
attr_writer :open_error_files
|
||||
|
||||
# Save and open page storage directory, defaults to current directory
|
||||
attr_accessor :saved_pages_dir
|
||||
|
||||
# Which rails environment should the selenium tests be run in? Defaults to selenium.
|
||||
attr_accessor :application_environment
|
||||
webrat_deprecate :selenium_environment, :application_environment
|
||||
|
@ -60,6 +63,7 @@ module Webrat
|
|||
|
||||
def initialize # :nodoc:
|
||||
self.open_error_files = true
|
||||
self.saved_pages_dir = File.expand_path(".")
|
||||
self.application_environment = :test
|
||||
self.application_port = 3001
|
||||
self.application_address = 'localhost'
|
||||
|
|
|
@ -6,9 +6,9 @@ module Webrat
|
|||
# Example:
|
||||
# save_and_open_page
|
||||
def save_and_open_page
|
||||
return unless File.exist?(saved_page_dir)
|
||||
return unless File.exist?(Webrat.configuration.saved_pages_dir)
|
||||
|
||||
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html"
|
||||
filename = "#{Webrat.configuration.saved_pages_dir}/webrat-#{Time.now.to_i}.html"
|
||||
|
||||
File.open(filename, "w") do |f|
|
||||
f.write rewrite_css_and_image_references(response_body)
|
||||
|
@ -29,10 +29,6 @@ module Webrat
|
|||
response_html.gsub(/("|')\/(stylesheets|images)/, '\1' + doc_root + '/\2')
|
||||
end
|
||||
|
||||
def saved_page_dir #:nodoc:
|
||||
File.expand_path(".")
|
||||
end
|
||||
|
||||
def doc_root #:nodoc:
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -195,9 +195,9 @@ EOS
|
|||
|
||||
|
||||
def save_and_open_screengrab
|
||||
return unless File.exist?(saved_page_dir)
|
||||
return unless File.exist?(Webrat.configuration.saved_pages_dir)
|
||||
|
||||
filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.png"
|
||||
filename = "#{Webrat.configuration.saved_pages_dir}/webrat-#{Time.now.to_i}.png"
|
||||
|
||||
if $browser.chrome_backend?
|
||||
$browser.capture_entire_page_screenshot(filename, '')
|
||||
|
|
|
@ -17,6 +17,11 @@ describe Webrat::Configuration do
|
|||
config.should open_error_files
|
||||
end
|
||||
|
||||
it "should default saved_pages_dir to current dir" do
|
||||
config = Webrat::Configuration.new
|
||||
config.saved_pages_dir.should == File.expand_path(".")
|
||||
end
|
||||
|
||||
it "should detect infinite redirects after 10" do
|
||||
config = Webrat::Configuration.new
|
||||
config.infinite_redirect_limit.should == 10
|
||||
|
|
|
@ -76,10 +76,6 @@ describe Webrat::RailsAdapter do
|
|||
end
|
||||
end
|
||||
|
||||
it "should provide a saved_page_dir" do
|
||||
Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:saved_page_dir)
|
||||
end
|
||||
|
||||
it "should provide a doc_root" do
|
||||
Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:doc_root)
|
||||
end
|
||||
|
|
|
@ -22,10 +22,17 @@ describe "save_and_open_page" do
|
|||
Launchy::Browser.stub!(:run)
|
||||
|
||||
@file_handle = mock("file handle")
|
||||
File.stub!(:open).with(filename, 'w').and_yield(@file_handle)
|
||||
File.stub!(:open).and_yield(@file_handle)
|
||||
@file_handle.stub!(:write)
|
||||
end
|
||||
|
||||
it "should save pages to the directory configured" do
|
||||
Webrat.configuration.stub!(:saved_pages_dir => "path/to/dir")
|
||||
File.should_receive(:open).with("path/to/dir/webrat-1234.html", "w").and_yield(@file_handle)
|
||||
|
||||
save_and_open_page
|
||||
end
|
||||
|
||||
it "should rewrite css rules" do
|
||||
@file_handle.should_receive(:write) do |html|
|
||||
html.should =~ %r|"#{webrat_session.doc_root}/stylesheets/foo.css"|s
|
||||
|
@ -63,8 +70,4 @@ describe "save_and_open_page" do
|
|||
end.should_not raise_error
|
||||
end
|
||||
|
||||
def filename
|
||||
File.expand_path("./webrat-#{Time.now}.html")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue