Skip to content
Browse files

Added Redis dependency in Gemfile. Start and stop Redis instance in R…

…akefile for test. Simple integration test to demonstrate loading and query.
  • Loading branch information...
1 parent b497420 commit a596eb5b45738bfad5ec8228c8c2c53220aec12d @czarneckid czarneckid committed Feb 15, 2011
Showing with 69 additions and 4 deletions.
  1. +2 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +38 −2 Rakefile
  4. 0 test/db/.gitkeep
  5. +5 −0 test/samples/venues.json
  6. +8 −0 test/test.conf
  7. +14 −2 test/test_soulmate.rb
View
2 Gemfile
@@ -11,3 +11,5 @@ group :development do
gem "jeweler", "~> 1.5.2"
gem "rcov", ">= 0"
end
+
+gem 'redis', "~> 2.1.1"
View
2 Gemfile.lock
@@ -8,6 +8,7 @@ GEM
rake
rake (0.8.7)
rcov (0.9.9)
+ redis (2.1.1)
shoulda (2.11.3)
PLATFORMS
@@ -17,4 +18,5 @@ DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.2)
rcov
+ redis (~> 2.1.1)
shoulda
View
40 Rakefile
@@ -45,8 +45,6 @@ Rcov::RcovTask.new do |test|
test.verbose = true
end
-task :default => :test
-
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
@@ -56,3 +54,41 @@ Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
+
+REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
+REDIS_CNF = File.join(REDIS_DIR, "test.conf")
+REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")
+REDIS_LOCATION = ENV['REDIS_LOCATION']
+
+task :default => :run
+
+desc "Run tests and manage server start/stop"
+task :run => [:start, :test, :stop]
+
+desc "Run rcov and manage server start/stop"
+task :rcoverage => [:start, :rcov, :stop]
+
+desc "Start the Redis server"
+task :start do
+ redis_running = \
+ begin
+ File.exists?(REDIS_PID) && Process.kill(0, File.read(REDIS_PID).to_i)
+ rescue Errno::ESRCH
+ FileUtils.rm REDIS_PID
+ false
+ end
+
+ if REDIS_LOCATION
+ system "#{REDIS_LOCATION}/redis-server #{REDIS_CNF}" unless redis_running
+ else
+ system "redis-server #{REDIS_CNF}" unless redis_running
+ end
+end
+
+desc "Stop the Redis server"
+task :stop do
+ if File.exists?(REDIS_PID)
+ Process.kill "INT", File.read(REDIS_PID).to_i
+ FileUtils.rm REDIS_PID
+ end
+end
View
0 test/db/.gitkeep
No changes.
View
5 test/samples/venues.json
@@ -0,0 +1,5 @@
+{"id":1,"term":"Dodger Stadium","score":85,"data":{"url":"\/dodger-stadium-tickets\/","subtitle":"Los Angeles, CA"}}
+{"id":28,"term":"Angel Stadium","score":85,"data":{"url":"\/angel-stadium-tickets\/","subtitle":"Anaheim, CA"}}
+{"id":30,"term":"Chase Field ","score":85,"data":{"url":"\/chase-field-tickets\/","subtitle":"Phoenix, AZ"}}
+{"id":29,"term":"Sun Life Stadium","score":84,"data":{"url":"\/sun-life-stadium-tickets\/","subtitle":"Miami, FL"}}
+{"id":2,"term":"Turner Field","score":83,"data":{"url":"\/turner-field-tickets\/","subtitle":"Atlanta, GA"}}
View
8 test/test.conf
@@ -0,0 +1,8 @@
+dir ./test/db
+pidfile ./redis.pid
+port 6379
+timeout 300
+loglevel debug
+logfile stdout
+databases 16
+daemonize yes
View
16 test/test_soulmate.rb
@@ -1,7 +1,19 @@
require 'helper'
class TestSoulmate < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
+ def test_integration_can_load_values_and_query
+ items = []
+ venues = File.open(File.expand_path(File.dirname(__FILE__)) + '/samples/venues.json', "r")
+ venues.each_line do |venue|
+ items << JSON.parse(venue)
+ end
+
+ Soulmate::Loader.new('venues').load(items)
+
+ matcher = Soulmate::Matcher.new('venues')
+ results = matcher.matches_for_term('stad', :limit => 5)
+
+ assert_equal 3, results.size
+ assert_equal 'Angel Stadium', results[0]['term']
end
end

0 comments on commit a596eb5

Please sign in to comment.
Something went wrong with that request. Please try again.