From 8b49f456c2311846f42cb618398bb7d938876770 Mon Sep 17 00:00:00 2001 From: Jesse Date: Wed, 7 Sep 2011 09:48:08 -0700 Subject: [PATCH] Fix custom error message for the "find a photo" - Added tests for this case --- lib/moneypenny/responders/image.rb | 2 +- spec/responders/image_spec.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/moneypenny/responders/image.rb b/lib/moneypenny/responders/image.rb index 1c4d90f..759fb59 100644 --- a/lib/moneypenny/responders/image.rb +++ b/lib/moneypenny/responders/image.rb @@ -18,7 +18,7 @@ def self.respond(message) when /^image me (.*)$/i image_response $1 when /^find\ (a|an)\ (.+)\ (image|picture|photo)$/i - image_response $2, "I couldn't find #{$1} #{$2} #{3}." + image_response $2, "I couldn't find #{$1} #{$2} #{$3}." else false end diff --git a/spec/responders/image_spec.rb b/spec/responders/image_spec.rb index 48d54dc..6de88f1 100644 --- a/spec/responders/image_spec.rb +++ b/spec/responders/image_spec.rb @@ -11,6 +11,8 @@ end describe 'respond' do + bad_search_term = ".................." + context 'given a message that it understands' do it "should respond to 'image me'" do Image.respond('image me cat').should match /^https?:\/\/\w/i @@ -18,8 +20,11 @@ it "should respond to 'find a something image'" do Image.respond('find a cat image').should match /^https?:\/\/\w/i end - it "should pass back the error message for a failed search" do - Image.respond("image me ..................").should match /I was unable to find/ + it "should pass back the default error message for a failed search" do + Image.respond("image me #{bad_search_term}").should match /I was unable to find/ + end + it "should pass back a custom error message for a failed search" do + Image.respond("find a #{bad_search_term} photo").should match Regexp.new("a[^n].*#{bad_search_term}.*photo") end end