summaryrefslogtreecommitdiff
path: root/features/support/hooks.rb
blob: f2e3b418f17f6ef3663f915354eb7545deffffb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
After '@tempfile' do
  if @tempfile
    @tempfile.close
    @tempfile.unlink
  end
end

Around '@config' do |scenario, block|
  old_config = APP_CONFIG.dup
  block.call
  APP_CONFIG.replace old_config
end

# store end of server log for failing scenarios
After do |scenario|
  if scenario.failed?
    logfile_path = Rails.root + 'tmp'
    logfile_path += "#{scenario.title.gsub(/\s/, '_')}.log"
    File.open(logfile_path, 'w') do |test_log|
      test_log.puts scenario.title
      test_log.puts "========================="
      test_log.puts `tail log/test.log -n 200`
    end
  end
end

# clear all records we created
After do
  names = self.instance_variables.reject do |v|
    v.to_s.starts_with?('@_')
  end
  names.each do |name|
    record = self.instance_variable_get name
    if record.is_a?(CouchRest::Model::Base) && record.persisted?
      record.reload && record.destroy
    end
  end
end