-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Panczo/master
Fix Encoding::CompatibilityError: incompatible encoding regexp match …
- Loading branch information
Showing
12 changed files
with
368 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ lib/bundler/man | |
pkg | ||
rdoc | ||
spec/reports | ||
spec/secrets.yml | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'spec_helper' | ||
require 'vcr' | ||
|
||
describe Yandex::Translator do | ||
let(:api_key) { 'secret' } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require 'spec_helper' | ||
require 'vcr' | ||
|
||
describe Yandex::Translator do | ||
let(:api_key) { RSpec.configuration.yandex_api_key } | ||
subject(:translator) { Yandex::Translator.new(api_key) } | ||
|
||
describe '::translate' do | ||
before do | ||
expect_any_instance_of(Yandex::Translator).to receive(:translate) | ||
Yandex::Translator.api_key = api_key | ||
end | ||
end | ||
|
||
describe '#translate' do | ||
it 'returns ru translalation ' do | ||
VCR.use_cassette('get_translated_ru_text') do | ||
response = translator.translate('Car', 'ru') | ||
expect(response).to eq("Автомобиль") | ||
end | ||
end | ||
|
||
it 'returns pl translalation' do | ||
VCR.use_cassette('get_translated_pl_text') do | ||
response = translator.translate('Car', 'pl') | ||
expect(response).to eq("Samochód") | ||
end | ||
end | ||
|
||
it 'accepts options' do | ||
VCR.use_cassette('accepts options') do | ||
response = translator.translate('Car', from: :ru) | ||
expect(response).to eq("Автомобиль") | ||
end | ||
end | ||
|
||
context 'with two languages' do | ||
it 'accepts options' do | ||
VCR.use_cassette('accepts options') do | ||
response = translator.translate('Samochód', from: :pl, to: :ru) | ||
expect(response).to eq("Автомобиль") | ||
end | ||
end | ||
|
||
it 'accepts languages list' do | ||
VCR.use_cassette('accepts options') do | ||
response = translator.translate('Car', :ru, :en) | ||
expect(response).to eq("Автомобиль") | ||
end | ||
end | ||
end | ||
|
||
context 'with wrong api key' do | ||
let(:wrong_translator) { Yandex::Translator.new('wrong_api_key') } | ||
|
||
it 'returns translation error' do | ||
expect{ | ||
VCR.use_cassette('wrong_api_key') do | ||
wrong_translator.translate('Car', :ru, :en) | ||
end | ||
}.to raise_error(Yandex::ApiError, "API key is invalid") | ||
end | ||
end | ||
end | ||
|
||
describe '#detect' do | ||
let(:detected_translation) { | ||
VCR.use_cassette('#detect') do | ||
translator.detect('Car') | ||
end | ||
} | ||
|
||
it 'returns detected language' do | ||
expect(detected_translation).to eq 'en' | ||
end | ||
end | ||
|
||
describe '#langs' do | ||
let(:list_of_langs) { | ||
VCR.use_cassette('#langs') do | ||
translator.langs | ||
end | ||
} | ||
|
||
it 'returns array of dirs' do | ||
expect(list_of_langs).to include 'en-ru', 'uk-pl', 'pl-ru' | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
require 'rspec' | ||
require 'yandex-translator' | ||
require 'webmock/rspec' | ||
include WebMock | ||
require 'vcr' | ||
include WebMock::API | ||
|
||
RSpec.configure do |config| | ||
if File.exists? ('spec/secrets.yml') | ||
YANDEX_API_KEY = YAML.load_file('spec/secrets.yml') | ||
else | ||
YANDEX_API_KEY = {} | ||
end | ||
config.add_setting :yandex_api_key, :default => YANDEX_API_KEY['yandex_translator_api_key'] | ||
end | ||
|
||
VCR.configure do |c| | ||
c.cassette_library_dir = 'spec/vcr' | ||
c.hook_into :webmock | ||
c.filter_sensitive_data('<YANDEX_API_KEY>') { RSpec.configuration.yandex_api_key } | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.