Skip to content

Commit

Permalink
Fix custom error message for the "find a <something> photo"
Browse files Browse the repository at this point in the history
- Added tests for this case
  • Loading branch information
Jesse committed Sep 7, 2011
1 parent a507c6f commit 8b49f45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/moneypenny/responders/image.rb
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions spec/responders/image_spec.rb
Expand Up @@ -11,15 +11,20 @@
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
end
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

Expand Down

0 comments on commit 8b49f45

Please sign in to comment.