diff options
| author | mo k <mo@mokhan.ca> | 2012-05-23 21:22:51 -0600 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-05-23 21:22:51 -0600 |
| commit | b34061bec51cb12e7f6d38bcbd2a112578658917 (patch) | |
| tree | de49b760e8e09b025de4113154d2132697bc61df | |
| parent | 27e7e55f0a14b83a2eb4be4e5bd178e4da9bd95a (diff) | |
add quotes around search term.
| -rw-r--r-- | app/services/rock_score.rb | 4 | ||||
| -rw-r--r-- | spec/services/rock_score_spec.rb | 16 |
2 files changed, 10 insertions, 10 deletions
diff --git a/app/services/rock_score.rb b/app/services/rock_score.rb index 060e9b4..9ad70d7 100644 --- a/app/services/rock_score.rb +++ b/app/services/rock_score.rb @@ -1,8 +1,8 @@ class RockScore NoScore = Class.new def self.for_term(term) - positive = SearchEngine.count_results("#{term} rocks").to_f - negative = SearchEngine.count_results("#{term} sucks").to_f + positive = SearchEngine.count_results(%{"#{term} rocks"}).to_f + negative = SearchEngine.count_results(%{"#{term} sucks"}).to_f score = 10 * (positive / (positive + negative)) score.nan? ? NoScore : score end diff --git a/spec/services/rock_score_spec.rb b/spec/services/rock_score_spec.rb index b83a6f2..4a38d52 100644 --- a/spec/services/rock_score_spec.rb +++ b/spec/services/rock_score_spec.rb @@ -3,23 +3,23 @@ require_relative '../../app/services/search_engine' describe RockScore do it "returns 0 for unpopular terms" do - SearchEngine.stub(:count_results).with("apple rocks") { 0 } - SearchEngine.stub(:count_results).with("apple sucks") { 1 } + SearchEngine.stub(:count_results).with(%{"apple rocks"}) { 0 } + SearchEngine.stub(:count_results).with(%{"apple sucks"}) { 1 } RockScore.for_term("apple").should == 0.0 end it "returns 10 for popular terms" do - SearchEngine.stub(:count_results).with("apple rocks") { 1 } - SearchEngine.stub(:count_results).with("apple sucks") { 0 } + SearchEngine.stub(:count_results).with(%{"apple rocks"}) { 1 } + SearchEngine.stub(:count_results).with(%{"apple sucks"}) { 0 } RockScore.for_term("apple").should == 10.0 end it "returns mediocore results for mediocre terms" do - SearchEngine.stub(:count_results).with("apple rocks") { 9 } - SearchEngine.stub(:count_results).with("apple sucks") { 11 } + SearchEngine.stub(:count_results).with(%{"apple rocks"}) { 9 } + SearchEngine.stub(:count_results).with(%{"apple sucks"}) { 11 } RockScore.for_term("apple").should == 4.5 end it "does not divide by zero" do - SearchEngine.stub(:count_results).with("apple rocks") { 0 } - SearchEngine.stub(:count_results).with("apple sucks") { 0 } + SearchEngine.stub(:count_results).with(%{"apple rocks"}) { 0 } + SearchEngine.stub(:count_results).with(%{"apple sucks"}) { 0 } RockScore.for_term("apple").should == RockScore::NoScore end end |
