Permalink
Browse files

add failing specs for magic methods, add hash to map languages to lan…

…guage codes
  • Loading branch information...
1 parent dc008a8 commit d08f68d82cf858188290b3fc8905c73e5e564f15 @jimmycuadra jimmycuadra committed Dec 26, 2010
Showing with 71 additions and 1 deletion.
  1. +1 −0 lib/to_lang.rb
  2. +57 −0 lib/to_lang/codemap.rb
  3. +13 −1 spec/to_lang_spec.rb
View
@@ -1,3 +1,4 @@
+require File.expand_path("../to_lang/codemap", __FILE__)
require File.expand_path("../to_lang/connector", __FILE__)
module ToLang
View
@@ -0,0 +1,57 @@
+module ToLang
+ CODEMAP = {
+ 'afrikaans' => 'af',
+ 'albanian' => 'sq',
+ 'arabic' => 'ar',
+ 'basque' => 'eu',
+ 'belarusian' => 'be',
+ 'bulgarian' => 'bg',
+ 'catalan' => 'ca',
+ 'simplified_chinese' => 'zh-CN',
+ 'traditional_chinese' => 'zh-TW',
+ 'croatian' => 'hr',
+ 'czech' => 'cs',
+ 'danish' => 'da',
+ 'dutch' => 'nl',
+ 'english' => 'en',
+ 'estonian' => 'et',
+ 'filipino' => 'tl',
+ 'finnish' => 'fi',
+ 'french' => 'fr',
+ 'galician' => 'gl',
+ 'german' => 'de',
+ 'greek' => 'el',
+ 'haitian_creole' => 'ht',
+ 'hebrew' => 'iw',
+ 'hindi' => 'hi',
+ 'hungarian' => 'hu',
+ 'icelandic' => 'is',
+ 'indonesian' => 'id',
+ 'irish' => 'ga',
+ 'italian' => 'it',
+ 'japanese' => 'ja',
+ 'latvian' => 'lv',
+ 'lithuanian' => 'lt',
+ 'macedonian' => 'mk',
+ 'malay' => 'ms',
+ 'maltese' => 'mt',
+ 'norwegian' => 'no',
+ 'persian' => 'fa',
+ 'polish' => 'pl',
+ 'portuguese' => 'pt',
+ 'romanian' => 'ro',
+ 'russian' => 'ru',
+ 'serbian' => 'sr',
+ 'slovak' => 'sk',
+ 'slovenian' => 'sl',
+ 'spanish' => 'es',
+ 'swahili' => 'sw',
+ 'swedish' => 'sv',
+ 'thai' => 'th',
+ 'turkish' => 'tr',
+ 'ukrainian' => 'uk',
+ 'vietnamese' => 'vi',
+ 'welsh' => 'cy',
+ 'yiddish' => 'yi',
+ }
+end
View
@@ -16,7 +16,7 @@
end
end
-describe "An instance of String" do
+describe "A string" do
context "after ToLang has received :start" do
before :all do
ToLang.start('apikey')
@@ -33,5 +33,17 @@
"hello world".translate("es")
end
end
+
+ ToLang::CODEMAP.each do |language, code|
+ it "translates to #{language} when sent :to_#{language}" do
+ ToLang.connector.stub(:request)
+ ToLang.connector.should_receive(:request).with("hello world", code)
+ "hello world".send("to_#{language}")
+ end
+
+ it "will then respond_to? :to_#{language}" do
+ "hello_world".should respond_to "to_#{language}"
+ end
+ end
end
end

0 comments on commit d08f68d

Please sign in to comment.