1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/spec/save_and_open_page_spec.rb

84 lines
2.4 KiB
Ruby
Raw Normal View History

2009-11-22 12:12:40 -05:00
require File.expand_path('spec_helper', File.dirname(__FILE__))
2010-07-09 21:06:44 -04:00
require 'capybara/util/save_and_open_page'
2009-11-22 12:12:40 -05:00
require 'launchy'
2010-07-09 21:06:44 -04:00
describe Capybara do
describe ".save_save_and_open_page" do
2009-11-22 12:12:40 -05:00
before do
@time = Time.new.strftime("%Y%m%d%H%M%S")
@temp_file = mock("FILE")
2009-11-22 12:12:40 -05:00
@temp_file.stub!(:write)
@temp_file.stub!(:close)
2010-09-15 12:19:50 -04:00
2009-11-22 12:12:40 -05:00
@html = <<-HTML
<html>
<head>
</head>
<body>
<h1>test</h1>
</body>
<html>
HTML
Launchy::Browser.stub(:run)
end
describe "defaults" do
before do
@name = "capybara-#{@time}.html"
2010-09-15 12:19:50 -04:00
@temp_file.stub!(:path).and_return(@name)
File.should_receive(:exist?).and_return true
File.should_receive(:new).and_return @temp_file
end
2010-09-15 12:19:50 -04:00
it "should create a new temporary file" do
@temp_file.should_receive(:write).with @html
2010-07-09 21:06:44 -04:00
Capybara.save_and_open_page @html
end
it "should open the file in the browser" do
2010-07-09 21:06:44 -04:00
Capybara.should_receive(:open_in_browser).with(@name)
Capybara.save_and_open_page @html
end
2009-11-22 12:12:40 -05:00
end
2010-09-15 12:19:50 -04:00
describe "custom output path" do
before do
@custom_path = File.join('tmp', 'capybara')
@custom_name = File.join(@custom_path, "capybara-#{@time}.html")
2009-11-22 12:12:40 -05:00
@temp_file.stub!(:path).and_return(@custom_name)
2010-09-15 12:19:50 -04:00
Capybara.should_receive(:save_and_open_page_path).at_least(:once).and_return(@custom_path)
end
2010-09-15 12:19:50 -04:00
it "should create a new temporary file in the custom path" do
File.should_receive(:directory?).and_return true
File.should_receive(:exist?).and_return true
File.should_receive(:new).and_return @temp_file
2010-09-15 12:19:50 -04:00
@temp_file.should_receive(:write).with @html
2010-07-09 21:06:44 -04:00
Capybara.save_and_open_page @html
end
2010-09-15 12:19:50 -04:00
it "should open the file - in the custom path - in the browser" do
2010-07-09 21:06:44 -04:00
Capybara.should_receive(:open_in_browser).with(@custom_name)
Capybara.save_and_open_page @html
end
2010-09-15 12:19:50 -04:00
it "should be possible to configure output path" do
Capybara.should respond_to(:save_and_open_page_path)
default_setting = Capybara.save_and_open_page_path
lambda {
Capybara.save_and_open_page_path = File.join('tmp', 'capybara')
Capybara.save_and_open_page_path.should == File.join('tmp', 'capybara')
}.should_not raise_error
Capybara.save_and_open_page_path = default_setting
end
2009-11-22 12:12:40 -05:00
end
end
end