yandex_translator 0.1.1 → 0.1.3
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.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/yandex_translator/version.rb +1 -1
- data/spec/lib/yandex_translator_spec.rb +64 -0
- data/spec/spec_helper.rb +8 -0
- data/yandex_translator.gemspec +2 -3
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d78323fc2a4422c5ae6b89fe175b47890457b9
|
4
|
+
data.tar.gz: daa56154caf446345445aaa234e77e0a70aa9f0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 350f1a21dc843fd96b3317a731908e2424928e0e6b3c77bef7f24f00d530d79bf830d63b4144c293dd3ccfc3aad640ff1faec1e574f1e5b56d8b8c6f6725b24c
|
7
|
+
data.tar.gz: 1fded56b2058136f84c084a86456c62b88d89a7166cc4ffa562f8ecd87cc5d1daf466efab6717fdfea24a3df904cc596d7822872202a9ad3d9ae65f8ad5f9d79
|
data/Rakefile
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe YandexTranslator::Translator do
|
4
|
+
let(:key) { 'api_key' }
|
5
|
+
subject(:translator) { YandexTranslator::Translator.new(key) }
|
6
|
+
|
7
|
+
it 'should exists' do
|
8
|
+
YandexTranslator::Translator.new(key)
|
9
|
+
end
|
10
|
+
|
11
|
+
# it 'returns YandexError for invalid key' do
|
12
|
+
# expect{YandexTranslator::Translator.new(key)}.to raise_error(YandexTranslator::YandexError)
|
13
|
+
# end
|
14
|
+
|
15
|
+
describe '#translate' do
|
16
|
+
let(:translate_url) { "https://translate.yandex.net/api/v1.5/tr.json/translate?key=#{key}&text=Car&lang=ru" }
|
17
|
+
let(:translate_response_body) { '{"code":200, "lang": "en-ru", "text": ["Автомобиль"]}' }
|
18
|
+
let!(:translate_request) do
|
19
|
+
stub_request(:get, translate_url)
|
20
|
+
.to_return(
|
21
|
+
body: translate_response_body,
|
22
|
+
headers: {'Content-Type' => 'application/json'}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns translalation' do
|
27
|
+
expect(translator.translate('Car', 'ru')).to eq ['Автомобиль']
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when server responds with invalid "lang" parameter error' do
|
31
|
+
let(:translate_request_body) { "text=Car&lang=ru-ru&key=#{key}" }
|
32
|
+
let(:translate_url) {"https://translate.yandex.net/api/v1.5/tr.json/translate?key=#{key}&text=Car&lang=ri"}
|
33
|
+
let(:translate_response_body) { '{"code":501,"message":"The specified translation direction is not supported"}' }
|
34
|
+
let!(:translate_request) do
|
35
|
+
stub_request(:get, translate_url)
|
36
|
+
.to_return(
|
37
|
+
body: translate_response_body,
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns translation error' do
|
42
|
+
expect{
|
43
|
+
translator.translate('Car', 'ri')
|
44
|
+
}.to raise_error(YandexTranslator::YandexError, "The specified translation direction is not supported")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#lang_detect' do
|
50
|
+
let(:detect_url) { "https://translate.yandex.net/api/v1.5/tr.json/detect?key=#{key}&text=Car" }
|
51
|
+
let(:detect_response_body) { '{"code": 200, "lang": "en"}' }
|
52
|
+
let!(:detect_request) do
|
53
|
+
stub_request(:get, detect_url)
|
54
|
+
.to_return(
|
55
|
+
body: detect_response_body,
|
56
|
+
headers: { 'Content-Type' => 'application/json' }
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns detected language' do
|
61
|
+
expect(translator.lang_detect('Car')).to eq 'en'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/yandex_translator.gemspec
CHANGED
@@ -11,11 +11,10 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.date = '2017-05-14'
|
12
12
|
spec.summary = "A library for translating text using Yandex Translate API"
|
13
13
|
spec.license = "MIT"
|
14
|
-
spec.files = `git ls-files -z`.split("\x0")
|
15
|
-
f.match(%r{^(test|spec|features)/})
|
16
|
-
end
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
15
|
spec.bindir = "exe"
|
18
16
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
20
|
spec.add_development_dependency "bundler", "~> 1.14"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex_translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kozlov_Evgeny
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- lib/yandex_translator.rb
|
82
82
|
- lib/yandex_translator/version.rb
|
83
|
+
- spec/lib/yandex_translator_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
83
85
|
- yandex_translator.gemspec
|
84
86
|
homepage:
|
85
87
|
licenses:
|
@@ -105,4 +107,6 @@ rubygems_version: 2.5.2
|
|
105
107
|
signing_key:
|
106
108
|
specification_version: 4
|
107
109
|
summary: A library for translating text using Yandex Translate API
|
108
|
-
test_files:
|
110
|
+
test_files:
|
111
|
+
- spec/lib/yandex_translator_spec.rb
|
112
|
+
- spec/spec_helper.rb
|