File: test_setup_requirements.rb

package info (click to toggle)
libi18n-ruby 0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 576 kB
  • ctags: 619
  • sloc: ruby: 4,655; makefile: 5
file content (71 lines) | stat: -rw-r--r-- 1,812 bytes parent folder | download
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 'optparse'

options = { :with => [] }
OptionParser.new do |o|
   o.on('-w', '--with DEPENDENCIES', 'Define dependencies') do |dep|
     options[:with] = dep.split(',').map { |group| group.to_sym }
   end
end.parse!

options[:with].each do |dep|
  case dep
  when :ar23, :'activerecord-2.3'
    gem 'activerecord', '~> 2.3'
  when :ar3, :'activerecord-3'
    gem 'activerecord', '~> 3'
  end
end

# Do not load the i18n gem from libraries like active_support, we'll load it from here :)
alias :gem_for_ruby_19 :gem # for 1.9. gives a super ugly seg fault otherwise
def gem(gem_name, *version_requirements)
  if gem_name =='i18n'
    puts "skipping loading the i18n gem ..."
    return
  end
  super(gem_name, *version_requirements)
end

def setup_mocha
  begin
    require 'mocha'
  rescue LoadError
    puts "skipping tests using mocha as mocha can't be found"
  end
end

def setup_active_record
  begin
    require 'active_record'
    ActiveRecord::Base.connection
    true
  rescue LoadError => e
    puts "can't use ActiveRecord backend because: #{e.message}"
  rescue ActiveRecord::ConnectionNotEstablished
    require 'i18n/backend/active_record'
    require 'i18n/backend/active_record/store_procs'
    connect_active_record
    true
  end
end

def connect_active_record
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
  ActiveRecord::Migration.verbose = false
  ActiveRecord::Schema.define(:version => 1) do
    create_table :translations do |t|
      t.string :locale
      t.string :key
      t.string :value
      t.string :interpolations
      t.boolean :is_proc, :default => false
    end
  end
end

def setup_rufus_tokyo
  require 'rubygems'
  require 'rufus/tokyo'
rescue LoadError => e
  puts "can't use KeyValue backend because: #{e.message}"
end