module RSpec::Approvals

Public Instance Methods

approval_directory() click to toggle source

The directory containing this spec’s approvals

# File lib/git/approvals/rspec.rb, line 42
def approval_directory
  example.file_path.sub /\.rb$/, ''
end
approval_filename() click to toggle source

The approval filename

# 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_path() click to toggle source

The path to the approval for this example

# File lib/git/approvals/rspec.rb, line 27
def approval_path
  File.join approval_directory, approval_filename
end
verify( options={}, &block ) click to toggle source

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

# 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