Skip to content

Commit

Permalink
Added Redis dependency in Gemfile. Start and stop Redis instance in R…
Browse files Browse the repository at this point in the history
…akefile for test. Simple integration test to demonstrate loading and query.
  • Loading branch information
David Czarnecki committed Feb 15, 2011
1 parent b497420 commit a596eb5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -11,3 +11,5 @@ group :development do
gem "jeweler", "~> 1.5.2"
gem "rcov", ">= 0"
end

gem 'redis', "~> 2.1.1"
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -8,6 +8,7 @@ GEM
rake
rake (0.8.7)
rcov (0.9.9)
redis (2.1.1)
shoulda (2.11.3)

PLATFORMS
Expand All @@ -17,4 +18,5 @@ DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.2)
rcov
redis (~> 2.1.1)
shoulda
40 changes: 38 additions & 2 deletions Rakefile
Expand Up @@ -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') : ""
Expand All @@ -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
Empty file added test/db/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions 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"}}
8 changes: 8 additions & 0 deletions 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
16 changes: 14 additions & 2 deletions 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.