Module: Approvals::RSpec::DSL

Defined in:
lib/approvals/extensions/rspec/dsl.rb

Instance Method Summary collapse

Instance Method Details

#executable(command, &block) ⇒ Object


6
7
8
# File 'lib/approvals/extensions/rspec/dsl.rb', line 6

def executable(command, &block)
  Approvals::Executable.new(command, &block)
end

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


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/approvals/extensions/rspec/dsl.rb', line 10

def verify(options = {}, &block)
  # Workaround to support both Rspec 2 and 3
  # RSpec.current_example is the Rspec 3 way
  fetch_current_example = ::RSpec.respond_to?(:current_example) ? proc { ::RSpec.current_example } : proc { |context| context.example }
  # /Workaround

  group = eval "self", block.binding
  namer = ::RSpec.configuration.approvals_namer_class.new(fetch_current_example.call(group))
  defaults = {
    :namer => namer
  }
  format = ::RSpec.configuration.approvals_default_format
  defaults[:format] = format if format
  Approvals.verify(block.call, defaults.merge(options))
rescue ApprovalError => e
  if diff_on_approval_failure?
    ::RSpec::Expectations.fail_with(e.message, e.approved_text, e.received_text)
  else
    raise e
  end
end