Permalink
Browse files

adding initial cucumber support

  • Loading branch information...
1 parent 3a13382 commit 49bf0565bbe97ad1e9157fa5c03e63d866bddde7 @ryanb committed Mar 26, 2009
View
@@ -1,4 +1,5 @@
pkg
doc
*.sqlite3
+tmp/**/*
spec/tmp/**/*
@@ -0,0 +1,6 @@
+Scenario: Save xapian database on index
+ Given I configured the database to be saved at "tmp/xapiandb"
+ And I have a class to be indexed
+ And I have 3 records
+ When I index the database
+ Then I should find a directory at "tmp/xapiandb"
@@ -0,0 +1,3 @@
+Then /^I should find a directory at "([^\"]*)"$/ do |path|
+ File.exist?(File.dirname(__FILE__) + "/../../#{path}").should be_true
+end
@@ -0,0 +1,19 @@
+Given /^I configured the database to be saved at "([^\"]*)"$/ do |path|
+ Xapit::Config.setup(:database_path => File.dirname(__FILE__) + "/../../#{path}")
+end
+
+Given /^I have a class to be indexed$/ do
+ XapitMember.xapit do |index|
+ index.text :name
+ end
+end
+
+Given /^I have ([0-9]+) records?$/ do |num|
+ num.to_i.times do
+ XapitMember.new(:name => "foo")
+ end
+end
+
+When /^I index the database$/ do
+ Xapit::IndexBlueprint.index_all
+end
@@ -0,0 +1,6 @@
+require 'cucumber'
+require 'spec'
+require 'active_support'
+require 'fileutils'
+
+require File.dirname(__FILE__) + '/../../lib/xapit'
@@ -0,0 +1,32 @@
+class XapitMember
+ include Xapit::Membership
+
+ attr_reader :id
+
+ def self.each(&block)
+ @@records.each(&block) if @@records
+ end
+
+ def self.delete_all
+ @@records = []
+ end
+
+ def self.find(id)
+ @@records.detect { |r| r.id == id.to_i }
+ end
+
+ def initialize(attributes = {})
+ @@records ||= []
+ @id = @@records.size + 1
+ @attributes = attributes
+ @@records << self
+ end
+
+ def method_missing(name, *args)
+ if @attributes.has_key? name
+ @attributes[name]
+ else
+ super
+ end
+ end
+end
View
@@ -2,7 +2,7 @@
require 'spec'
require 'active_support'
require 'fileutils'
-require File.dirname(__FILE__) + '/../lib/xapit.rb'
+require File.dirname(__FILE__) + '/../lib/xapit'
Spec::Runner.configure do |config|
config.mock_with :rr

0 comments on commit 49bf056

Please sign in to comment.