-
Notifications
You must be signed in to change notification settings - Fork 57
/
load_path_spec.rb
75 lines (63 loc) · 2.8 KB
/
load_path_spec.rb
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
72
73
74
75
require File.dirname(__FILE__) + '/spec/helper.rb'
require 'globalize/load_path'
I18n.send :include, Globalize::LoadPath::I18n
describe Globalize::LoadPath do
before :each do
@locale_dir = "#{File.dirname(__FILE__)}/spec/fixtures/locale"
@load_path = I18n.load_path
@load_path << @locale_dir if @load_path.empty?
end
it "returns an instance of Globalize::LoadPath from I18n.load_path" do
@load_path.should be_instance_of(Globalize::LoadPath)
end
it "allows to add paths (using yml as a default file extension)" do
@load_path.should == [[@locale_dir, ['yml']]]
end
it "allows to specify a single file extension while adding a path" do
load_path = Globalize::LoadPath.new
load_path.add(@locale_dir, 'rb')
load_path.should == [[@locale_dir, ['rb']]]
end
it "allows to specify an array of file extensions while adding a path" do
load_path = Globalize::LoadPath.new
load_path.add(@locale_dir, 'rb', 'yml')
load_path.should == [[@locale_dir, ['rb', 'yml']]]
end
it "creates glob patterns which enforce the default directory structure" do
load_path = Globalize::LoadPath.new
load_path.add(@locale_dir, 'rb', 'yml')
locale = 'en-US'
patterns = %W( #{@locale_dir}/#{locale}/**/*.rb
#{@locale_dir}/#{locale}.rb
#{@locale_dir}/all.rb
#{@locale_dir}/#{locale}/**/*.yml
#{@locale_dir}/#{locale}.yml
#{@locale_dir}/all.yml )
load_path.send(:patterns, locale).should == patterns
end
it "finds all locale files for a given locale including the all file and files in the locale-specific subdirectory" do
@load_path.filenames('fi-FI').should == ["#{@locale_dir}/all.yml", "#{@locale_dir}/fi-FI/module.yml"]
end
it "finds all locale files for a given locale including the all file and locale-specific files" do
@load_path.filenames('de-DE').should == ["#{@locale_dir}/all.yml", "#{@locale_dir}/de-DE.yml"]
end
end
describe I18n, "#load_locales" do
before :each do
@locale_dir = "#{File.dirname(__FILE__)}/spec/fixtures/locale"
@load_path = I18n.load_path
@load_path << @locale_dir if @load_path.empty?
end
it "loading locale data for the given locales from all files in the current load_path" do
I18n.should_receive(:load_locale).with('en-US').once.ordered
I18n.should_receive(:load_locale).with('de-DE').once.ordered
I18n.load_locales('en-US', 'de-DE')
end
it "loading locale data for the given locale from all files in the current load_path" do
I18n.load_locale('en-US')
I18n.locale = 'en-US'
keys = [:"from-all-file", :"from-locale-file", :"from-locale-dir"]
translations = ['From the "all" file.', 'From the locale file.', 'From the locale directory.']
I18n.t(keys).should == translations
end
end