Permalink
Browse files

first cucumber tests, all pass. NOTE: you need both rspec and cucumbe…

…r gems (it uses rspec "should" and whatnot)
  • Loading branch information...
1 parent f4ad1f1 commit 9842bee45c76c0d06113aac2755029971c9f4ce0 Jake McGinty committed Feb 26, 2012
View
@@ -1 +1,2 @@
-require 'cucumber/rake/task'
+require 'cucumber/rake/task'
+
@@ -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
View
@@ -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'
@@ -1,15 +0,0 @@
-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 TextMood is loaded successfully
- When I start an instance initialized with ':afinn'
- And I ask the score of 'assfucking'
- Then the score returned should be '-4'
-
- Scenario: Initializing with a string
- Given TextMood is loaded successfully
- When I start an instance initialized with 'dict/AFINN-111.txt'
- And I ask the score of 'assfucking'
- Then the score returned should be '-4'
@@ -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

0 comments on commit 9842bee

Please sign in to comment.