Permalink
Browse files

split stub_response spec helper method into two for success and errors

  • Loading branch information...
1 parent cc6b74a commit 38826d544232af4ab6ffdb034e0ca02f3c824fc3 @jimmycuadra jimmycuadra committed Dec 25, 2010
Showing with 14 additions and 5 deletions.
  1. +14 −5 spec/to_lang/connector_spec.rb
@@ -10,30 +10,39 @@
end
context "when sent :request" do
- def stub_response(response_text)
- parsed_response = { "data" => { "translations" => [ { "translatedText" => response_text } ] } }
+ def stub_response(parsed_response)
mock_response = mock('HTTParty::Response', :parsed_response => parsed_response)
HTTParty.stub(:get).and_return(mock_response)
end
+ def stub_good_response(translated_text)
+ parsed_response = { "data" => { "translations" => [ { "translatedText" => translated_text } ] } }
+ stub_response(parsed_response)
+ end
+
+ def stub_bad_response(error_message)
+ parsed_response = { "error" => { "message" => error_message } }
+ stub_response(parsed_response)
+ end
+
context "with only a target language" do
it "returns the translated string" do
- stub_response "hola mundo"
+ stub_good_response "hola mundo"
@connector.request("hello world", "es").should == "hola mundo"
end
end
context "with an ambiguous source language" do
context "and no source language specified" do
it "returns the same string" do
- stub_response "a pie"
+ stub_good_response "a pie"
@connector.request("a pie", "es").should == "a pie"
end
end
context "and a source language specified" do
it "returns the translated string" do
- stub_response "un pastel"
+ stub_good_response "un pastel"
@connector.request("a pie", "es", :from => "en").should == "un pastel"
end
end

0 comments on commit 38826d5

Please sign in to comment.