-
Notifications
You must be signed in to change notification settings - Fork 2
Test your models with rspec
architect4r test support is still very limited and needs lot of work. Maybe some experienced user might be able to help here!
Assuming you want to reset your neo4j database before each testrun, you can use the InstanceManager to do so. Just require the file and create an instance pointing to the location of neo4j server. In this case it is placed in the app's root folder. But you could also put it i.e. in ~/packages/my_app_neo_test_server
.
require 'architect4r/instance_manager'
neo_manager = Architect4r::InstanceManager.new(File.join(File.dirname(__FILE__), '../neo4j_server'))
Next you can define when to reset the database. If you need to debug what is happening in the graph db, it is best to reset the database before running the tests and stop the server afterwards. This way you can still check what data has been added. Just comment the neo_manager.stop command or start the server manually.
RSpec.configure do |config|
# Setup architect4r
config.before(:suite) do
neo_manager.reset
end
config.after(:suite) do
neo_manager.stop
end
end
If you wanna test with an existing database which already contains some data, just use this command instead of reset
and point it to the neo4j graph.db folder. It will copy the data and start your test instance.
neo_manager.reset_to_sample_data(File.join(File.dirname(__FILE__), "fixtures/graph.db.default/"))
If you do not wanna run tons of servers, you can easily use an environment variable to store the path to your test server. As the data is reset with every new run, you can use the same test server for multiple projects.
neo_manager = Architect4r::InstanceManager.new(ENV["NEO4J_TEST_SERVER"])