Class: Suture::Adapter::Dictaphone

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/suture/adapter/dictaphone.rb

Instance Method Summary collapse

Methods included from Log

#log_debug, #log_error, #log_info, #log_warn, logger, reset!

Constructor Details

#initialize(plan) ⇒ Dictaphone

Returns a new instance of Dictaphone.



12
13
14
15
16
17
18
19
20
# File 'lib/suture/adapter/dictaphone.rb', line 12

def initialize(plan)
  @db = Suture::Wrap::Sqlite.init(plan.database_path)
  @name = plan.name
  @compares_results = Suture::Util::ComparesResults.new(plan.comparator)
  if plan.respond_to?(:args) # does not apply to TestPlan objects
    @args_inspect = plan.args.inspect
    @args_dump = Marshal.dump(plan.args)
  end
end

Instance Method Details

#delete_by_id!(id) ⇒ Object



41
42
43
44
# File 'lib/suture/adapter/dictaphone.rb', line 41

def delete_by_id!(id)
  log_info("deleting call with ID: #{id}")
  Suture::Wrap::Sqlite.delete(@db, :observations, "where id = ?", [id])
end

#delete_by_name!(name) ⇒ Object



46
47
48
49
# File 'lib/suture/adapter/dictaphone.rb', line 46

def delete_by_name!(name)
  log_info("deleting calls for seam named: #{name}")
  Suture::Wrap::Sqlite.delete(@db, :observations, "where name = ?", [name.to_s])
end

#play(only_id = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/suture/adapter/dictaphone.rb', line 31

def play(only_id = nil)
  rows = Suture::Wrap::Sqlite.select(
    @db, :observations,
    "where name = ? #{"and id = ?" if only_id}",
    [@name.to_s, only_id].compact
  )
  log_debug("found #{rows.size} recorded calls for seam #{@name.inspect}.")
  rows.map { |row| row_to_observation(row) }
end

#record(returned_value) ⇒ Object



23
24
25
# File 'lib/suture/adapter/dictaphone.rb', line 23

def record(returned_value)
  record_result(Suture::Value::Result.returned(returned_value))
end

#record_error(error) ⇒ Object



27
28
29
# File 'lib/suture/adapter/dictaphone.rb', line 27

def record_error(error)
  record_result(Suture::Value::Result.errored(error))
end