Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switched test to minitest.

  • Loading branch information...
commit acab4e3a79438075eb59e0eac0997684f85ae4ca 1 parent 67fc9d7
@shanna authored
View
6 Gemfile
@@ -1,11 +1,11 @@
# vim: syntax=ruby
+# gem install bundler08
bundle_path 'gems'
disable_rubygems
disable_system_gems
-gem 'dm-core', '~> 0.10.2'
+gem 'dm-core', '~> 0.10.3', :git => 'git://github.com/datamapper/dm-core.git'
gem 'riddle', '~> 1.0.9'
gem 'nokogiri', :only => :xmlpipe2
-gem 'shoulda', :only => :development
-
+gem 'ansi', :only => :development
View
12 Rakefile
@@ -1,6 +1,4 @@
-require 'rubygems'
require 'rake'
-require 'rake/testtask'
begin
require 'jeweler'
@@ -11,7 +9,7 @@ begin
gem.homepage = "http://github.com/shanna/dm-sphinx-adapter"
gem.authors = ["Shane Hanna"]
gem.executables = [] # Only ever bundled development executables in bin/*
- gem.add_dependency 'dm-core', ['~> 0.10.2']
+ gem.add_dependency 'dm-core', ['~> 0.10.3']
gem.add_dependency 'riddle', ['~> 1.0.9']
gem.files.reject!{|f| f=~ %r{test/files/tmp/.*}}
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
@@ -20,10 +18,10 @@ rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
-Rake::TestTask.new(:test) do |test|
- test.libs << 'lib' << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
+desc 'Run tests.'
+task :test do
+ Dir.glob(File.join(File.dirname(__FILE__), 'test', '**', 'test_*.rb')){|file| require file}
+ MiniTest::Unit.autorun
end
task :default => :test
View
13 dm-sphinx-adapter.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Shane Hanna"]
- s.date = %q{2010-02-11}
+ s.date = %q{2010-05-18}
s.email = %q{shane.hanna@gmail.com}
s.extra_rdoc_files = [
"README.rdoc"
@@ -27,7 +27,6 @@ Gem::Specification.new do |s|
"lib/dm-sphinx-adapter/connection.rb",
"lib/dm-sphinx-adapter/query.rb",
"lib/dm-sphinx-adapter/query/conditions.rb",
- "lib/dm-sphinx-adapter/query_factory.rb",
"lib/dm-sphinx-adapter/search.rb",
"lib/dm-sphinx-adapter/search/extended2.rb",
"lib/dm-sphinx-adapter/search/filter.rb",
@@ -38,6 +37,7 @@ Gem::Specification.new do |s|
"test/files/sphinx.conf",
"test/files/test_xmlpipe2.xml",
"test/helper.rb",
+ "test/lib/minitest/pretty.rb",
"test/test_adapter.rb",
"test/test_search_extended2.rb",
"test/test_search_filter.rb"
@@ -45,13 +45,14 @@ Gem::Specification.new do |s|
s.homepage = %q{http://github.com/shanna/dm-sphinx-adapter}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.5}
+ s.rubygems_version = %q{1.3.6}
s.summary = %q{A DataMapper Sphinx adapter.}
s.test_files = [
"test/test_search_filter.rb",
"test/test_search_extended2.rb",
"test/test_adapter.rb",
"test/files/model.rb",
+ "test/lib/minitest/pretty.rb",
"test/helper.rb"
]
@@ -60,14 +61,14 @@ Gem::Specification.new do |s|
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<dm-core>, ["~> 0.10.2"])
+ s.add_runtime_dependency(%q<dm-core>, ["~> 0.10.3"])
s.add_runtime_dependency(%q<riddle>, ["~> 1.0.9"])
else
- s.add_dependency(%q<dm-core>, ["~> 0.10.2"])
+ s.add_dependency(%q<dm-core>, ["~> 0.10.3"])
s.add_dependency(%q<riddle>, ["~> 1.0.9"])
end
else
- s.add_dependency(%q<dm-core>, ["~> 0.10.2"])
+ s.add_dependency(%q<dm-core>, ["~> 0.10.3"])
s.add_dependency(%q<riddle>, ["~> 1.0.9"])
end
end
View
1  lib/dm-sphinx-adapter.rb
@@ -2,7 +2,6 @@
require 'dm-sphinx-adapter/connection'
# The adapter propper.
-require 'dm-sphinx-adapter/query_factory'
require 'dm-sphinx-adapter/query'
require 'dm-sphinx-adapter/query/conditions'
require 'dm-sphinx-adapter/search'
View
6 lib/dm-sphinx-adapter/adapter.rb
@@ -37,6 +37,12 @@ def read(query)
end
end
+ # ==== Returns
+ # DataMapper::Sphinx::Query
+ def new_query *args
+ Query.new(*args)
+ end
+
protected
def with_connection
begin
View
36 lib/dm-sphinx-adapter/query_factory.rb
@@ -1,36 +0,0 @@
-#--
-# TODO: Ask about this monkey patch or alternatively I was thinking repository.create_query(*args) which would in turn
-# call the same method on the adapter. The command stuff in data objects works the same way so I don't see a good
-# argument against it other than the extra dispatch would be slightly slower.
-module DataMapper
- class Query
- extend Chainable
-
- chainable do
- def self.new(*args, &block)
- super
- end
- end
- end # Query
-end # DataMapper
-
-# Hijack the DataMapper::Query constructor allowing us to return a subclassed sphinx query object.
-module DataMapper
- module Sphinx
- module QueryFactory
-
- def new(repository, *args)
- if repository.adapter.is_a?(Sphinx::Adapter) && self == DataMapper::Query
- Sphinx::Query.new(repository, *args)
- else
- super
- end
- end
- end # QueryFactory
- end # Sphinx
-
- class Query
- extend Sphinx::QueryFactory
- end
-end # DataMapper
-
View
29 test/helper.rb
@@ -1,22 +1,19 @@
root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
files = File.join(root, 'test', 'files')
-at_exit do
- system("searchd -c #{files}/sphinx.conf --stop")
-end
+#at_exit do
+# system("searchd -c #{files}/sphinx.conf --stop")
+#end
require File.join(root, 'gems', 'environment')
Bundler.require_env(:development)
-require 'test/unit'
-begin
- require 'shoulda'
-rescue LoadError
- warn 'Shoulda is required for testing. Use gem bundle to install development gems.'
- exit 1
-end
+require 'minitest/unit'
+require 'minitest/spec'
+require File.join(root, 'test/lib/minitest/pretty')
$:.unshift File.join(root, 'lib')
+require 'extlib/blank' # Just to get up and running.
require 'dm-sphinx-adapter'
# Sphinx runner.
@@ -36,15 +33,11 @@
# DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, :adapter => 'sphinx')
-class Test::Unit::TestCase
+# Use DM shared spec model cleanup code.
+require 'dm-core/spec/lib/spec_helper'
+class MiniTest::Unit::TestCase
def teardown
- descendants = DataMapper::Model.descendants.dup.to_a
- while model = descendants.shift
- next unless Object.const_defined?(model.name.to_sym)
- descendants.concat(model.descendants) if model.respond_to?(:descendants)
- Object.send(:remove_const, model.name.to_sym)
- DataMapper::Model.descendants.delete(model)
- end
+ ::DataMapper::Spec.cleanup_models
end
end
View
153 test/lib/minitest/pretty.rb
@@ -0,0 +1,153 @@
+require 'minitest/unit'
+require 'minitest/spec'
+require 'ansi'
+
+class MiniTest::Unit
+ include ANSI::Code
+
+ PADDING_SIZE = 4
+
+ def run(args = [])
+ @verbose = true
+
+ filter = if args.first =~ /^(-n|--name)$/ then
+ args.shift
+ arg = args.shift
+ arg =~ /\/(.*)\// ? Regexp.new($1) : arg
+ else
+ /./ # anything - ^test_ already filtered by #tests
+ end
+
+ @@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"
+
+ start = Time.now
+ run_test_suites filter
+
+ @@out.puts
+ @@out.puts "Finished in #{'%.6f' % (Time.now - start)} seconds."
+
+ @@out.puts
+
+ @@out.print "%d tests, " % test_count
+ @@out.print "%d assertions, " % assertion_count
+ @@out.print red { "%d failures, " % failures }
+ @@out.print yellow { "%d errors, " % errors }
+ @@out.puts cyan { "%d skips" % skips}
+
+ return failures + errors if @test_count > 0 # or return nil...
+ end
+
+ # Overwrite #run_test_suites so that it prints out reports
+ # as errors are generated.
+ def run_test_suites(filter = /./)
+ @test_count, @assertion_count = 0, 0
+ old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync=
+ TestCase.test_suites.each do |suite|
+ test_cases = suite.test_methods.grep(filter)
+ if test_cases.size > 0
+ @@out.print "\n#{suite}:\n"
+ end
+
+ test_cases.each do |test|
+ inst = suite.new test
+ inst._assertions = 0
+
+ t = Time.now
+
+ @broken = nil
+
+ @@out.print(case inst.run(self)
+ when :pass
+ @broken = false
+ green { pad_with_size "PASS" }
+ when :error
+ @broken = true
+ yellow { pad_with_size "ERROR" }
+ when :fail
+ @broken = true
+ red { pad_with_size "FAIL" }
+ when :skip
+ @broken = false
+ cyan { pad_with_size "SKIP" }
+ end)
+
+
+ @@out.print " #{test}"
+ @@out.print " (%.2fs) " % (Time.now - t)
+
+ if @broken
+ @@out.puts
+
+ report = @report.last
+ @@out.puts pad(report[:message], 10)
+ trace = MiniTest::filter_backtrace(report[:exception].backtrace).first
+ @@out.print pad(trace, 10)
+
+ @@out.puts
+ end
+
+ @@out.puts
+ @test_count += 1
+ @assertion_count += inst._assertions
+ end
+ end
+ @@out.sync = old_sync if @@out.respond_to? :sync=
+ [@test_count, @assertion_count]
+ end
+
+ def pad(str, size=PADDING_SIZE)
+ " " * size + str
+ end
+
+ def pad_with_size(str)
+ pad("%5s" % str)
+ end
+
+ # Overwrite #puke method so that is stores a hash
+ # with :message and :exception keys.
+ def puke(klass, meth, e)
+ result = nil
+ msg = case e
+ when MiniTest::Skip
+ @skips += 1
+ result = :skip
+ e.message
+ when MiniTest::Assertion
+ @failures += 1
+ result = :fail
+ e.message
+ else
+ @errors += 1
+ result = :error
+ "#{e.class}: #{e.message}\n"
+ end
+
+ @report << {:message => msg, :exception => e}
+ result
+ end
+
+
+ class TestCase
+ # Overwrite #run method so that is uses symbols
+ # as return values rather than characters.
+ def run(runner)
+ result = :pass
+ begin
+ @passed = nil
+ self.setup
+ self.__send__ self.name
+ @passed = true
+ rescue Exception => e
+ @passed = false
+ result = runner.puke(self.class, self.name, e)
+ ensure
+ begin
+ self.teardown
+ rescue Exception => e
+ result = runner.puke(self.class, self.name, e)
+ end
+ end
+ result
+ end
+ end # TestCase
+end # MiniTest::Unit
View
38 test/test_adapter.rb
@@ -1,30 +1,20 @@
require File.join(File.dirname(__FILE__), 'helper')
-class AdapterTest < Test::Unit::TestCase
- context 'Adapter' do
- setup do
- class ::Item
- include DataMapper::Resource
- property :id, Serial
- property :t_string, String
- property :t_text, Text, :lazy => false
- end
- @it = ::Item.repository.adapter
+describe 'Adapter' do
+ before do
+ class ::Item
+ include DataMapper::Resource
+ property :id, Serial
end
+ @it = ::Item.repository.adapter
+ end
- context 'instance' do
- should 'be adapter intance' do
- assert_kind_of DataMapper::Adapters::SphinxAdapter, @it
- assert_kind_of DataMapper::Sphinx::Adapter, @it
- end
-
- should 'get all items' do
- assert_equal 3, Item.all.size # should invoke full scan mode.
- end
+ it 'should be adapter intance' do
+ assert_kind_of DataMapper::Adapters::SphinxAdapter, @it
+ assert_kind_of DataMapper::Sphinx::Adapter, @it
+ end
- should 'be sphinx query' do
- assert_kind_of DataMapper::Sphinx::Query, DataMapper::Query.new(::Item.repository, ::Item, {})
- end
- end
+ it 'should invoke full scan (*) mode' do
+ assert_equal 3, Item.all.size
end
-end # AdapterTest
+end
View
27 test/test_query.rb
@@ -1,27 +0,0 @@
-require File.join(File.dirname(__FILE__), 'helper')
-
-class QueryTest < Test::Unit::TestCase
- context 'Query' do
- setup do
- class ::Item
- include DataMapper::Resource
- property :id, Serial
- end
- end
-
- should 'use sphinx query subclass' do
- assert_kind_of DataMapper::Sphinx::Query, query
- end
-
- should 'allow search mode' do
- assert_nothing_raised do
- assert_kind_of DataMapper::Sphinx::Query, query(:mode => :extended2)
- end
- end
- end
-
- protected
- def query(conditions = {})
- DataMapper::Query.new(::Item.repository, ::Item, conditions)
- end
-end
View
109 test/test_search_extended2.rb
@@ -1,74 +1,71 @@
require File.join(File.dirname(__FILE__), 'helper')
-class SearchTest < Test::Unit::TestCase
- context 'Search' do
- setup do
- class ::Item
- include DataMapper::Resource
- property :id, Serial
- property :t_string, String
- property :t_text, Text, :lazy => false
- end
- end
+describe 'Search Extended2' do
+ def search conditions = {}
+ DataMapper::Sphinx::Search::Extended2.new(
+ DataMapper::Sphinx::Query.new(::Item.repository, ::Item, conditions)
+ )
+ end
- should 'treat nil operator as equal comparison' do
- search = search(:t_string => 'foo')
- assert_equal '(@t_string foo)', search.statement
+ before do
+ class ::Item
+ include DataMapper::Resource
+ property :id, Serial
+ property :t_string, String
+ property :t_text, Text, :lazy => false
end
+ end
- should 'treat position operator as position comparison' do
- search = search(:t_string.position => ['foo', 2])
- assert_equal '(@t_string[2] "foo")', search.statement
- end
+ it 'should treat nil operator as equal comparison' do
+ search = search(:t_string => 'foo')
+ assert_equal '(@t_string foo)', search.statement
+ end
- should 'treat phrase operator as phrase comparison' do
- search = search(:t_string.phrase => 'foo bar')
- assert_equal '(@t_string "foo bar")', search.statement
- end
+ it 'should treat position operator as position comparison' do
+ search = search(:t_string.position => ['foo', 2])
+ assert_equal '(@t_string[2] "foo")', search.statement
+ end
- should 'treat proximity operator as proximity comparison' do
- search = search(:t_string.proximity => ['foo bar', 2])
- assert_equal '(@t_string "foo bar"~2)', search.statement
- end
+ it 'should treat phrase operator as phrase comparison' do
+ search = search(:t_string.phrase => 'foo bar')
+ assert_equal '(@t_string "foo bar")', search.statement
+ end
- should 'treat quorum operator as quorum comparison' do
- search = search(:t_string.quorum => ['foo bar', 2])
- assert_equal '(@t_string "foo bar"/2)', search.statement
- end
+ it 'should treat proximity operator as proximity comparison' do
+ search = search(:t_string.proximity => ['foo bar', 2])
+ assert_equal '(@t_string "foo bar"~2)', search.statement
+ end
- should 'treat exact operator as exact comparison' do
- search = search(:t_string.exact => 'foo')
- assert_equal '(@t_string ="foo")', search.statement
- end
+ it 'should treat quorum operator as quorum comparison' do
+ search = search(:t_string.quorum => ['foo bar', 2])
+ assert_equal '(@t_string "foo bar"/2)', search.statement
+ end
- should 'treat Array as inclusion comparison' do
- search = search(:t_string => %w{foo bar})
- assert_equal '(@t_string (foo|bar))', search.statement
- end
+ it 'should treat exact operator as exact comparison' do
+ search = search(:t_string.exact => 'foo')
+ assert_equal '(@t_string ="foo")', search.statement
+ end
- should 'treat .not opeartor as not operation' do
- search = search(:t_string.not => 'foo')
- assert_equal '(!(@t_string foo))', search.statement
- end
+ it 'should treat Array as inclusion comparison' do
+ search = search(:t_string => %w{foo bar})
+ assert_equal '(@t_string (foo|bar))', search.statement
+ end
- should 'treat Array .not operator as not operation of inclusion comparison' do
- search = search(:t_string.not => %w{foo bar})
- assert_equal '(!(@t_string (foo|bar)))', search.statement
- end
+ it 'should treat .not opeartor as not operation' do
+ search = search(:t_string.not => 'foo')
+ assert_equal '(!(@t_string foo))', search.statement
+ end
- should 'handle raw conditions' do
- search = search(:conditions => ['@* foo'])
- assert_equal '(@* foo)', search.statement
- end
+ it 'should treat Array .not operator as not operation of inclusion comparison' do
+ search = search(:t_string.not => %w{foo bar})
+ assert_equal '(!(@t_string (foo|bar)))', search.statement
+ end
- # TODO: Test 'and', 'or' connective operators.
+ it 'should handle raw conditions' do
+ search = search(:conditions => ['@* foo'])
+ assert_equal '(@* foo)', search.statement
end
- protected
- def search(conditions = {})
- DataMapper::Sphinx::Search::Extended2.new(
- DataMapper::Query.new(::Item.repository, ::Item, conditions)
- )
- end
+ # TODO: Test 'and', 'or' connective operators.
end
View
64 test/test_search_filter.rb
@@ -1,43 +1,39 @@
require File.join(File.dirname(__FILE__), 'helper')
-class FilterTest < Test::Unit::TestCase
- context 'Search' do
- setup do
- class ::Item
- include DataMapper::Resource
- property :id, Serial
- property :t_string, String
- property :t_deciaml, BigDecimal
- property :t_float, Float
- property :t_integer, Integer
- property :t_datetime, DateTime
- end
- end
+describe 'Search Filter' do
+ def filter(conditions = {})
+ DataMapper::Sphinx::Search::Filter.new(
+ DataMapper::Sphinx::Query.new(::Item.repository, ::Item, conditions)
+ )
+ end
- should 'treat nil operator as equal comparison' do
- filter = filter(:t_integer => 2000).statement
- assert_equal 1, filter.size
- assert_equal 't_integer', filter.first.attribute
- assert_equal [2000], filter.first.values
- assert_equal false, filter.first.exclude
+ before do
+ class ::Item
+ include DataMapper::Resource
+ property :id, Serial
+ property :t_string, String
+ property :t_deciaml, Decimal
+ property :t_float, Float
+ property :t_integer, Integer
+ property :t_datetime, DateTime
end
+ end
- should 'treat .not opeartor as not operation' do
- filter = filter(:t_integer.not => '2000').statement
- assert_equal 1, filter.size
- assert_equal 't_integer', filter.first.attribute
- assert_equal [2000], filter.first.values
- assert_equal true, filter.first.exclude
- end
+ it 'should treat nil operator as equal comparison' do
+ filter = filter(:t_integer => 2000).statement
+ assert_equal 1, filter.size
+ assert_equal 't_integer', filter.first.attribute
+ assert_equal [2000], filter.first.values
+ assert_equal false, filter.first.exclude
+ end
- # TODO: Ranges.
+ it 'should treat .not opeartor as not operation' do
+ filter = filter(:t_integer.not => '2000').statement
+ assert_equal 1, filter.size
+ assert_equal 't_integer', filter.first.attribute
+ assert_equal [2000], filter.first.values
+ assert_equal true, filter.first.exclude
end
- protected
- def filter(conditions = {})
- DataMapper::Sphinx::Search::Filter.new(
- DataMapper::Query.new(::Item.repository, ::Item, conditions)
- )
- end
+ # TODO: Ranges.
end
-
Please sign in to comment.
Something went wrong with that request. Please try again.