require "rails_helper"
require 'rack/file'
require ::File.expand_path("../../../lib/cornucopia/util/report_builder", File.dirname(__FILE__))
require ::File.expand_path("../../../lib/cornucopia/capybara/page_diagnostics", File.dirname(__FILE__))
require ::File.expand_path("../../../lib/cornucopia/capybara/finder_extensions", File.dirname(__FILE__))
require ::File.expand_path("../../../lib/cornucopia/capybara/matcher_extensions", File.dirname(__FILE__))
describe Cornucopia::Capybara::PageDiagnostics, type: :feature do
# Make sure that all tests start clean and get cleaned up afterwards...
around(:example) do |example|
expect(File.directory?(Rails.root.join("cornucopia_report/"))).to be_falsey
begin
example.run
ensure
if (Cornucopia::Util::ReportBuilder.class_variable_get("@@current_report"))
Cornucopia::Util::ReportBuilder.current_report.close
end
::Capybara.current_session.driver.window_handles.each do |handle|
if handle != ::Capybara.current_session.driver.current_window_handle
::Capybara.current_session.driver.close_window(handle)
end
end
FileUtils.rm_rf Rails.root.join("cornucopia_report/")
FileUtils.rm_rf Rails.root.join("sample_report/")
end
end
describe "#dump_page_details" do
before(:context) do
file_name_1 = generate_report_file("report_1")
::Capybara.app = Rack::File.new File.absolute_path(File.join(File.dirname(file_name_1), ".."))
end
it "does nothing if Capybara isn't open" do
report = Cornucopia::Util::ReportBuilder.current_report
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report)
report.close
report_text = File.read(report.report_contents_page_name)
expect(report_text).to match /No Errors to report/
end
it "can open a page" do
file_name_1 = generate_report_file("report_1")
::Capybara.current_session.visit("/report_1/#{File.basename(file_name_1)}")
::Capybara.page.has_text?(@last_val)
report = Cornucopia::Util::ReportBuilder.current_report
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report)
report.close
report_text = File.read(report.report_test_contents_page_name)
expect(report_text).not_to match /No Errors to report/
expect(report_text).to match /\>Page Dump:\
expect(report_text).to match /\>\npage_url\n\
expect(report_text).to match /\>\ntitle\n\
expect(report_text).to match /\>\nscreen_shot\n\
expect(report_text).to match /\More Details...\
expect(report_text).to match /\>\nhtml_frame\n\
expect(report_text).to match /\