Sha256: 587e2560709cdef718fdaafd37c3d0480bd2e9bffa2680d795350a07cc356d2f
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
require "./test/tests_helper" require "nele" describe "MsTranslator" do def setup String.translator = :ms String.translator.config[:url] = "http://example.com/" String.translator.config[:appId] = "abc" String.translator.config[:to] = "pl" String.translator.config[:from] = "en" end def subject String.translator end describe("#build_uri") do it("builds proper uri") do str = "hello" expected_url = "http://example.com/?appId=abc&text=hello&from=en&to=pl" subject.build_uri(str).must_equal expected_url end end describe("#build_request") do it("invokes /parse_uri/ method") do str = "hello" subject.expects(:parse_uri).with(subject.build_uri(str)).once subject.build_request(str) end end describe("when there are no errors from the ms api") do it("returns translated string") do subject.stubs(:connect).returns ms_response "hello world".translate.must_equal "powitania" end end describe("when api returns errors") do it("returns hash with api errors") do subject.stubs(:connect).returns ms_response_with_error lambda { "hello world".translate }.must_raise(Nele::TranslatorAPIError) end end describe("when there is connection error") do it("invokes /handle_connection/ on rescue") do subject.config[:url] = "invalid_url" lambda { subject.connect }.must_raise(Nele::ConnectionError) end end def ms_response "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">powitania</string>" end def ms_response_with_error "<html><body><h1>Argument Exception</h1><p>Method: Translate()</p><p>Parameter: appId</p><p>Message: Invalid appId</p><code></code></body></html>" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nele-0.2.2 | test/ms_translator_test.rb |