File: spec_helper.rb

package info (click to toggle)
ruby-ice-cube 0.16.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 800 kB
  • sloc: ruby: 7,823; makefile: 6
file content (71 lines) | stat: -rw-r--r-- 1,721 bytes parent folder | download | duplicates (2)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'ice_cube'
require 'timeout'

IceCube.compatibility = 12

DAY = Time.utc(2010, 3, 1)
WEDNESDAY = Time.utc(2010, 6, 23, 5, 0, 0)

WORLD_TIME_ZONES = [
  'America/Anchorage',  # -1000 / -0900
  'Europe/London',      # +0000 / +0100
  'Pacific/Auckland',   # +1200 / +1300
]

# TODO: enable warnings here and update specs to call IceCube objects correctly
def Object.const_missing(sym)
  case sym
  when :Schedule, :Rule, :Occurrence, :TimeUtil, :ONE_DAY, :ONE_HOUR, :ONE_MINUTE
    # warn "Use IceCube::#{sym}", caller[0]
    IceCube.const_get(sym)
  else
    super
  end
end

RSpec.configure do |config|
  # Enable flags like --only-failures and --next-failure
  config.example_status_persistence_file_path = ".rspec_status"

  config.expect_with :rspec do |c|
    c.syntax = :expect
  end

  Dir[File.dirname(__FILE__) + '/support/**/*'].each { |f| require f }

  config.warnings = true

  config.include WarningHelpers

  config.before :each do |example|
    if example.metadata[:requires_active_support]
      raise 'ActiveSupport required but not present' unless defined?(ActiveSupport)
    end
  end

  config.around :each, system_time_zone: true do |example|
    orig_zone = ENV['TZ']
    ENV['TZ'] = example.metadata[:system_time_zone]
    example.run
    ENV['TZ'] = orig_zone
  end

  config.around :each, locale: true do |example|
    orig_locale = I18n.locale
    I18n.locale = example.metadata[:locale]
    example.run
    I18n.locale = orig_locale
  end

  config.around :each, expect_warnings: true do |example|
    capture_warnings do
      example.run
    end
  end

  config.around :each do |example|
    Timeout.timeout(example.metadata.fetch(:timeout, 1)) do
      example.run
    end
  end
end