-
Notifications
You must be signed in to change notification settings - Fork 5
/
spec_helper.rb
98 lines (79 loc) · 2.16 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require 'rubygems'
require "bundler/setup"
require 'rspec'
require 'fileutils'
require 'tmpdir'
require 'its'
require 'logger'
require 'neo4j-core'
#require 'pry'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
#unless ENV['TRAVIS'] == 'true'
# puts "Use test db"
# Neo4j::Community.load_test_jars!
# #Neo4j::Core::Database.default_embedded_db = Java::OrgNeo4jTest::ImpermanentGraphDatabase
# $NEO4J_SERVER = Java::OrgNeo4jTest::ImpermanentGraphDatabase.new
#end
# Config
Neo4j::Config[:logger_level] = Logger::ERROR
Neo4j::Config[:debug_java] = true
EMBEDDED_DB_PATH = File.join(Dir.tmpdir, "neo4j-core-java")
FileUtils.rm_rf EMBEDDED_DB_PATH
def embedded_db
@@db ||= begin
FileUtils.rm_rf EMBEDDED_DB_PATH
db = Java::OrgNeo4jKernel::EmbeddedGraphDatabase.new(EMBEDDED_DB_PATH, Neo4j.config.to_java_map)
at_exit do
db.shutdown
FileUtils.rm_rf EMBEDDED_DB_PATH
end
db
end
end
def shutdown_embedded_db
if defined? @@db && @@db
finish_tx
@@db.shutdown
FileUtils.rm_rf EMBEDDED_DB_PATH
@@db = nil
end
end
def new_java_tx(db)
finish_tx if @tx
@tx = db.begin_tx
end
def finish_tx
return unless @tx
@tx.success
@tx.finish
@tx = nil
end
def new_tx
finish_tx if @tx
@tx = Neo4j::Transaction.new
end
Neo4j::Config[:storage_path] = File.join(Dir.tmpdir, "neo4j_core_integration_rspec")
FileUtils.rm_rf Neo4j::Config[:storage_path]
RSpec.configure do |c|
c.include(CustomNeo4jMatchers)
# c.filter_run :type => :featured
c.after(:each, :type => :integration) do
finish_tx
end
c.before(:all) do
Neo4j::Config[:storage_path] = File.join(Dir.tmpdir, "neo4j_core_integration_rspec")
end
c.before(:all, :type => :mock_db) do
Neo4j.shutdown
Neo4j::Config[:storage_path] = File.join(Dir.tmpdir, "neo4j_core_integration_rspec")
FileUtils.rm_rf Neo4j::Config[:storage_path]
Neo4j::Core::Database.default_embedded_db= MockDb
Neo4j.start
end
c.after(:all, :type => :mock_db) do
Neo4j.shutdown
Neo4j::Core::Database.default_embedded_db = nil
end
end