Skip to content

Commit

Permalink
only match entire words
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian C. Anderson committed Dec 12, 2014
1 parent 99b686d commit 3a9306b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/girls_just_want_to_have_puns/punifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize original_phrase, word_to_replace, replacement_word
end

def pun
new_phrase = @original_phrase.text.sub(/\b#{@word_to_replace}/i, @replacement_word)
new_phrase = @original_phrase.text.sub(/\b#{@word_to_replace}\b/i, @replacement_word)
if new_phrase == @original_phrase.text
nil
else
Expand Down
14 changes: 14 additions & 0 deletions spec/girls_just_want_to_have_puns/pun_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@

expect(pun).to eq(nil)
end

it "doesn't match partial words" do
generator = described_class.new(
"cats",
minimum_word_count: 6,
rhymes: ["bat"],
source_phrases: [
Phrase.new("misc", "throw the baby out with the bath water")
]
)
pun = generator.puns.first

expect(pun).to eq(nil)
end
end

0 comments on commit 3a9306b

Please sign in to comment.