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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 524211c9e2e79788806d06b9870faa9e58d58684
4
- data.tar.gz: a9f37c86fe27129ccd15a24b5eed9f80e105d5af
3
+ metadata.gz: 674bc5569896b716d19543ec3a2c058f88faedcc
4
+ data.tar.gz: daf46a0df8f0ec0fd81e76ab9df42b2fed7c7052
5
5
  SHA512:
6
- metadata.gz: 92754882211fd1b7067ea2e9936fb6a8a77c77fd2009ec1d8544cf8576e6908c0767297f2a5643238de6649d70c193b9e785e0a21c1d00e9cbc2263bae73501f
7
- data.tar.gz: 3bf352dc1a9163b2d39a92498b5732448b4ed57817ae6a50eebeac7d18dba25fd78b1031630c7300251df4557abae43bf322a4603c44bcc9b084b6d552b8a7b8
6
+ metadata.gz: 2d41beee2102492e1a31260584c407391a4559d52b2b6e92807753681cce4d83ecdae4c52c431f1e29cc5b12d2d5bb61ca35577a76d47dd20d4b22f553888b41
7
+ data.tar.gz: c6eb67cc82b5f9a38d914e8459a0c366b6eb7f3ea3cc35508e1df0b4f9623aacc0d0a48cc76cbca7e160d9503af149c20aeddc8471c54243c5c0de85a66336b6
data/Gemfile CHANGED
@@ -7,6 +7,8 @@ group :development, :test do
7
7
  gem 'pry-nav'
8
8
  gem 'ruby-prof' unless RUBY_PLATFORM == 'java'
9
9
  gem 'regexp_parser', '~> 0.1'
10
+ gem 'benchmark-ips'
11
+ gem 'rubyzip', '~> 1.0'
10
12
  end
11
13
 
12
14
  group :development do
@@ -20,8 +22,7 @@ group :development do
20
22
  end
21
23
 
22
24
  group :test do
23
- gem 'rspec', '~> 2.14.0'
24
- gem 'rr', '~> 1.1.2'
25
+ gem 'rspec', '~> 3.0'
25
26
 
26
27
  gem 'term-ansicolor', '~> 1.3.0' # 1.4 breaks ruby 1.9 support
27
28
  gem 'coveralls', require: false
@@ -31,8 +32,3 @@ group :test do
31
32
  gem 'launchy'
32
33
  gem 'addressable', '~> 2.4.0' # 2.5 breaks ruby 1.9 support
33
34
  end
34
-
35
- group :development, :test do
36
- gem 'rubyzip', '~> 1.0'
37
- gem 'benchmark-ips'
38
- end
data/README.md CHANGED
@@ -29,11 +29,11 @@ TwitterCldr.supported_locale?(:xx) # false
29
29
  ```
30
30
 
31
31
 
32
- TwitterCldr patches core Ruby objects like `Fixnum` and `Date` to make localization as straightforward as possible.
32
+ TwitterCldr patches core Ruby objects like `Integer` and `Date` to make localization as straightforward as possible.
33
33
 
34
34
  ### Numbers
35
35
 
36
- `Fixnum`, `Bignum`, and `Float` objects are supported. Here are some examples:
36
+ `Integer` and `Float` objects are supported (as well as `Fixnum` and `Bignum` for Ruby versions < 2.4). Here are some examples:
37
37
 
38
38
  ```ruby
39
39
  # default formatting with to_s
@@ -554,7 +554,7 @@ postal_code.regexp # /(\d{5})(?:[ \-](\d{4}))?/
554
554
  Get a sample of valid postal codes with the `#sample` method:
555
555
 
556
556
  ```ruby
557
- postal_code.sample(5) # ["88435-2482", "19400", "34845-8011", "73815-5785", "43520-3829"]
557
+ postal_code.sample(5) # ["10781", "69079-7159", "79836-3996", "79771", "61093"]
558
558
  ```
559
559
 
560
560
  ### Phone Codes
@@ -984,7 +984,7 @@ bidi.to_s
984
984
 
985
985
  ### Unicode YAML Support
986
986
 
987
- The Psych gem that is the default YAML engine inRuby 1.9 doesn't handle Unicode characters perfectly. To mitigate this problem, TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`.
987
+ The Psych gem that is the default YAML engine in Ruby 1.9 doesn't handle Unicode characters perfectly. To mitigate this problem, TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`.
988
988
 
989
989
  You can make use of TwitterCLDR's YAML dumper by calling `localize` and then `to_yaml` on an `Array`, `Hash`, or `String`:
990
990
 
@@ -1078,6 +1078,6 @@ TwitterCLDR currently supports localization of certain textual objects in JavaSc
1078
1078
 
1079
1079
  ## License
1080
1080
 
1081
- Copyright 2016 Twitter, Inc.
1081
+ Copyright 2017 Twitter, Inc.
1082
1082
 
1083
1083
  Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
@@ -81,7 +81,7 @@ module TwitterCldr
81
81
  @last_leading_byte = nil
82
82
 
83
83
  @collation_elements.each do |collation_element|
84
- bytes = fixnum_to_bytes_array(level_weight(collation_element, PRIMARY_LEVEL))
84
+ bytes = integer_to_bytes_array(level_weight(collation_element, PRIMARY_LEVEL))
85
85
 
86
86
  unless bytes.empty?
87
87
  leading_byte = bytes.shift
@@ -108,7 +108,7 @@ module TwitterCldr
108
108
  @common_count = 0
109
109
 
110
110
  @collation_elements.each do |collation_element|
111
- fixnum_to_bytes_array(level_weight(collation_element, SECONDARY_LEVEL)).each do |byte|
111
+ integer_to_bytes_array(level_weight(collation_element, SECONDARY_LEVEL)).each do |byte|
112
112
  append_secondary_byte(byte)
113
113
  end
114
114
  end
@@ -123,7 +123,7 @@ module TwitterCldr
123
123
  @common_count = 0
124
124
 
125
125
  @collation_elements.each do |collation_element|
126
- fixnum_to_bytes_array(tertiary_weight(collation_element)).each do |byte|
126
+ integer_to_bytes_array(tertiary_weight(collation_element)).each do |byte|
127
127
  append_tertiary_byte(byte)
128
128
  end
129
129
  end
@@ -199,7 +199,7 @@ module TwitterCldr
199
199
  collation_element[level] || 0
200
200
  end
201
201
 
202
- def fixnum_to_bytes_array(number)
202
+ def integer_to_bytes_array(number)
203
203
  bytes = []
204
204
 
205
205
  while number > 0
@@ -315,4 +315,4 @@ module TwitterCldr
315
315
  end
316
316
 
317
317
  end
318
- end
318
+ end
@@ -3,14 +3,8 @@
3
3
  # Copyright 2012 Twitter, Inc
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
- if RUBY_VERSION >= '2.4.0'
7
- [Integer, Float].each do |klass|
8
- TwitterCldr::Localized::LocalizedNumber.localize(klass)
9
- end
10
- else
11
- [Bignum, Fixnum, Float].each do |klass|
12
- TwitterCldr::Localized::LocalizedNumber.localize(klass)
13
- end
6
+ [Integer, Float].each do |klass|
7
+ TwitterCldr::Localized::LocalizedNumber.localize(klass)
14
8
  end
15
9
 
16
10
  [Array, Date, DateTime, String, Symbol, Time, Hash].each do |klass|
@@ -21,6 +21,10 @@ module TwitterCldr
21
21
  @token_index = 0
22
22
  end
23
23
 
24
+ def eof?
25
+ @token_index >= @tokens.size
26
+ end
27
+
24
28
  private
25
29
 
26
30
  def next_token(type)
@@ -44,10 +48,6 @@ module TwitterCldr
44
48
  def current_token
45
49
  @tokens[@token_index]
46
50
  end
47
-
48
- def eof?
49
- @token_index >= @tokens.size
50
- end
51
51
  end
52
52
 
53
53
  end
@@ -203,7 +203,7 @@ module TwitterCldr
203
203
  end
204
204
 
205
205
  def includes_range?(range)
206
- bsearch do |cur_range|
206
+ result = bsearch do |cur_range|
207
207
  fo = front_overlap?(cur_range, range)
208
208
  ro = rear_overlap?(cur_range, range)
209
209
 
@@ -217,6 +217,8 @@ module TwitterCldr
217
217
  1
218
218
  end
219
219
  end
220
+
221
+ !!result
220
222
  end
221
223
 
222
224
  def bsearch
@@ -7,23 +7,23 @@
7
7
  # https://github.com/afunai/ya2yaml
8
8
 
9
9
  # Copyright (c) 2006 Akira FUNAI <funai.akira@gmail.com>
10
- #
11
- # Permission is hereby granted, free of charge, to any person obtaining a
12
- # copy of this software and associated documentation files (the "Software"),
13
- # to deal in the Software without restriction, including without limitation
14
- # the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
- # and/or sell copies of the Software, and to permit persons to whom the
10
+ #
11
+ # Permission is hereby granted, free of charge, to any person obtaining a
12
+ # copy of this software and associated documentation files (the "Software"),
13
+ # to deal in the Software without restriction, including without limitation
14
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
+ # and/or sell copies of the Software, and to permit persons to whom the
16
16
  # Software is furnished to do so, subject to the following conditions:
17
- #
18
- # The above copyright notice and this permission notice shall be included in
17
+ #
18
+ # The above copyright notice and this permission notice shall be included in
19
19
  # all copies or substantial portions of the Software.
20
- #
21
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
- # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
+ #
21
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
+ # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
27
  # DEALINGS IN THE SOFTWARE.
28
28
 
29
29
 
@@ -193,7 +193,7 @@ module TwitterCldr
193
193
  emit_string(obj, level)
194
194
  when TrueClass, FalseClass
195
195
  obj.to_s
196
- when Fixnum, Bignum, Float
196
+ when Integer, Float
197
197
  obj.to_s
198
198
  when Date
199
199
  obj.to_s
@@ -390,4 +390,4 @@ module TwitterCldr
390
390
  end
391
391
 
392
392
  end
393
- end
393
+ end
@@ -4,5 +4,5 @@
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  module TwitterCldr
7
- VERSION = '4.3.1'
7
+ VERSION = '4.4.0'
8
8
  end
@@ -17,7 +17,7 @@ describe Collator do
17
17
  describe '.default_trie' do
18
18
  before(:each) do
19
19
  clear_default_trie_cache
20
- mock(TrieLoader).load_default_trie { trie }
20
+ expect(TrieLoader).to receive(:load_default_trie).and_return(trie)
21
21
  end
22
22
 
23
23
  it 'returns default fractional collation elements trie' do
@@ -38,8 +38,12 @@ describe Collator do
38
38
 
39
39
  before(:each) do
40
40
  clear_tailored_tries_cache
41
- stub(Collator).default_trie { trie }
42
- mock(TrieLoader).load_tailored_trie(locale, Collator.default_trie) { trie }
41
+ allow(Collator).to receive(:default_trie).and_return(trie)
42
+ expect(TrieLoader).to(
43
+ receive(:load_tailored_trie)
44
+ .with(locale, Collator.default_trie)
45
+ .and_return(trie)
46
+ )
43
47
  end
44
48
 
45
49
  it 'returns default fractional collation elements trie' do
@@ -57,7 +61,12 @@ describe Collator do
57
61
 
58
62
  describe '#initialize' do
59
63
  before :each do
60
- any_instance_of(Collator) { |c| stub(c).load_trie { trie } }
64
+ allow(Collator).to receive(:new) do |*args|
65
+ Collator.allocate.tap do |c|
66
+ allow(c).to receive(:load_trie).and_return(trie)
67
+ c.send(:initialize, *args)
68
+ end
69
+ end
61
70
  end
62
71
 
63
72
  context 'without locale' do
@@ -84,9 +93,9 @@ describe Collator do
84
93
  let(:collation_elements) { [[39, 5, 5], [41, 5, 5], [43, 5, 5]] }
85
94
 
86
95
  before :each do
87
- any_instance_of(TwitterCldr::Shared::CodePoint) do |instance|
88
- stub(instance).combining_class_for { 0 }
89
- end
96
+ allow_any_instance_of(TwitterCldr::Shared::CodePoint).to(
97
+ receive(:combining_class_for).and_return(0)
98
+ )
90
99
  end
91
100
 
92
101
  it 'returns collation elements for a string' do
@@ -116,18 +125,24 @@ describe Collator do
116
125
  let(:sort_key) { [39, 41, 43, 1, 7, 1, 7] }
117
126
 
118
127
  context 'with a loaded trie' do
119
- before(:each) { mock(TrieLoader).load_default_trie { trie } }
128
+ before(:each) { expect(TrieLoader).to receive(:load_default_trie).and_return(trie) }
120
129
 
121
130
  describe 'calculating sort key' do
122
- before(:each) { mock(TwitterCldr::Collation::SortKeyBuilder).build(collation_elements, case_first: nil, maximum_level: nil) { sort_key } }
131
+ before(:each) do
132
+ expect(TwitterCldr::Collation::SortKeyBuilder).to(
133
+ receive(:build)
134
+ .with(collation_elements, case_first: nil, maximum_level: nil)
135
+ .and_return(sort_key)
136
+ )
137
+ end
123
138
 
124
139
  it 'calculates sort key for a string' do
125
- mock(collator).get_collation_elements(string) { collation_elements }
140
+ expect(collator).to receive(:get_collation_elements).with(string).and_return(collation_elements)
126
141
  expect(collator.get_sort_key(string)).to eq(sort_key)
127
142
  end
128
143
 
129
144
  it 'calculates sort key for an array of code points (represented as hex strings)' do
130
- mock(collator).get_collation_elements(code_points) { collation_elements }
145
+ expect(collator).to receive(:get_collation_elements).with(code_points).and_return(collation_elements)
131
146
  expect(collator.get_sort_key(code_points)).to eq(sort_key)
132
147
  end
133
148
  end
@@ -138,25 +153,25 @@ describe Collator do
138
153
  let(:maximum_level) { 2 }
139
154
 
140
155
  it 'passes case-first sort option to sort key builder' do
141
- mock(TwitterCldr::Collation::TrieLoader).load_tailored_trie(locale, trie) { TwitterCldr::Utils::Trie.new }
142
- mock(TwitterCldr::Collation::TrieBuilder).tailoring_data(locale) { { collator_options: { case_first: case_first } } }
156
+ expect(TwitterCldr::Collation::TrieLoader).to receive(:load_tailored_trie).with(locale, trie).and_return(TwitterCldr::Utils::Trie.new)
157
+ expect(TwitterCldr::Collation::TrieBuilder).to receive(:tailoring_data).with(locale).and_return(collator_options: { case_first: case_first })
143
158
 
144
159
  collator = Collator.new(locale)
145
160
 
146
- mock(collator).get_collation_elements(code_points) { collation_elements }
147
- mock(TwitterCldr::Collation::SortKeyBuilder).build(collation_elements, case_first: case_first, maximum_level: nil) { sort_key }
161
+ expect(collator).to receive(:get_collation_elements).with(code_points).and_return(collation_elements)
162
+ expect(TwitterCldr::Collation::SortKeyBuilder).to receive(:build).with(collation_elements, case_first: case_first, maximum_level: nil).and_return(sort_key)
148
163
 
149
164
  expect(collator.get_sort_key(code_points)).to eq(sort_key)
150
165
  end
151
166
 
152
167
  it 'passes maximum_level option to sort key builder' do
153
- mock(TwitterCldr::Collation::TrieLoader).load_tailored_trie(locale, trie) { TwitterCldr::Utils::Trie.new }
154
- mock(TwitterCldr::Collation::TrieBuilder).tailoring_data(locale) { { collator_options: { case_first: case_first } } }
168
+ expect(TwitterCldr::Collation::TrieLoader).to receive(:load_tailored_trie).with(locale, trie).and_return(TwitterCldr::Utils::Trie.new)
169
+ expect(TwitterCldr::Collation::TrieBuilder).to receive(:tailoring_data).with(locale).and_return(collator_options: { case_first: case_first })
155
170
 
156
171
  collator = Collator.new(locale)
157
172
 
158
- mock(collator).get_collation_elements(code_points) { collation_elements }
159
- mock(TwitterCldr::Collation::SortKeyBuilder).build(collation_elements, case_first: case_first, maximum_level: maximum_level) { sort_key }
173
+ expect(collator).to receive(:get_collation_elements).with(code_points).and_return(collation_elements)
174
+ expect(TwitterCldr::Collation::SortKeyBuilder).to receive(:build).with(collation_elements, case_first: case_first, maximum_level: maximum_level).and_return(sort_key)
160
175
 
161
176
  expect(collator.get_sort_key(code_points, maximum_level: maximum_level)).to eq(sort_key)
162
177
  end
@@ -179,7 +194,7 @@ describe Collator do
179
194
  let(:sort_key) { [1, 3, 8, 9] }
180
195
  let(:another_sort_key) { [6, 8, 9, 2] }
181
196
 
182
- before(:each) { stub(Collator).default_trie { trie } }
197
+ before(:each) { allow(Collator).to receive(:default_trie).and_return(trie) }
183
198
 
184
199
  it 'compares strings by sort keys' do
185
200
  stub_sort_key(collator, 'foo', sort_key)
@@ -190,7 +205,7 @@ describe Collator do
190
205
  end
191
206
 
192
207
  it 'returns 0 without computing sort keys if the strings are equal' do
193
- dont_allow(collator).get_sort_key
208
+ expect(collator).to_not receive(:get_sort_key)
194
209
 
195
210
  expect(collator.compare('foo', 'foo')).to eq(0)
196
211
  end
@@ -203,7 +218,7 @@ describe Collator do
203
218
  let(:sorted) { %w[aaa abc bca] }
204
219
 
205
220
  before :each do
206
- stub(Collator).default_trie { trie }
221
+ allow(Collator).to receive(:default_trie).and_return(trie)
207
222
  sort_keys.each { |s, key| mock_sort_key(collator, s, key) }
208
223
  end
209
224
 
@@ -227,16 +242,22 @@ describe Collator do
227
242
 
228
243
  describe 'tailoring support' do
229
244
  before(:each) do
230
- stub(TwitterCldr).get_resource(:collation, :tailoring, locale) { YAML.load(tailoring_resource_stub) }
231
-
232
- mock(File).open(TrieBuilder::FRACTIONAL_UCA_SHORT_PATH, 'r') do |*args|
233
- args.last.call(fractional_uca_short_stub)
234
- end
235
-
236
- mock(TrieLoader).load_default_trie { TrieBuilder.load_default_trie }
237
- mock(TrieLoader).load_tailored_trie.with_any_args { |*args| TrieBuilder.load_tailored_trie(*args) }
238
-
239
- stub(TwitterCldr::Normalization).normalize_code_points { |code_points| code_points }
245
+ allow(TwitterCldr).to(
246
+ receive(:get_resource)
247
+ .with(:collation, :tailoring, locale)
248
+ .and_return(YAML.load(tailoring_resource_stub))
249
+ )
250
+
251
+ expect(File).to(
252
+ receive(:open)
253
+ .with(TrieBuilder::FRACTIONAL_UCA_SHORT_PATH, 'r')
254
+ .and_yield(fractional_uca_short_stub)
255
+ )
256
+
257
+ expect(TrieLoader).to receive(:load_default_trie) { TrieBuilder.load_default_trie }
258
+ expect(TrieLoader).to receive(:load_tailored_trie) { |*args| TrieBuilder.load_tailored_trie(*args) }
259
+
260
+ allow(TwitterCldr::Normalization).to receive(:normalize_code_points) { |code_points| code_points }
240
261
  end
241
262
 
242
263
  let(:locale) { :some_locale }
@@ -309,11 +330,11 @@ END
309
330
  end
310
331
 
311
332
  def mock_sort_key(collator, string, sort_key)
312
- mock(collator).get_sort_key(string) { sort_key }
333
+ expect(collator).to receive(:get_sort_key).with(string).and_return(sort_key)
313
334
  end
314
335
 
315
336
  def stub_sort_key(collator, string, sort_key)
316
- stub(collator).get_sort_key(string) { sort_key }
337
+ allow(collator).to receive(:get_sort_key).with(string).and_return(sort_key)
317
338
  end
318
339
 
319
340
  def clear_tries_cache
@@ -17,8 +17,8 @@ describe SortKeyBuilder do
17
17
  it 'returns a sort key for a given array of collation elements' do
18
18
  sort_key = SortKeyBuilder.new(collation_elements)
19
19
 
20
- mock(SortKeyBuilder).new(collation_elements, nil) { sort_key }
21
- mock(sort_key).bytes_array { sort_key_bytes }
20
+ expect(SortKeyBuilder).to receive(:new).with(collation_elements, nil).and_return(sort_key)
21
+ expect(sort_key).to receive(:bytes_array).and_return(sort_key_bytes)
22
22
 
23
23
  expect(SortKeyBuilder.build(collation_elements)).to eq(sort_key_bytes)
24
24
  end
@@ -54,7 +54,7 @@ describe SortKeyBuilder do
54
54
  end
55
55
 
56
56
  it 'builds bytes array only once' do
57
- mock(sort_key).build_bytes_array { sort_key_bytes }
57
+ expect(sort_key).to receive(:build_bytes_array).and_return(sort_key_bytes)
58
58
  sort_key.bytes_array.object_id == sort_key.bytes_array.object_id
59
59
  end
60
60
 
@@ -120,7 +120,7 @@ END
120
120
 
121
121
  before :each do
122
122
  mock_default_table
123
- mock(TrieBuilder).tailoring_data(locale) { tailoring_data }
123
+ expect(TrieBuilder).to receive(:tailoring_data).with(locale).and_return(tailoring_data)
124
124
  end
125
125
 
126
126
  it 'returns a TrieWithFallback' do
@@ -186,15 +186,17 @@ END
186
186
  let(:locale) { :fu }
187
187
 
188
188
  it 'loads tailoring data' do
189
- mock(TwitterCldr).get_resource(:collation, :tailoring, locale) { tailoring_data }
189
+ expect(TwitterCldr).to receive(:get_resource).with(:collation, :tailoring, locale).and_return(tailoring_data)
190
190
  expect(TrieBuilder.tailoring_data(locale)).to eq(tailoring_data)
191
191
  end
192
192
  end
193
193
 
194
194
  def mock_default_table
195
- mock(File).open(TrieBuilder::FRACTIONAL_UCA_SHORT_PATH, 'r') do |*args|
196
- args.last.call(fractional_uca_short_stub)
197
- end
195
+ expect(File).to(
196
+ receive(:open)
197
+ .with(TrieBuilder::FRACTIONAL_UCA_SHORT_PATH, 'r')
198
+ .and_yield(fractional_uca_short_stub)
199
+ )
198
200
  end
199
201
 
200
202
  end