i18n-spec 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
data/i18n-spec.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{i18n-spec}
8
- s.version = "0.0.9"
8
+ s.version = "0.0.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Christopher Dell}]
12
- s.date = %q{2011-12-21}
12
+ s.date = %q{2011-12-25}
13
13
  s.description = %q{Includes a number of rspec matchers to make specing your locale files easy peasy.}
14
14
  s.email = %q{chris@tigrish.com}
15
15
  s.extra_rdoc_files = [
@@ -47,6 +47,7 @@ Gem::Specification.new do |s|
47
47
  "spec/fixtures/not_subset.yml",
48
48
  "spec/fixtures/unparseable.yml",
49
49
  "spec/lib/i18n-spec/matchers_spec.rb",
50
+ "spec/lib/i18n-spec/models/locale_file_spec.rb",
50
51
  "spec/spec_helper.rb"
51
52
  ]
52
53
  s.homepage = %q{http://github.com/tigrish/i18n-spec}
@@ -1,6 +1,11 @@
1
1
  RSpec::Matchers.define :have_valid_pluralization_keys do |expected|
2
2
  match do |actual|
3
3
  locale_file = I18nSpec::LocaleFile.new(actual)
4
- locale_file.has_valid_pluralization_keys?
4
+ @invalid_keys = locale_file.invalid_pluralization_keys
5
+ @invalid_keys.empty?
6
+ end
7
+
8
+ failure_message_for_should do |filepath|
9
+ "expected #{filepath} to not include invalid pluralization keys :\n- " << @invalid_keys.join("\n- ")
5
10
  end
6
11
  end
@@ -13,13 +13,29 @@ module I18nSpec
13
13
  end
14
14
 
15
15
  def translations
16
- @translations ||= Psych.load_file(@filepath)
16
+ @translations ||= Psych.load(content)
17
17
  end
18
18
 
19
19
  def flattened_translations
20
20
  @flattened_translations ||= flatten_tree(translations.values.first)
21
21
  end
22
22
 
23
+ def pluralizations
24
+ flatten_tree(translations).select do |key, value|
25
+ value.is_a?(Hash)
26
+ end
27
+ end
28
+
29
+ def invalid_pluralization_keys
30
+ invalid = []
31
+ pluralizations.each do |parent, pluralization|
32
+ pluralization.keys.select do |key, value|
33
+ invalid << [parent, key].join('.') unless PLURALIZATION_KEYS.include?(key)
34
+ end
35
+ end
36
+ invalid
37
+ end
38
+
23
39
  def is_parseable?
24
40
  begin
25
41
  Psych.load_file(@filepath)
@@ -29,13 +45,6 @@ module I18nSpec
29
45
  end
30
46
  end
31
47
 
32
- def has_valid_pluralization_keys?
33
- pluralizations.each do |key, pluralization|
34
- return false unless pluralization.keys.all? {|k| PLURALIZATION_KEYS.include?(k)}
35
- end
36
- true
37
- end
38
-
39
48
  def has_one_top_level_namespace?
40
49
  translations.keys.size == 1
41
50
  end
@@ -63,10 +72,5 @@ module I18nSpec
63
72
  keys.any? {|k| PLURALIZATION_KEYS.include?(k) }
64
73
  end
65
74
 
66
- def pluralizations
67
- flatten_tree(translations).select do |key, value|
68
- value.is_a?(Hash)
69
- end
70
- end
71
75
  end
72
76
  end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe I18nSpec::LocaleFile, "#pluralizations" do
4
+ def content
5
+ "en:
6
+ cats:
7
+ one: one
8
+ two: two
9
+ three: three
10
+ dogs:
11
+ one: one
12
+ some: some
13
+ birds:
14
+ penguins: penguins
15
+ doves: doves"
16
+ end
17
+
18
+ it "returns the leaf where one of the keys is a pluralization key" do
19
+ locale_file = I18nSpec::LocaleFile.new('test.yml')
20
+ locale_file.should_receive(:content).and_return(content)
21
+ locale_file.pluralizations.should == {
22
+ 'en.cats' => {'one' => 'one', 'two' => 'two', 'three' => 'three'},
23
+ 'en.dogs' => {'one' => 'one', 'some' => 'some'},
24
+ }
25
+ end
26
+ end
27
+
28
+ describe I18nSpec::LocaleFile, "#invalid_pluralization_keys" do
29
+ def content
30
+ "en:
31
+ cats:
32
+ one: one
33
+ two: two
34
+ tommy: tommy
35
+ tabby: tabby
36
+ dogs:
37
+ one: one
38
+ some: some
39
+ birds:
40
+ zero: zero
41
+ other: other"
42
+ end
43
+
44
+ it "returns pluralization keys where key is not in PLURALIZATION_KEYS" do
45
+ locale_file = I18nSpec::LocaleFile.new('test.yml')
46
+ locale_file.should_receive(:content).and_return(content)
47
+ locale_file.invalid_pluralization_keys.should == ['en.cats.tommy', 'en.cats.tabby', 'en.dogs.some']
48
+ end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-21 00:00:00.000000000Z
12
+ date: 2011-12-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70322522003820 !ruby/object:Gem::Requirement
16
+ requirement: &70298451985820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.3.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70322522003820
24
+ version_requirements: *70298451985820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70322522003340 !ruby/object:Gem::Requirement
27
+ requirement: &70298451985220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.10
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70322522003340
35
+ version_requirements: *70298451985220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &70322522002860 !ruby/object:Gem::Requirement
38
+ requirement: &70298451984620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70322522002860
46
+ version_requirements: *70298451984620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &70322522002380 !ruby/object:Gem::Requirement
49
+ requirement: &70298451984020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70322522002380
57
+ version_requirements: *70298451984020
58
58
  description: Includes a number of rspec matchers to make specing your locale files
59
59
  easy peasy.
60
60
  email: chris@tigrish.com
@@ -94,6 +94,7 @@ files:
94
94
  - spec/fixtures/not_subset.yml
95
95
  - spec/fixtures/unparseable.yml
96
96
  - spec/lib/i18n-spec/matchers_spec.rb
97
+ - spec/lib/i18n-spec/models/locale_file_spec.rb
97
98
  - spec/spec_helper.rb
98
99
  homepage: http://github.com/tigrish/i18n-spec
99
100
  licenses:
@@ -110,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  segments:
112
113
  - 0
113
- hash: -2200790858591140101
114
+ hash: -1979141701292860623
114
115
  required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  none: false
116
117
  requirements: