twitter_cldr 4.3.1 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -7
  3. data/README.md +5 -5
  4. data/lib/twitter_cldr/collation/sort_key_builder.rb +5 -5
  5. data/lib/twitter_cldr/core_ext.rb +2 -8
  6. data/lib/twitter_cldr/parsers/parser.rb +4 -4
  7. data/lib/twitter_cldr/utils/range_set.rb +3 -1
  8. data/lib/twitter_cldr/utils/yaml.rb +17 -17
  9. data/lib/twitter_cldr/version.rb +1 -1
  10. data/spec/collation/collator_spec.rb +55 -34
  11. data/spec/collation/sort_key_builder_spec.rb +3 -3
  12. data/spec/collation/trie_builder_spec.rb +7 -5
  13. data/spec/collation/trie_loader_spec.rb +5 -1
  14. data/spec/collation/trie_with_fallback_spec.rb +4 -4
  15. data/spec/core_ext_spec.rb +1 -7
  16. data/spec/data_readers/date_time_data_reader_spec.rb +1 -1
  17. data/spec/data_readers/number_data_reader_spec.rb +1 -1
  18. data/spec/formatters/calendars/datetime_formatter_spec.rb +5 -5
  19. data/spec/formatters/plurals/plural_formatter_spec.rb +3 -3
  20. data/spec/formatters/plurals/rules_spec.rb +2 -2
  21. data/spec/localized/localized_array_spec.rb +6 -2
  22. data/spec/localized/localized_date_spec.rb +1 -1
  23. data/spec/localized/localized_datetime_spec.rb +2 -4
  24. data/spec/localized/localized_object_spec.rb +3 -3
  25. data/spec/localized/localized_string_spec.rb +6 -4
  26. data/spec/localized/localized_symbol_spec.rb +2 -2
  27. data/spec/normalization_spec.rb +5 -5
  28. data/spec/parsers/number_parser_spec.rb +12 -12
  29. data/spec/parsers/parser_spec.rb +1 -1
  30. data/spec/resources/loader_spec.rb +31 -31
  31. data/spec/shared/calendar_spec.rb +5 -5
  32. data/spec/shared/code_point_spec.rb +5 -5
  33. data/spec/shared/hyphenator_spec.rb +2 -2
  34. data/spec/shared/language_codes_spec.rb +7 -7
  35. data/spec/shared/languages_spec.rb +2 -2
  36. data/spec/shared/locale_spec.rb +10 -10
  37. data/spec/shared/numbers_spec.rb +5 -5
  38. data/spec/shared/phone_codes_spec.rb +4 -2
  39. data/spec/shared/postal_code_generator_spec.rb +1 -1
  40. data/spec/shared/properties_database_spec.rb +6 -6
  41. data/spec/shared/territories_containment_spec.rb +8 -8
  42. data/spec/shared/territories_spec.rb +10 -6
  43. data/spec/shared/territory_spec.rb +4 -5
  44. data/spec/spec_helper.rb +1 -2
  45. data/spec/twitter_cldr_spec.rb +20 -20
  46. data/spec/utils/range_set_spec.rb +7 -7
  47. data/spec/utils/regexp_ast_spec.rb +4 -4
  48. data/spec/utils/regexp_sampler_spec.rb +23 -23
  49. metadata +2 -2
@@ -66,7 +66,11 @@ describe TrieLoader do
66
66
  end
67
67
 
68
68
  def mock_trie_dump
69
- mock(File).open(TrieLoader.dump_path(locale), 'r') { |*args| args.last.call(trie_dump) }
69
+ expect(File).to(
70
+ receive(:open)
71
+ .with(TrieLoader.dump_path(locale), 'r')
72
+ .and_yield(trie_dump)
73
+ )
70
74
  end
71
75
 
72
76
  end
@@ -16,24 +16,24 @@ describe TrieWithFallback do
16
16
 
17
17
  describe '#get' do
18
18
  it 'returns result if the key is present' do
19
- dont_allow(fallback).get
19
+ expect(fallback).to_not receive(:get)
20
20
  expect(trie.get([1, 2, 3])).to eq('value')
21
21
  end
22
22
 
23
23
  it 'resorts to the fallback if the key is not present' do
24
- mock(fallback).get([3, 2, 1]) { 'fallback-value' }
24
+ expect(fallback).to receive(:get).with([3, 2, 1]).and_return('fallback-value')
25
25
  expect(trie.get([3, 2, 1])).to eq('fallback-value')
26
26
  end
27
27
  end
28
28
 
29
29
  describe '#find_prefix' do
30
30
  it 'returns result if the key is present' do
31
- dont_allow(fallback).find_prefix
31
+ expect(fallback).to_not receive(:find_prefix)
32
32
  expect(trie.find_prefix([1, 2, 3, 4]).first(2)).to eq(['value', 3])
33
33
  end
34
34
 
35
35
  it 'resorts to the fallback if the key is not present' do
36
- mock(fallback).find_prefix([3, 2, 1]) { 'fallback-result' }
36
+ expect(fallback).to receive(:find_prefix).with([3, 2, 1]).and_return('fallback-result')
37
37
  expect(trie.find_prefix([3, 2, 1])).to eq('fallback-result')
38
38
  end
39
39
  end
@@ -6,13 +6,7 @@
6
6
  require 'spec_helper'
7
7
 
8
8
  describe 'Core classes localization' do
9
- core_classes = [Array, DateTime, Float, String, Symbol, Time]
10
-
11
- if RUBY_VERSION >= '2.4.0'
12
- core_classes.push Integer
13
- else
14
- core_classes.push Bignum, Fixnum
15
- end
9
+ core_classes = [Array, DateTime, Float, String, Symbol, Time, Integer]
16
10
 
17
11
  core_classes.each do |klass|
18
12
  describe klass do
@@ -19,7 +19,7 @@ describe DateTimeDataReader do
19
19
 
20
20
  describe "#pattern" do
21
21
  it "as of CLDR 23, should choose the medium date time path if no other type is specified" do
22
- mock.proxy(data_reader).path_for(:medium, anything)
22
+ expect(data_reader).to receive(:path_for).with(:medium, anything).and_call_original
23
23
  data_reader.pattern
24
24
  end
25
25
  end
@@ -33,7 +33,7 @@ describe NumberDataReader do
33
33
  let(:symbols) { { nan: 'NaN', minus_sign: '<->' } } # unique locale-specific minus sign
34
34
 
35
35
  before(:each) do
36
- stub(TwitterCldr).get_locale_resource(:en, :numbers) {
36
+ allow(TwitterCldr).to receive(:get_locale_resource).with(:en, :numbers) {
37
37
  {
38
38
  en: {
39
39
  numbers: {
@@ -429,17 +429,17 @@ describe DateTimeFormatter do
429
429
  end
430
430
 
431
431
  it "should fall back if the calendar doesn't contain the appropriate era data" do
432
- stub(@formatter.data_reader.calendar).eras(:abbr) do
432
+ allow(@formatter.data_reader.calendar).to receive(:eras).with(:abbr) do
433
433
  { 0 => "abbr0", 1 => "abbr1" }
434
434
  end
435
435
 
436
- stub(@formatter.data_reader.calendar).eras(:name) do
436
+ allow(@formatter.data_reader.calendar).to receive(:eras).with(:name) do
437
437
  { 0 => "name0" }
438
438
  end
439
439
 
440
440
  date = Date.new(2012, 1, 1)
441
- mock.proxy(@formatter).era(date, "GGGG", 4) # first attempts to find full name era
442
- mock.proxy(@formatter).era(date, "GGG", 3) # falls back to abbreviated era
441
+ expect(@formatter).to receive(:era).with(date, "GGGG", 4).and_call_original # first attempts to find full name era
442
+ expect(@formatter).to receive(:era).with(date, "GGG", 3).and_call_original # falls back to abbreviated era
443
443
  expect(@formatter.send(:era, date, 'GGGG', 4)).to eq("abbr1")
444
444
  end
445
445
  end
@@ -470,4 +470,4 @@ describe DateTimeFormatter do
470
470
  expect(@formatter.send(:month_stand_alone, Date.new(2010, 10, 1), 'LLLLL', 5)).to eq("O")
471
471
  end
472
472
  end
473
- end
473
+ end
@@ -23,7 +23,7 @@ describe PluralFormatter do
23
23
  subject { PluralFormatter.new }
24
24
 
25
25
  before(:each) do
26
- stub(subject).pluralization_rule { |n| n == 1 ? :one : :other }
26
+ allow(subject).to receive(:pluralization_rule) { |n| n == 1 ? :one : :other }
27
27
  end
28
28
 
29
29
  let(:horses) { { one: 'is 1 horse', other: 'are %{horses_count} horses' } }
@@ -197,9 +197,9 @@ describe PluralFormatter do
197
197
 
198
198
  describe '#pluralization_rule' do
199
199
  it 'delegates pluralization rule fetching to Rules.rule_for method' do
200
- mock(Plurals::Rules).rule_for(42, :jp) { 'result' }
200
+ expect(Plurals::Rules).to receive(:rule_for).with(42, :jp).and_return('result')
201
201
  expect(PluralFormatter.new(:jp).send(:pluralization_rule, 42)).to eq('result')
202
202
  end
203
203
  end
204
204
 
205
- end
205
+ end
@@ -45,7 +45,7 @@ describe Rules do
45
45
  end
46
46
 
47
47
  it "returns :other if there's an error" do
48
- stub(Rules).get_resource { lambda { raise "Jelly beans" } }
48
+ allow(Rules).to receive(:get_resource).and_return(lambda { raise "Jelly beans" })
49
49
  expect(Rules.rule_for(1, :en)).to eq(:other)
50
50
  expect(Rules.rule_for(1, :ru)).to eq(:other)
51
51
  end
@@ -88,7 +88,7 @@ describe Rules do
88
88
 
89
89
  describe "#all" do
90
90
  before(:each) do
91
- mock(TwitterCldr).locale { :ru }
91
+ expect(TwitterCldr).to receive(:locale).and_return(:ru)
92
92
  end
93
93
 
94
94
  it "gets rules for the default locale (usually supplied by FastGettext)" do
@@ -20,7 +20,11 @@ describe LocalizedArray do
20
20
  let(:sorted) { %w[aaa abc bca] }
21
21
  let(:localized) { array.localize(locale) }
22
22
 
23
- before(:each) { mock(TwitterCldr::Collation::Collator).new(locale) { FakeCollator.new } }
23
+ before(:each) do
24
+ expect(TwitterCldr::Collation::Collator).to(
25
+ receive(:new).with(locale).and_return(FakeCollator.new)
26
+ )
27
+ end
24
28
 
25
29
  describe '#sort' do
26
30
  it 'returns a new LocalizedArray' do
@@ -84,4 +88,4 @@ class FakeCollator
84
88
  def sort!(array)
85
89
  array.sort!
86
90
  end
87
- end
91
+ end
@@ -16,7 +16,7 @@ describe LocalizedDate do
16
16
  let(:base_time) { Time.gm(2010, 8, 6, 12, 12, 30) }
17
17
 
18
18
  it "should ago-ify from now when no base_time given" do
19
- stub(Time).now { Time.gm(2010, 8, 6, 12, 12, 30) }
19
+ allow(Time).to receive(:now).and_return(Time.gm(2010, 8, 6, 12, 12, 30))
20
20
  loc_date = date_time.localize(:ko).to_date
21
21
  expect(loc_date.ago.to_s(unit: :hour)).to match_normalized("744시간 전")
22
22
  end
@@ -90,9 +90,7 @@ describe LocalizedDateTime do
90
90
  TwitterCldr.supported_locales.each do |locale|
91
91
  data_reader = TwitterCldr::DataReaders::CalendarDataReader.new(locale)
92
92
  data_reader.additional_format_selector.patterns.each do |pattern|
93
- # puts "#{locale}: #{pattern}"
94
- # lambda { date_time.localize(locale).to_additional_s(pattern.to_s) }.should_not raise_error
95
- date_time.localize(locale).to_additional_s(pattern.to_s)
93
+ expect { date_time.localize(locale).to_additional_s(pattern.to_s) }.to_not raise_error
96
94
  end
97
95
  end
98
96
  end
@@ -115,7 +113,7 @@ describe LocalizedDateTime do
115
113
  describe "#to_s" do
116
114
  it "uses the default format if no :format is given" do
117
115
  loc_date = date_time.localize
118
- mock.proxy(loc_date).to_default_s
116
+ expect(loc_date).to receive(:to_default_s).and_call_original
119
117
  expect(loc_date.to_s).to eq("Sep 20, 1987, 10:05:00 PM")
120
118
  end
121
119
  end
@@ -71,14 +71,14 @@ describe LocalizedObject do
71
71
  end
72
72
 
73
73
  it 'accepts locale and options and pass them to the localized class constructor' do
74
- mock(LocalizedClass).new(localizable_object, locale, options)
74
+ expect(LocalizedClass).to receive(:new).with(localizable_object, locale, options)
75
75
  localizable_object.localize(locale, options)
76
76
  end
77
77
 
78
78
  it 'uses default locale and empty options hash by default' do
79
- mock(LocalizedClass).new(localizable_object, TwitterCldr.locale, {})
79
+ expect(LocalizedClass).to receive(:new).with(localizable_object, TwitterCldr.locale, {})
80
80
  localizable_object.localize
81
81
  end
82
82
  end
83
83
 
84
- end
84
+ end
@@ -32,7 +32,9 @@ describe LocalizedString do
32
32
  let(:horses) { { one: '1 horse', other: '%{horses_count} horses' } }
33
33
 
34
34
  before(:each) do
35
- stub(TwitterCldr::Formatters::Plurals::Rules).rule_for { |n, _| n == 1 ? :one : :other }
35
+ allow(TwitterCldr::Formatters::Plurals::Rules).to receive(:rule_for) do |n, _|
36
+ n == 1 ? :one : :other
37
+ end
36
38
  end
37
39
 
38
40
  it 'interpolates named placeholders' do
@@ -87,7 +89,7 @@ describe LocalizedString do
87
89
  result = string.localize.to_s
88
90
 
89
91
  expect(result).to eq(string)
90
- expect(result.equal?(string)).not_to be_true
92
+ expect(result.equal?(string)).not_to eq(true)
91
93
  end
92
94
  end
93
95
 
@@ -134,12 +136,12 @@ describe LocalizedString do
134
136
  end
135
137
 
136
138
  it 'it uses NFD by default' do
137
- mock(Eprun).normalize(string, :nfd) { normalized_string }
139
+ expect(Eprun).to receive(:normalize).with(string, :nfd).and_return(normalized_string)
138
140
  expect(localized_string.normalize.base_obj).to eq(normalized_string)
139
141
  end
140
142
 
141
143
  it "uses specified algorithm if there is any" do
142
- mock(Eprun).normalize(string, :nfkd) { normalized_string }
144
+ expect(Eprun).to receive(:normalize).with(string, :nfkd).and_return(normalized_string)
143
145
  expect(localized_string.normalize(using: :NFKD).base_obj).to eq(normalized_string)
144
146
  end
145
147
 
@@ -49,8 +49,8 @@ describe LocalizedSymbol do
49
49
 
50
50
  describe "#is_rtl?" do
51
51
  it "returns true or false depending on the locale" do
52
- expect(:es.localize.is_rtl?).to be_false
53
- expect(:ar.localize.is_rtl?).to be_true
52
+ expect(:es.localize.is_rtl?).to eq(false)
53
+ expect(:ar.localize.is_rtl?).to eq(true)
54
54
  end
55
55
  end
56
56
 
@@ -12,12 +12,12 @@ describe TwitterCldr::Normalization do
12
12
  let(:normalized_string) { 'normalized' }
13
13
 
14
14
  it 'it uses NFD by default' do
15
- mock(Eprun).normalize(string, :nfd) { normalized_string }
15
+ expect(Eprun).to receive(:normalize).with(string, :nfd).and_return(normalized_string)
16
16
  expect(TwitterCldr::Normalization.normalize(string)).to eq(normalized_string)
17
17
  end
18
18
 
19
19
  it "uses specified algorithm if there is any" do
20
- mock(Eprun).normalize(string, :nfkd) { normalized_string }
20
+ expect(Eprun).to receive(:normalize).with(string, :nfkd).and_return(normalized_string)
21
21
  expect(TwitterCldr::Normalization.normalize(string, using: :nfkd)).to eq(normalized_string)
22
22
  end
23
23
 
@@ -28,15 +28,15 @@ describe TwitterCldr::Normalization do
28
28
  end
29
29
 
30
30
  it 'accepts normalizer name in upper case' do
31
- mock(Eprun).normalize(string, :nfkd) { normalized_string }
31
+ expect(Eprun).to receive(:normalize).with(string, :nfkd).and_return(normalized_string)
32
32
  expect(TwitterCldr::Normalization.normalize(string, using: :NFKD)).to eq(normalized_string)
33
33
  end
34
34
 
35
35
  it 'accepts a string' do
36
- mock(Eprun).normalize(string, :nfkd) { normalized_string }
36
+ expect(Eprun).to receive(:normalize).with(string, :nfkd).and_return(normalized_string)
37
37
  expect(TwitterCldr::Normalization.normalize(string, using: 'nfkd')).to eq(normalized_string)
38
38
  end
39
39
 
40
40
  end
41
41
 
42
- end
42
+ end
@@ -77,51 +77,51 @@ describe NumberParser do
77
77
  describe "#punct_valid" do
78
78
  it "correctly validates a number with no decimal" do
79
79
  tokens = @parser.send(:tokenize, "1.337", *separators).reject { |t| t[:type] == :numeric }
80
- expect(@parser.send(:punct_valid?, tokens)).to be_true
80
+ expect(@parser.send(:punct_valid?, tokens)).to eq(true)
81
81
  end
82
82
 
83
83
  it "correctly validates a number with a decimal" do
84
84
  tokens = @parser.send(:tokenize, "1.337,00", *separators).reject { |t| t[:type] == :numeric }
85
- expect(@parser.send(:punct_valid?, tokens)).to be_true
85
+ expect(@parser.send(:punct_valid?, tokens)).to eq(true)
86
86
  end
87
87
 
88
88
  it "reports on an invalid number when it has more than one decimal" do
89
89
  tokens = @parser.send(:tokenize, "1,337,00", *separators).reject { |t| t[:type] == :numeric }
90
- expect(@parser.send(:punct_valid?, tokens)).to be_false
90
+ expect(@parser.send(:punct_valid?, tokens)).to eq(false)
91
91
  end
92
92
  end
93
93
 
94
94
  describe "#is_numeric?" do
95
95
  it "returns true if the text is numeric" do
96
- expect(NumberParser.is_numeric?("4839", "")).to be_true
97
- expect(NumberParser.is_numeric?("1", "")).to be_true
96
+ expect(NumberParser.is_numeric?("4839", "")).to eq(true)
97
+ expect(NumberParser.is_numeric?("1", "")).to eq(true)
98
98
  end
99
99
 
100
100
  it "returns false if the text is not purely numeric" do
101
- expect(NumberParser.is_numeric?("abc", "")).to be_false
102
- expect(NumberParser.is_numeric?("123abc", "")).to be_false
101
+ expect(NumberParser.is_numeric?("abc", "")).to eq(false)
102
+ expect(NumberParser.is_numeric?("123abc", "")).to eq(false)
103
103
  end
104
104
 
105
105
  it "returns false if the text is blank" do
106
- expect(NumberParser.is_numeric?("", "")).to be_false
106
+ expect(NumberParser.is_numeric?("", "")).to eq(false)
107
107
  end
108
108
 
109
109
  it "accepts the given characters as valid numerics" do
110
- expect(NumberParser.is_numeric?("a123a", "a")).to be_true
111
- expect(NumberParser.is_numeric?("1.234,56")).to be_true # default separator chars used here
110
+ expect(NumberParser.is_numeric?("a123a", "a")).to eq(true)
111
+ expect(NumberParser.is_numeric?("1.234,56")).to eq(true) # default separator chars used here
112
112
  end
113
113
  end
114
114
 
115
115
  describe "#valid?" do
116
116
  it "correctly identifies a series of valid cases" do
117
117
  ["5", "5,0", "1.337", "1.337,0", "0,05", ",5", "1.337.000,00"].each do |num|
118
- expect(@parser.valid?(num)).to be_true
118
+ expect(@parser.valid?(num)).to eq(true)
119
119
  end
120
120
  end
121
121
 
122
122
  it "correctly identifies a series of invalid cases" do
123
123
  ["12,0,0", "5,", "5."].each do |num|
124
- expect(@parser.valid?(num)).to be_false
124
+ expect(@parser.valid?(num)).to eq(false)
125
125
  end
126
126
  end
127
127
  end
@@ -24,7 +24,7 @@ describe Parser do
24
24
 
25
25
  describe "#parse" do
26
26
  it "should call do_parse" do
27
- mock(parser).do_parse({})
27
+ expect(parser).to receive(:do_parse).and_return({})
28
28
  parser.parse(tokens)
29
29
  end
30
30
  end
@@ -25,7 +25,7 @@ describe Loader do
25
25
  end
26
26
 
27
27
  it 'loads the resource only once' do
28
- mock(loader).load_resource(resource_path).once { resource_content }
28
+ expect(loader).to receive(:load_resource).with(resource_path).and_return(resource_content)
29
29
 
30
30
  result = loader.get_resource(:random, :resource)
31
31
  expect(result).to eq(resource_content)
@@ -34,32 +34,32 @@ describe Loader do
34
34
  end
35
35
 
36
36
  it 'accepts a variable length resource path both in symbols and strings' do
37
- stub(loader).load_resource('foo/bar/baz.yml') { 'foo-bar-baz' }
37
+ allow(loader).to receive(:load_resource).with('foo/bar/baz.yml').and_return('foo-bar-baz')
38
38
  expect(loader.get_resource('foo', :bar, 'baz')).to eq('foo-bar-baz')
39
39
  end
40
40
 
41
41
  it 'raises an exception if resource file is missing' do
42
- mock(File).file?(File.join(TwitterCldr::RESOURCES_DIR, 'foo/bar.yml')) { false }
42
+ expect(File).to receive(:file?).with(File.join(TwitterCldr::RESOURCES_DIR, 'foo/bar.yml')).and_return(false)
43
43
  expect { loader.get_resource(:foo, :bar) }.to raise_error(ResourceLoadError, "Resource 'foo/bar.yml' not found.")
44
44
  end
45
45
 
46
46
  context 'custom resources' do
47
47
  it "doesn't merge the custom resource if it doesn't exist" do
48
- mock(loader).read_resource_file('foo/bar.yml') { ":foo: bar" }
48
+ expect(loader).to receive(:read_resource_file).with('foo/bar.yml').and_return(":foo: bar")
49
49
  expect(loader.get_resource(:foo, :bar)).to eq({ foo: "bar" })
50
50
  end
51
51
 
52
52
  context 'with a custom resource' do
53
53
  before(:each) do
54
- stub(loader).read_resource_file('foo/bar.yml') { ":foo: bar" }
55
- stub(loader).custom_resource_exists?('custom/foo/bar.yml') { true }
56
- stub(loader).read_resource_file('custom/foo/bar.yml') { ":bar: baz" }
54
+ allow(loader).to receive(:read_resource_file).with('foo/bar.yml').and_return(":foo: bar")
55
+ allow(loader).to receive(:custom_resource_exists?).with('custom/foo/bar.yml').and_return(true)
56
+ allow(loader).to receive(:read_resource_file).with('custom/foo/bar.yml').and_return(":bar: baz")
57
57
  end
58
58
 
59
59
  it 'merges the given file with its corresponding custom resource if it exists' do
60
60
  # make sure load_resource is called with custom = false the second time
61
- mock.proxy(loader).load_resource("foo/bar.yml")
62
- mock.proxy(loader).load_resource("custom/foo/bar.yml", false)
61
+ expect(loader).to receive(:load_resource).with("foo/bar.yml").and_call_original
62
+ expect(loader).to receive(:load_resource).with("custom/foo/bar.yml", false).and_call_original
63
63
 
64
64
  expect(loader.get_resource(:foo, :bar)).to eq({ foo: "bar", bar: "baz" })
65
65
  end
@@ -75,12 +75,12 @@ describe Loader do
75
75
 
76
76
  describe '#get_locale_resource' do
77
77
  it 'loads the correct locale resource file' do
78
- stub(loader).get_resource(:locales, :de, :numbers) { 'foo' }
78
+ allow(loader).to receive(:get_resource).with(:locales, :de, :numbers).and_return('foo')
79
79
  expect(loader.get_locale_resource(:de, :numbers)).to eq('foo')
80
80
  end
81
81
 
82
82
  it 'loads the resource only once' do
83
- mock(loader).load_resource('locales/de/numbers.yml').once { 'foo' }
83
+ expect(loader).to receive(:load_resource).with('locales/de/numbers.yml').and_return('foo')
84
84
 
85
85
  result = loader.get_locale_resource(:de, :numbers)
86
86
  # second time get_resource is not called but we get the same object as before
@@ -88,8 +88,8 @@ describe Loader do
88
88
  end
89
89
 
90
90
  it 'converts locales' do
91
- mock(TwitterCldr).convert_locale('zh-tw') { :'zh-Hant' }
92
- mock(loader).get_resource(:locales, :'zh-Hant', :numbers) { 'foo' }
91
+ expect(TwitterCldr).to receive(:convert_locale).with('zh-tw').and_return(:'zh-Hant')
92
+ expect(loader).to receive(:get_resource).with(:locales, :'zh-Hant', :numbers).and_return('foo')
93
93
 
94
94
  expect(loader.get_locale_resource('zh-tw', :numbers)).to eq('foo')
95
95
  end
@@ -98,16 +98,16 @@ describe Loader do
98
98
  describe '#resource_loaded' do
99
99
  it 'should return true if the resource is cached, false otherwise' do
100
100
  loader.preload_resources_for_locale(:de, :numbers)
101
- expect(loader.resource_loaded?(:locales, :de, :numbers)).to be_true
102
- expect(loader.resource_loaded?(:locales, :de, :calendars)).to be_false
101
+ expect(loader.resource_loaded?(:locales, :de, :numbers)).to eq(true)
102
+ expect(loader.resource_loaded?(:locales, :de, :calendars)).to eq(false)
103
103
  end
104
104
  end
105
105
 
106
106
  describe '#locale_resource_loaded' do
107
107
  it 'should return true if the locale resource is cached, false otherwise' do
108
108
  loader.preload_resources_for_locale(:de, :numbers)
109
- expect(loader.locale_resource_loaded?(:de, :numbers)).to be_true
110
- expect(loader.locale_resource_loaded?(:de, :calendars)).to be_false
109
+ expect(loader.locale_resource_loaded?(:de, :numbers)).to eq(true)
110
+ expect(loader.locale_resource_loaded?(:de, :calendars)).to eq(false)
111
111
  end
112
112
  end
113
113
 
@@ -131,16 +131,16 @@ describe Loader do
131
131
  describe '#preload_resources_for_locale' do
132
132
  it 'loads potentially multiple resources into the cache' do
133
133
  loader.preload_resources_for_locale(:ar, :calendars, :fields)
134
- expect(loader.locale_resource_loaded?(:ar, :calendars)).to be_true
135
- expect(loader.locale_resource_loaded?(:ar, :fields)).to be_true
136
- expect(loader.locale_resource_loaded?(:en, :fields)).to be_false
134
+ expect(loader.locale_resource_loaded?(:ar, :calendars)).to eq(true)
135
+ expect(loader.locale_resource_loaded?(:ar, :fields)).to eq(true)
136
+ expect(loader.locale_resource_loaded?(:en, :fields)).to eq(false)
137
137
  end
138
138
 
139
139
  it 'loads all resources for the locale if the :all resource type is specified' do
140
140
  loader.preload_resources_for_locale(:ar, :all)
141
141
  loader.resource_types_for(:ar).each do |resource_type|
142
- expect(loader.locale_resource_loaded?(:ar, resource_type)).to be_true
143
- expect(loader.locale_resource_loaded?(:en, resource_type)).to be_false
142
+ expect(loader.locale_resource_loaded?(:ar, resource_type)).to eq(true)
143
+ expect(loader.locale_resource_loaded?(:en, resource_type)).to eq(false)
144
144
  end
145
145
  end
146
146
  end
@@ -148,9 +148,9 @@ describe Loader do
148
148
  describe '#preload_resource_for_locales' do
149
149
  it 'loads a single resource for potentially multiple locales into the cache' do
150
150
  loader.preload_resource_for_locales(:calendars, :sv, :bn)
151
- expect(loader.locale_resource_loaded?(:sv, :calendars)).to be_true
152
- expect(loader.locale_resource_loaded?(:bn, :calendars)).to be_true
153
- expect(loader.locale_resource_loaded?(:sv, :units)).to be_false
151
+ expect(loader.locale_resource_loaded?(:sv, :calendars)).to eq(true)
152
+ expect(loader.locale_resource_loaded?(:bn, :calendars)).to eq(true)
153
+ expect(loader.locale_resource_loaded?(:sv, :units)).to eq(false)
154
154
  end
155
155
  end
156
156
 
@@ -158,9 +158,9 @@ describe Loader do
158
158
  it 'loads potentially multiple resources for all locales' do
159
159
  loader.preload_resources_for_all_locales(:plurals, :lists)
160
160
  TwitterCldr.supported_locales.each do |locale|
161
- expect(loader.locale_resource_loaded?(locale, :plurals)).to be_true
162
- expect(loader.locale_resource_loaded?(locale, :lists)).to be_true
163
- expect(loader.locale_resource_loaded?(locale, :calendars)).to be_false
161
+ expect(loader.locale_resource_loaded?(locale, :plurals)).to eq(true)
162
+ expect(loader.locale_resource_loaded?(locale, :lists)).to eq(true)
163
+ expect(loader.locale_resource_loaded?(locale, :calendars)).to eq(false)
164
164
  end
165
165
  end
166
166
  end
@@ -170,7 +170,7 @@ describe Loader do
170
170
  loader.preload_all_resources
171
171
  TwitterCldr.supported_locales.each do |locale|
172
172
  loader.resource_types_for(locale).each do |resource_type|
173
- expect(loader.locale_resource_loaded?(locale, resource_type)).to be_true
173
+ expect(loader.locale_resource_loaded?(locale, resource_type)).to eq(true)
174
174
  end
175
175
  end
176
176
  end
@@ -178,8 +178,8 @@ describe Loader do
178
178
 
179
179
  def stub_resource_file(resource_path, content)
180
180
  file_path = File.join(TwitterCldr::RESOURCES_DIR, resource_path)
181
- stub(File).read(file_path) { content }
182
- stub(File).file?(file_path) { true }
181
+ allow(File).to receive(:read).with(file_path).and_return(content)
182
+ allow(File).to receive(:file?).with(file_path).and_return(true)
183
183
  end
184
184
 
185
185
  end