Class: ApprovalTests::Approvers::FileApprover

Inherits:
Object
  • Object
show all
Defined in:
lib/approval_tests/approvers/file_approver.rb

Instance Method Summary collapse

Constructor Details

#initialize(writer, namer) ⇒ FileApprover

Returns a new instance of FileApprover.



6
7
8
9
# File 'lib/approval_tests/approvers/file_approver.rb', line 6

def initialize(writer, namer)
	@writer = writer
	@namer = namer
end

Instance Method Details

#approveObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/approval_tests/approvers/file_approver.rb', line 11

def approve()
	basename = "#{@namer.source_file_path}/#{@namer.approval_name}"
	@approved = @writer.get_approval_filename(basename)
	@received = @writer.get_received_filename(basename)
	@received = @writer.write_received_file(@received)

	unless File.exists?(@approved)
	  @failure = ApprovalError.new("Failed Approval: Approval File \"#{@approved}\" Not Found.")
	  @failure.received_filename = @received
	  @failure.approved_filename = @approved
		return false
	end

	unless FileUtils.cmp(@received, @approved)
	  @failure = ApprovalError.new("Failed Approval: Received file #{@received} does not match approved file #{@approved}.")
	  @failure.received_filename = @received
	  @failure.approved_filename = @approved
		return false
	end

	return true
end

#clean_up_after_successObject



42
43
44
# File 'lib/approval_tests/approvers/file_approver.rb', line 42

def clean_up_after_success()
  File.delete(@received)
end

#failObject

Raises:

  • (@failure)


34
35
36
# File 'lib/approval_tests/approvers/file_approver.rb', line 34

def fail()
  raise @failure
end

#report_failure(reporter) ⇒ Object



38
39
40
# File 'lib/approval_tests/approvers/file_approver.rb', line 38

def report_failure(reporter)
  reporter.report(@approved, @received);
end