Module: Capybara::Differ

Defined in:
lib/capybara-differ.rb,
lib/capybara-differ/version.rb

Defined Under Namespace

Classes: Comparator

Constant Summary collapse

VERSION =
"0.2.1"

Instance Method Summary collapse

Instance Method Details

#check_page(name, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/capybara-differ.rb', line 73

def check_page(name, options = {})
  raise ArgumentError, 'options must be hash' unless options.is_a?(Hash)
  path_from_name = name.gsub(/[^a-z0-9\-_]+/i, '_')
  filename = File.join(path_from_name, Time.now.strftime('%Y%m%d%H%M%S') + '.html')
  save_page(filename)

  base_dir = File.join([Capybara.save_path, path_from_name].compact)
  file_list = Dir[File.join(base_dir, '*.html')].sort
  old_html_path = options[:compare_with] == :previous ? file_list[-2] : file_list.first
  new_html_path = file_list.last

  comparator = Capybara::Differ::Comparator.new(old_html_path, new_html_path, options)
  if (result = comparator.compare).strip.size > 0
    puts result
  else
    puts "No difference on '#{path_from_name}' snapshots"
  end
end