Skip to content

Commit

Permalink
Reply when no images are found.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Aug 20, 2013
1 parent 86d7e4f commit 0ec4afb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/lita/handlers/google_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def fetch(response)

if data["responseStatus"] == 200
choice = data["responseData"]["results"].sample
response.reply "#{choice["unescapedUrl"]}#.png"
if choice
response.reply "#{choice["unescapedUrl"]}#.png"
else
response.reply %{No images found for "#{query}".}
end
else
reason = data["responseDetails"] || "unknown error"
Lita.logger.warn(
Expand Down
9 changes: 9 additions & 0 deletions spec/lita/handlers/google_images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
)
end

it "replies that no images were found if the results are empty" do
allow(response).to receive(:body).and_return(<<-JSON.chomp
{"responseStatus": 200, "responseData": { "results": [] } }
JSON
)
send_command("image carl")
expect(replies.last).to eq(%{No images found for "carl".})
end

it "logs a warning on failure" do
allow(response).to receive(:body).and_return(<<-JSON.chomp
{
Expand Down

0 comments on commit 0ec4afb

Please sign in to comment.