bisu 1.2.3 → 1.2.4

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.
@@ -0,0 +1,61 @@
1
+ describe Bisu::GoogleSheet do
2
+ subject(:to_hash) { Bisu::GoogleSheet.new(sheet_id, key_column).to_hash }
3
+
4
+ let(:sheet_id) { "abc1234567890" }
5
+ let(:url_info) { "https://spreadsheets.google.com/feeds/worksheets/#{sheet_id}/public/full" }
6
+ let(:url_sheet) { "https://spreadsheets.google.com/feeds/list/#{sheet_id}/od6/public/full" }
7
+
8
+ let(:key_column) { "key_column" }
9
+
10
+ context "when given a valid sheet" do
11
+ let(:file_info) { File.read("spec/fixtures/sample_kb_public_info.html") }
12
+ let(:file_sheet) { File.read("spec/fixtures/sample_kb_public_sheet.html") }
13
+
14
+ before do
15
+ stub_request(:get, url_info).to_return(:status => 200, :body => file_info, :headers => {})
16
+ stub_request(:get, url_sheet).to_return(:status => 200, :body => file_sheet, :headers => {})
17
+ end
18
+
19
+ it do
20
+ expect { to_hash }.not_to raise_error
21
+ end
22
+
23
+ it "returns an hash" do
24
+ expect(to_hash).to include("kConnectEmail")
25
+ expect(to_hash["kConnectEmail"]).to include("korean")
26
+ expect(to_hash["kConnectEmail"]).to include("spanish" => "Conéctate con Email")
27
+ end
28
+
29
+ context "but the key column is not present in the first sheet" do
30
+ let(:key_column) { "expecting_another_key_column" }
31
+
32
+ it do
33
+ expect { to_hash }.to raise_error /Cannot find key column/
34
+ end
35
+ end
36
+ end
37
+
38
+ context "when given an inexistent sheet" do
39
+ before { stub_request(:get, url_info).to_return(:status => 400, :body => "Not Found", :headers => {}) }
40
+
41
+ it do
42
+ expect { to_hash }.to raise_error /Cannot access sheet/
43
+ end
44
+ end
45
+
46
+ context "when given a private sheet" do
47
+ before { stub_request(:get, url_info).to_return(:status => 302, :body => "<HTML></HTML>", :headers => {}) }
48
+
49
+ it do
50
+ expect { to_hash }.to raise_error /Cannot access sheet/
51
+ end
52
+ end
53
+
54
+ context "when url content is not XML" do
55
+ before { stub_request(:get, url_info).to_return(:status => 200, :body => "This is not XML; { this: \"is json\" }", :headers => {}) }
56
+
57
+ it do
58
+ expect { to_hash }.to raise_error /Cannot parse. Expected XML/
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,149 @@
1
+ describe Bisu::Localizer do
2
+ let(:language) { "portuguese" }
3
+ let(:locale) { "PT-PT" }
4
+
5
+ let(:keys) { {
6
+ "kTranslationKey" => { language => "Não sabes nada João das Neves" },
7
+ "kTranslationKey2" => { language => "Naaada!" },
8
+ "kMissingTransKey" => { "english" => "You know little John Snow" },
9
+ "k1ParameterKey" => { language => "Não sabes nada %{name}" },
10
+ "k2ParametersKey" => { language => "Sabes %{perc} por cento %{name}" },
11
+
12
+ # type dependent translations
13
+ "kDoubleQuoted" => { language => "Não sabes nada \"João das Neves\"" },
14
+ "kSingleQuoted" => { language => "Não sabes nada 'João das Neves'" },
15
+ "kEllipsis" => { language => "Não sabes nada João das Neves..." },
16
+ "kAmpersand" => { language => "Não sabes nada João das Neves & Pícaros" },
17
+ "kAtSign" => { language => "\@johnsnow sabes alguma coisa?" }
18
+ } }
19
+
20
+ let(:kb) { Bisu::Dictionary.new(keys) }
21
+ let(:localizer) { Bisu::Localizer.new(kb, type) }
22
+
23
+ shared_examples_for "a localizer" do
24
+ it { expect { localizer }.not_to raise_error }
25
+
26
+ def translates(text, to:)
27
+ translation = localizer.localize(text, language, locale)
28
+ expect(translation).to eq to
29
+ end
30
+
31
+ it { translates("a line with no key", to: "a line with no key") }
32
+
33
+ it { translates("this special key: $specialKComment1$", to: "this special key: This file was automatically generated based on a translation template.") }
34
+ it { translates("this special key: $specialKComment2$", to: "this special key: Remember to CHANGE THE TEMPLATE and not this file!") }
35
+ it { translates("this special key: $specialKLanguage$", to: "this special key: #{language}") }
36
+ it { translates("this special key: $specialKLocale$", to: "this special key: #{locale}") }
37
+
38
+ it { translates("this key: $kTranslationKey$", to: "this key: Não sabes nada João das Neves") }
39
+ it { translates("this unknown key: $kUnknownKey$", to: "this unknown key: $kUnknownKey$") }
40
+ it { translates("this key with missing translations: $kMissingTransKey$", to: "this key with missing translations: $kMissingTransKey$") }
41
+ it { translates("these 2 keys: $kTranslationKey$, $kTranslationKey2$", to: "these 2 keys: Não sabes nada João das Neves, Naaada!") }
42
+
43
+ it { translates("1 parameter: $k1ParameterKey$", to: "1 parameter: Não sabes nada %{name}") }
44
+ it { translates("1 parameter: $k1ParameterKey{name:%1$s}$", to: "1 parameter: Não sabes nada %1$s") }
45
+ it { translates("2 parameters: $k2ParametersKey$", to: "2 parameters: Sabes %{perc} por cento %{name}") }
46
+ it { translates("2 parameters: $k2ParametersKey{perc:%2$d, name:%1$s}$", to: "2 parameters: Sabes %2$d por cento %1$s") }
47
+ it { translates("2 parameters: $k2ParametersKey{name:%1$s, perc:%2$d}$", to: "2 parameters: Sabes %2$d por cento %1$s") }
48
+
49
+ # type dependent translations
50
+
51
+ it { translates("$kDoubleQuoted$", to: expected[:double_quoted]) }
52
+ it { translates("$kSingleQuoted$", to: expected[:single_quoted]) }
53
+ it { translates("$kEllipsis$", to: expected[:ellipsis]) }
54
+ it { translates("$kAmpersand$", to: expected[:ampersand]) }
55
+ it { translates("$kAtSign$", to: expected[:at_sign]) }
56
+
57
+ # error handling
58
+
59
+ it "throws a warnings when key has no translation" do
60
+ expect {
61
+ localizer.localize("$kUnknownKey$", language, locale)
62
+ }.to change { Bisu::Logger.summary[:warn] }.by(1)
63
+ .and not_change { Bisu::Logger.summary[:error] }
64
+ end
65
+
66
+ it "does not throw a warning when key is found" do
67
+ expect {
68
+ localizer.localize("$kTranslationKey$", language, locale)
69
+ }.to not_change { Bisu::Logger.summary[:warn] }
70
+ .and not_change { Bisu::Logger.summary[:error] }
71
+ end
72
+
73
+ it "throws an error when missing key parameters (expect on ruby on rails)" do
74
+ if type == :ror
75
+ expect {
76
+ localizer.localize("$k1ParameterKey$", language, locale)
77
+ }.to not_change { Bisu::Logger.summary[:warn] }
78
+ .and not_change { Bisu::Logger.summary[:error] }
79
+ else
80
+ expect {
81
+ localizer.localize("$k1ParameterKey$", language, locale)
82
+ }.to not_change { Bisu::Logger.summary[:warn] }
83
+ .and change { Bisu::Logger.summary[:error] }.by(1)
84
+ end
85
+ end
86
+
87
+ it "does not throw an error when key parameters where given" do
88
+ Bisu::Logger.silent_mode = false
89
+
90
+ expect {
91
+ localizer.localize("$k1ParameterKey{name:%1$s}$", language, locale)
92
+ }.to not_change { Bisu::Logger.summary[:warn] }
93
+ .and not_change { Bisu::Logger.summary[:error] }
94
+ end
95
+
96
+ it "throws an error when given parameters for parameterless key" do
97
+ expect {
98
+ localizer.localize("$kTranslationKey{param:%s}$", language, locale)
99
+ }.to not_change { Bisu::Logger.summary[:warn] }
100
+ .and change { Bisu::Logger.summary[:error] }.by(1)
101
+ end
102
+ end
103
+
104
+ let(:type_dependent_defaults) { {
105
+ double_quoted: keys["kDoubleQuoted"][language],
106
+ single_quoted: keys["kSingleQuoted"][language],
107
+ ellipsis: keys["kEllipsis"][language],
108
+ ampersand: keys["kAmpersand"][language],
109
+ at_sign: keys["kAtSign"][language]
110
+ } }
111
+
112
+ describe "of type iOS" do
113
+ let(:type) { :ios }
114
+
115
+ let(:expected) { type_dependent_defaults.merge(
116
+ double_quoted: "Não sabes nada \\\"João das Neves\\\""
117
+ ) }
118
+
119
+ it_behaves_like "a localizer"
120
+ end
121
+
122
+ describe "of type Android" do
123
+ let(:type) { :android }
124
+
125
+ let(:expected) { type_dependent_defaults.merge(
126
+ single_quoted: "Não sabes nada \\'João das Neves\\'",
127
+ ellipsis: "Não sabes nada João das Neves…",
128
+ ampersand: "Não sabes nada João das Neves &amp; Pícaros",
129
+ at_sign: "\\@johnsnow sabes alguma coisa?"
130
+ ) }
131
+
132
+ it_behaves_like "a localizer"
133
+ end
134
+
135
+ describe "of type Ruby on Rails" do
136
+ let(:type) { :ror }
137
+
138
+ let(:expected) { type_dependent_defaults }
139
+
140
+ it_behaves_like "a localizer"
141
+ end
142
+
143
+ describe "of an unkown type" do
144
+ let(:type) { :dunno }
145
+ it do
146
+ expect { localizer }.to raise_error /Unknown type/
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,36 @@
1
+ describe Bisu::Logger do
2
+ let(:summary) { Bisu::Logger.summary }
3
+ let(:info) { summary[:info] }
4
+ let(:warn) { summary[:warn] }
5
+ let(:error) { summary[:error] }
6
+
7
+ context "when logging to info" do
8
+ before { Bisu::Logger.info "msg" }
9
+
10
+ it "returns the expected totals" do
11
+ expect(info).to eq 1
12
+ expect(warn).to eq 0
13
+ expect(error).to eq 0
14
+ end
15
+ end
16
+
17
+ context "when logging to warn" do
18
+ before { Bisu::Logger.warn "msg" }
19
+
20
+ it "returns the expected totals" do
21
+ expect(info).to eq 0
22
+ expect(warn).to eq 1
23
+ expect(error).to eq 0
24
+ end
25
+ end
26
+
27
+ context "when logging to error" do
28
+ before { Bisu::Logger.error "msg" }
29
+
30
+ it "returns the expected totals" do
31
+ expect(info).to eq 0
32
+ expect(warn).to eq 0
33
+ expect(error).to eq 1
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,116 @@
1
+ require 'bisu'
2
+ require 'webmock/rspec'
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ config.before do
24
+ Bisu::Logger.silent_mode = true
25
+ end
26
+
27
+ config.after do
28
+ Bisu::Logger.clean_summary
29
+ end
30
+
31
+ RSpec::Matchers.define_negated_matcher :not_change, :change
32
+
33
+ # rspec-expectations config goes here. You can use an alternate
34
+ # assertion/expectation library such as wrong or the stdlib/minitest
35
+ # assertions if you prefer.
36
+ config.expect_with :rspec do |expectations|
37
+ # This option will default to `true` in RSpec 4. It makes the `description`
38
+ # and `failure_message` of custom matchers include text for helper methods
39
+ # defined using `chain`, e.g.:
40
+ # be_bigger_than(2).and_smaller_than(4).description
41
+ # # => "be bigger than 2 and smaller than 4"
42
+ # ...rather than:
43
+ # # => "be bigger than 2"
44
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
45
+ end
46
+
47
+ # rspec-mocks config goes here. You can use an alternate test double
48
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
49
+ config.mock_with :rspec do |mocks|
50
+ # Prevents you from mocking or stubbing a method that does not exist on
51
+ # a real object. This is generally recommended, and will default to
52
+ # `true` in RSpec 4.
53
+ mocks.verify_partial_doubles = true
54
+ end
55
+
56
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
57
+ # have no way to turn it off -- the option exists only for backwards
58
+ # compatibility in RSpec 3). It causes shared context metadata to be
59
+ # inherited by the metadata hash of host groups and examples, rather than
60
+ # triggering implicit auto-inclusion in groups with matching metadata.
61
+ config.shared_context_metadata_behavior = :apply_to_host_groups
62
+
63
+ # The settings below are suggested to provide a good initial experience
64
+ # with RSpec, but feel free to customize to your heart's content.
65
+ =begin
66
+ # This allows you to limit a spec run to individual examples or groups
67
+ # you care about by tagging them with `:focus` metadata. When nothing
68
+ # is tagged with `:focus`, all examples get run. RSpec also provides
69
+ # aliases for `it`, `describe`, and `context` that include `:focus`
70
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
71
+ config.filter_run_when_matching :focus
72
+
73
+ # Allows RSpec to persist some state between runs in order to support
74
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
75
+ # you configure your source control system to ignore this file.
76
+ config.example_status_persistence_file_path = "spec/examples.txt"
77
+
78
+ # Limits the available syntax to the non-monkey patched syntax that is
79
+ # recommended. For more details, see:
80
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
81
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
82
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
83
+ config.disable_monkey_patching!
84
+
85
+ # This setting enables warnings. It's recommended, but in some cases may
86
+ # be too noisy due to issues in dependencies.
87
+ config.warnings = true
88
+
89
+ # Many RSpec users commonly either run the entire suite or an individual
90
+ # file, and it's useful to allow more verbose output when running an
91
+ # individual spec file.
92
+ if config.files_to_run.one?
93
+ # Use the documentation formatter for detailed output,
94
+ # unless a formatter has already been configured
95
+ # (e.g. via a command-line flag).
96
+ config.default_formatter = 'doc'
97
+ end
98
+
99
+ # Print the 10 slowest examples and example groups at the
100
+ # end of the spec run, to help surface which specs are running
101
+ # particularly slow.
102
+ config.profile_examples = 10
103
+
104
+ # Run specs in random order to surface order dependencies. If you find an
105
+ # order dependency and want to debug it, you can fix the order by providing
106
+ # the seed, which is printed after each run.
107
+ # --seed 1234
108
+ config.order = :random
109
+
110
+ # Seed global randomization in this process using the `--seed` CLI option.
111
+ # Setting this allows you to use `--seed` to deterministically reproduce
112
+ # test failures related to randomization by passing the same `--seed` value
113
+ # as the one that triggered the failure.
114
+ Kernel.srand config.seed
115
+ =end
116
+ end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bisu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - joaoffcosta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-14 00:00:00.000000000 Z
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safe_yaml
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: colorize
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: xml-simple
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.20'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.20'
69
69
  description: Bisu manages your app iOS and Android localization files for you. No
@@ -74,6 +74,10 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - Gemfile
80
+ - Gemfile.lock
77
81
  - README.md
78
82
  - Rakefile
79
83
  - bin/bisu
@@ -81,18 +85,20 @@ files:
81
85
  - generic.translatable.yml
82
86
  - lib/bisu.rb
83
87
  - lib/bisu/config.rb
84
- - lib/bisu/knowledge_base.rb
88
+ - lib/bisu/dictionary.rb
89
+ - lib/bisu/google_sheet.rb
90
+ - lib/bisu/localizer.rb
85
91
  - lib/bisu/logger.rb
86
- - lib/bisu/translator.rb
87
92
  - lib/bisu/version.rb
88
- - test/support/sample_kb_public_info.html
89
- - test/support/sample_kb_public_sheet.html
90
- - test/support/sample_translatable.yml
91
- - test/test_bisu_config.rb
92
- - test/test_bisu_knowledge_base.rb
93
- - test/test_bisu_logger.rb
94
- - test/test_bisu_translator.rb
95
- - test/test_helper.rb
93
+ - spec/bisu/config_spec.rb
94
+ - spec/bisu/dictionary_spec.rb
95
+ - spec/bisu/google_sheet_spec.rb
96
+ - spec/bisu/localizer_spec.rb
97
+ - spec/bisu/logger_spec.rb
98
+ - spec/fixtures/sample_kb_public_info.html
99
+ - spec/fixtures/sample_kb_public_sheet.html
100
+ - spec/fixtures/sample_translatable.yml
101
+ - spec/spec_helper.rb
96
102
  homepage: https://github.com/hole19/bisu
97
103
  licenses:
98
104
  - MIT
@@ -103,17 +109,17 @@ require_paths:
103
109
  - lib
104
110
  required_ruby_version: !ruby/object:Gem::Requirement
105
111
  requirements:
106
- - - '>='
112
+ - - ">="
107
113
  - !ruby/object:Gem::Version
108
114
  version: '0'
109
115
  required_rubygems_version: !ruby/object:Gem::Requirement
110
116
  requirements:
111
- - - '>='
117
+ - - ">="
112
118
  - !ruby/object:Gem::Version
113
119
  version: '0'
114
120
  requirements: []
115
121
  rubyforge_project:
116
- rubygems_version: 2.0.14.1
122
+ rubygems_version: 2.5.1
117
123
  signing_key:
118
124
  specification_version: 4
119
125
  summary: A localization automation service