Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
scowalt committed Feb 26, 2012
2 parents e4f1cf9 + 9842bee commit 35418ec
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Rakefile
@@ -1 +1,2 @@
require 'cucumber/rake/task'
require 'cucumber/rake/task'

33 changes: 33 additions & 0 deletions features/step_definitions/text_mood_steps.rb
@@ -0,0 +1,33 @@
$:.push File.join(File.dirname(__FILE__),'..','..','lib')
begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
require 'twitter-sentiment/parser/text_mood'

Before do
@text_mood = nil
end

After do
end

Given /I start an instance initialized with '(.*)'/ do |file|
file = file[1..-1].to_sym if file[0] == ":" # convert to symbol from string if that's what's passed
begin
@text_mood = TwitterSentiment::Parser::TextMood.new(file)
rescue Exception => e
@text_mood = Exception.new
end
end

When /I ask the score of '(.*)'/ do |word|
@result = @text_mood.score word
end

Then /the score returned should be '(.*)'/ do |result|
result = result == 'nil' ? nil : result.to_f

@result.should == result
end

Then /an exception should be thrown/ do
@text_mood.is_a? Exception
end
22 changes: 22 additions & 0 deletions features/text_mood.feature
@@ -0,0 +1,22 @@
Feature: Text Mood Parsing
In order to make sure the dictionary bag-of-words with weightings is parsed without mistakes
I am going to pass in a known legal file and request it be parsed and report back a score

Scenario: Initializing with a symbol
Given I start an instance initialized with ':afinn'
When I ask the score of 'assfucking'
Then the score returned should be '-4'

Scenario: Initializing with a legit filepath string
Given I start an instance initialized with 'dict/AFINN-111.txt'
When I ask the score of 'assfucking'
Then the score returned should be '-4'

Scenario: Initialize with a nonexistent filepath string
Given I start an instance initialized with 'dict/thisnameshouldneverexist.diggisthebest.justkidding'
Then an exception should be thrown

Scenario: Initializing with a legit filepath string
Given I start an instance initialized with 'dict/AFINN-111.txt'
When I ask the score of 'darthvaderinaspeedo'
Then the score returned should be 'nil'
15 changes: 0 additions & 15 deletions features/text_mood_parse.feature

This file was deleted.

4 changes: 2 additions & 2 deletions lib/twitter-sentiment/parser/text_mood.rb
Expand Up @@ -19,14 +19,14 @@ class TextMood
def initialize file
case file
when Symbol
file = @@bags[file] # Convert from symbol to filepath if passed
file = File.join(@@bags_dir, @@bags[file]) # Convert from symbol to filepath if passed
when String
# Do nuttin', we already have a filepath
else
raise ArgumentError, "Expected String or Symbol input for file"
end
@dict = {}
generate_dictionary File.open(File.join(@@bags_dir, file), "r")
generate_dictionary File.open(file, "r")
end

# Generate Dictionary from file of proper syntax
Expand Down

0 comments on commit 35418ec

Please sign in to comment.