Module: RSpec::Approvals

Defined in:
lib/git/approvals/rspec.rb

Instance Method Summary collapse

Instance Method Details

#approval_directoryObject

The directory containing this spec’s approvals



42
43
44
# File 'lib/git/approvals/rspec.rb', line 42

def approval_directory
  example.file_path.sub /\.rb$/, ''
end

#approval_filenameObject

The approval filename



33
34
35
36
37
38
# File 'lib/git/approvals/rspec.rb', line 33

def approval_filename
  parts = [ example, *example.example_group.parent_groups ].map do |ex|
    Git::Approvals::Utils.filenamify ex.description
  end
  File.join parts.to_a.reverse
end

#approval_pathObject

The path to the approval for this example



27
28
29
# File 'lib/git/approvals/rspec.rb', line 27

def approval_path
  File.join approval_directory, approval_filename
end

#verify(options = {}, &block) ⇒ Object

Verifies that the result of the block is the same as the approved version.



15
16
17
18
19
20
21
22
23
# File 'lib/git/approvals/rspec.rb', line 15

def verify( options={}, &block )
  approval = Git::Approvals::Approval.new( approval_path, options )
  approval.diff( block.call ) do |err|
    ::RSpec::Expectations.fail_with err
  end
rescue Errno::ENOENT => e
  ::RSpec::Expectations.fail_with e.message
  EOS
end