Class: Approvals

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_approvals/rspec/approvals.rb

Overview

Top-level class to provide approval test support (inspired by approvaltests.com/)

Class Method Summary collapse

Class Method Details

.verify(rendered_content, approved_path, **options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/simple_approvals/rspec/approvals.rb', line 4

def verify(rendered_content, approved_path, **options)
  scrubbed_content = apply_optional_scrubber(rendered_content, options)
  pre_approve_if_asked(approved_path, scrubbed_content, options)

  expected_content = load_expected_content(approved_path, options)
  received_path = received_path_for approved_path

  if scrubbed_content.strip.empty?
    raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, options) unless options[:allow_empty]
  elsif scrubbed_content.strip == expected_content.strip
    handle_match(received_path, scrubbed_content, options)
  else
    raise_verify_error_with_diff(approved_path, received_path, scrubbed_content, options)
  end
end