i18n-spec 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -43,3 +43,13 @@ If you need to test that all translations have been completed :
43
43
  describe "config/locales/fr.yml" do
44
44
  it { should be_a_complete_translation_of 'config/locales/en.yml' }
45
45
  end
46
+
47
+ ## Rake tasks
48
+
49
+ You can check a locale file with the following task :
50
+
51
+ rake i18n:check FILEPATH
52
+
53
+ or check a whole directory :
54
+
55
+ rake i18n:check DIRECTORY
data/Rakefile CHANGED
@@ -38,7 +38,7 @@ end
38
38
 
39
39
  task :default => :spec
40
40
 
41
- require 'rake/rdoctask'
41
+ require 'rdoc/task'
42
42
  Rake::RDocTask.new do |rdoc|
43
43
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
44
 
@@ -47,3 +47,5 @@ Rake::RDocTask.new do |rdoc|
47
47
  rdoc.rdoc_files.include('README*')
48
48
  rdoc.rdoc_files.include('lib/**/*.rb')
49
49
  end
50
+
51
+ require './lib/i18n-spec/tasks/checker'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.1.0
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.10"
8
+ s.version = "0.1.0"
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-25}
12
+ s.date = %q{2011-12-31}
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 = [
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  "lib/i18n-spec/matchers/have_valid_pluralization_keys_matcher.rb",
39
39
  "lib/i18n-spec/models/locale_file.rb",
40
40
  "lib/i18n-spec/shared_examples/valid_locale_file.rb",
41
+ "lib/i18n-spec/tasks/checker.rb",
41
42
  "spec/fixtures/en.yml",
42
43
  "spec/fixtures/es.yml",
43
44
  "spec/fixtures/fr.yml",
@@ -1,6 +1,10 @@
1
1
  RSpec::Matchers.define :be_parseable do |expected|
2
2
  match do |actual|
3
- locale_file = I18nSpec::LocaleFile.new(actual)
4
- locale_file.is_parseable?
3
+ @locale_file = I18nSpec::LocaleFile.new(actual)
4
+ @locale_file.is_parseable?
5
+ end
6
+
7
+ failure_message_for_should do |filepath|
8
+ "expected #{filepath} to be parseable but got :\n- #{@locale_file.errors[:unparseable]}"
5
9
  end
6
10
  end
@@ -1,11 +1,10 @@
1
1
  RSpec::Matchers.define :have_valid_pluralization_keys do |expected|
2
2
  match do |actual|
3
- locale_file = I18nSpec::LocaleFile.new(actual)
4
- @invalid_keys = locale_file.invalid_pluralization_keys
5
- @invalid_keys.empty?
3
+ @locale_file = I18nSpec::LocaleFile.new(actual)
4
+ @locale_file.invalid_pluralization_keys.empty?
6
5
  end
7
6
 
8
7
  failure_message_for_should do |filepath|
9
- "expected #{filepath} to not include invalid pluralization keys :\n- " << @invalid_keys.join("\n- ")
8
+ "expected #{filepath} to not include invalid pluralization keys :\n- " << @locale_file.errors[:invalid_pluralization_keys].join("\n- ")
10
9
  end
11
10
  end
@@ -3,9 +3,11 @@ module I18nSpec
3
3
  PLURALIZATION_KEYS = %w{zero one two few many other}
4
4
 
5
5
  attr_accessor :filepath
6
+ attr_reader :errors
6
7
 
7
8
  def initialize(filepath)
8
9
  @filepath = filepath
10
+ @errors = {}
9
11
  end
10
12
 
11
13
  def content
@@ -33,14 +35,16 @@ module I18nSpec
33
35
  invalid << [parent, key].join('.') unless PLURALIZATION_KEYS.include?(key)
34
36
  end
35
37
  end
38
+ @errors[:invalid_pluralization_keys] = invalid unless invalid.empty?
36
39
  invalid
37
40
  end
38
41
 
39
42
  def is_parseable?
40
43
  begin
41
- Psych.load_file(@filepath)
44
+ Psych.load(content)
42
45
  true
43
46
  rescue Psych::SyntaxError => e
47
+ @errors[:unparseable] = e.to_s
44
48
  false
45
49
  end
46
50
  end
@@ -0,0 +1,55 @@
1
+ require 'i18n-spec'
2
+
3
+ I18nSpec::LOG_DETAIL_PREDICATE = " | - "
4
+
5
+ namespace :i18n do
6
+ desc "Checks the validity of a locale file"
7
+ task :check do
8
+
9
+
10
+ if ARGV[1].nil?
11
+ puts "You must specifiy a file path or a folder path"
12
+ return
13
+ elsif File.directory?(ARGV[1])
14
+ filepaths = Dir.glob("#{ARGV[1]}/*.yml")
15
+ else
16
+ filepaths = [ARGV[1]]
17
+ end
18
+
19
+ filepaths.each do |filepath|
20
+ puts "-"*80
21
+ puts filepath
22
+
23
+ fatals, errors, warnings = [0, 0, 0]
24
+ locale_file = I18nSpec::LocaleFile.new(filepath)
25
+
26
+ unless locale_file.is_parseable?
27
+ log :fatal, 'could not be parsed', format_str(locale_file.errors[:unparseable])
28
+ fatals += 1
29
+ break
30
+ end
31
+
32
+ unless locale_file.invalid_pluralization_keys.empty?
33
+ log :error, 'invalid pluralization keys', format_array(locale_file.errors[:invalid_pluralization_keys])
34
+ errors += 1
35
+ end
36
+
37
+ puts '[OK]' if fatals + errors + warnings == 0
38
+ end
39
+
40
+ puts "="*80
41
+ end
42
+
43
+ def log(level, msg, detail=nil)
44
+ puts " - [" << level.to_s.upcase << '] ' << msg
45
+ puts detail if detail
46
+ end
47
+
48
+ def format_array(array)
49
+ [I18nSpec::LOG_DETAIL_PREDICATE, array.join(I18nSpec::LOG_DETAIL_PREDICATE)].join
50
+ end
51
+
52
+ def format_str(str)
53
+ [I18nSpec::LOG_DETAIL_PREDICATE, str].join
54
+ end
55
+ end
@@ -1,49 +1,85 @@
1
1
  require 'spec_helper'
2
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
3
+ module LocaleFileHelper
4
+ def locale_file_with_content(content)
19
5
  locale_file = I18nSpec::LocaleFile.new('test.yml')
20
6
  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
- }
7
+ locale_file
25
8
  end
26
9
  end
27
10
 
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"
11
+ describe I18nSpec::LocaleFile do
12
+ include LocaleFileHelper
13
+
14
+ describe "#is_parseable?" do
15
+ context "when YAML is parseable" do
16
+ let(:locale_file) { locale_file = locale_file_with_content("en:\n hello: world") }
17
+
18
+ it "returns true" do
19
+ locale_file.is_parseable?.should == true
20
+ end
21
+ end
22
+
23
+ context "when YAML is NOT parseable" do
24
+ let(:locale_file) { locale_file_with_content("<This isn't YAML>: foo: bar:") }
25
+
26
+ it "returns false" do
27
+ locale_file.is_parseable?.should == false
28
+ end
29
+
30
+ it "adds an :unparseable error" do
31
+ locale_file.is_parseable?
32
+ locale_file.errors[:unparseable].should_not be_nil
33
+ end
34
+ end
42
35
  end
43
36
 
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']
37
+ describe "#pluralizations" do
38
+ let(:content) {
39
+ "en:
40
+ cats:
41
+ one: one
42
+ two: two
43
+ three: three
44
+ dogs:
45
+ one: one
46
+ some: some
47
+ birds:
48
+ penguins: penguins
49
+ doves: doves"}
50
+
51
+ it "returns the leaf where one of the keys is a pluralization key" do
52
+ locale_file = locale_file_with_content(content)
53
+ locale_file.pluralizations.should == {
54
+ 'en.cats' => {'one' => 'one', 'two' => 'two', 'three' => 'three'},
55
+ 'en.dogs' => {'one' => 'one', 'some' => 'some'},
56
+ }
57
+ end
58
+ end
59
+
60
+ describe "#invalid_pluralization_keys" do
61
+ let(:content) {
62
+ "en:
63
+ cats:
64
+ one: one
65
+ two: two
66
+ tommy: tommy
67
+ tabby: tabby
68
+ dogs:
69
+ one: one
70
+ some: some
71
+ birds:
72
+ zero: zero
73
+ other: other"}
74
+ let(:locale_file) { locale_file_with_content(content) }
75
+
76
+ it "returns pluralization keys where key is not in PLURALIZATION_KEYS" do
77
+ locale_file.invalid_pluralization_keys.should == ['en.cats.tommy', 'en.cats.tabby', 'en.dogs.some']
78
+ end
79
+
80
+ it "adds a :invalid_pluralization_keys error with each invalid key" do
81
+ locale_file.invalid_pluralization_keys
82
+ locale_file.errors[:invalid_pluralization_keys].should == ['en.cats.tommy', 'en.cats.tabby', 'en.dogs.some']
83
+ end
48
84
  end
49
85
  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.10
4
+ version: 0.1.0
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-25 00:00:00.000000000Z
12
+ date: 2011-12-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70298451985820 !ruby/object:Gem::Requirement
16
+ requirement: &70320506471860 !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: *70298451985820
24
+ version_requirements: *70320506471860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70298451985220 !ruby/object:Gem::Requirement
27
+ requirement: &70320506470580 !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: *70298451985220
35
+ version_requirements: *70320506470580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &70298451984620 !ruby/object:Gem::Requirement
38
+ requirement: &70320506469500 !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: *70298451984620
46
+ version_requirements: *70320506469500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &70298451984020 !ruby/object:Gem::Requirement
49
+ requirement: &70320506468020 !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: *70298451984020
57
+ version_requirements: *70320506468020
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
@@ -85,6 +85,7 @@ files:
85
85
  - lib/i18n-spec/matchers/have_valid_pluralization_keys_matcher.rb
86
86
  - lib/i18n-spec/models/locale_file.rb
87
87
  - lib/i18n-spec/shared_examples/valid_locale_file.rb
88
+ - lib/i18n-spec/tasks/checker.rb
88
89
  - spec/fixtures/en.yml
89
90
  - spec/fixtures/es.yml
90
91
  - spec/fixtures/fr.yml
@@ -111,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  segments:
113
114
  - 0
114
- hash: -1979141701292860623
115
+ hash: 3595436614852658303
115
116
  required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  none: false
117
118
  requirements: