neo4j_test_server 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 257b7ce2ee458c295bbbea6d82777f0538f21a94
4
+ data.tar.gz: 5f03f0e29debae62a26f866f458090391bba3490
5
+ SHA512:
6
+ metadata.gz: 7e6731ff4c21f4407843a76c07d842b4dcb6ec37f5ce18145cbabce38043ca9a8402287084a5fe98518a8a4058082cfdefd415ef1daa86850a20ea5e84f409ca
7
+ data.tar.gz: cf61ba93cbbf36b90e49fc04ca10cde9c0f2459286b0ff84bdd2abc76516e15bd92612ec37cf6b29113799673287f7cb240caab61146d8068418a73196d60a4b
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,148 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-04-14 18:20:32 -0500 using RuboCop version 0.30.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ AllCops:
9
+ Exclude:
10
+ - '*.gemspec'
11
+
12
+ # Offense count: 1
13
+ # Cop supports --auto-correct.
14
+ Lint/UnusedBlockArgument:
15
+ Enabled: false
16
+
17
+ # Offense count: 1
18
+ Metrics/AbcSize:
19
+ Max: 25
20
+
21
+ # Offense count: 1
22
+ # Configuration parameters: CountComments.
23
+ Metrics/ClassLength:
24
+ Max: 158
25
+
26
+ # Offense count: 12
27
+ # Configuration parameters: AllowURI, URISchemes.
28
+ Metrics/LineLength:
29
+ Max: 115
30
+
31
+ # Offense count: 1
32
+ # Configuration parameters: CountComments.
33
+ Metrics/MethodLength:
34
+ Max: 25
35
+
36
+ # Offense count: 1
37
+ Style/AccessorMethodName:
38
+ Enabled: false
39
+
40
+ # Offense count: 2
41
+ # Cop supports --auto-correct.
42
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
43
+ Style/BarePercentLiterals:
44
+ Enabled: false
45
+
46
+ # Offense count: 1
47
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
48
+ Style/ClassAndModuleChildren:
49
+ Enabled: false
50
+
51
+ # Offense count: 3
52
+ Style/Documentation:
53
+ Enabled: false
54
+
55
+ # Offense count: 1
56
+ # Cop supports --auto-correct.
57
+ Style/EmptyLines:
58
+ Enabled: false
59
+
60
+ # Offense count: 1
61
+ # Cop supports --auto-correct.
62
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
63
+ Style/EmptyLinesAroundBlockBody:
64
+ Enabled: false
65
+
66
+ # Offense count: 1
67
+ # Cop supports --auto-correct.
68
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
69
+ Style/EmptyLinesAroundClassBody:
70
+ Enabled: false
71
+
72
+ # Offense count: 1
73
+ # Cop supports --auto-correct.
74
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
75
+ Style/EmptyLinesAroundModuleBody:
76
+ Enabled: false
77
+
78
+ # Offense count: 2
79
+ # Configuration parameters: MinBodyLength.
80
+ Style/GuardClause:
81
+ Enabled: false
82
+
83
+ # Offense count: 1
84
+ # Cop supports --auto-correct.
85
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
86
+ Style/HashSyntax:
87
+ Enabled: false
88
+
89
+ # Offense count: 5
90
+ # Cop supports --auto-correct.
91
+ Style/LeadingCommentSpace:
92
+ Enabled: false
93
+
94
+ # Offense count: 2
95
+ # Cop supports --auto-correct.
96
+ Style/MultilineIfThen:
97
+ Enabled: false
98
+
99
+ # Offense count: 29
100
+ # Cop supports --auto-correct.
101
+ # Configuration parameters: PreferredDelimiters.
102
+ Style/PercentLiteralDelimiters:
103
+ Enabled: false
104
+
105
+ # Offense count: 2
106
+ # Cop supports --auto-correct.
107
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
108
+ Style/PercentQLiterals:
109
+ Enabled: false
110
+
111
+ # Offense count: 1
112
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
113
+ Style/RaiseArgs:
114
+ Enabled: false
115
+
116
+ # Offense count: 1
117
+ # Cop supports --auto-correct.
118
+ Style/RedundantBegin:
119
+ Enabled: false
120
+
121
+ # Offense count: 2
122
+ # Cop supports --auto-correct.
123
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
124
+ Style/SignalException:
125
+ Enabled: false
126
+
127
+ # Offense count: 2
128
+ # Cop supports --auto-correct.
129
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
130
+ Style/SpaceInsideBlockBraces:
131
+ Enabled: false
132
+
133
+ # Offense count: 69
134
+ # Cop supports --auto-correct.
135
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
136
+ Style/StringLiterals:
137
+ Enabled: false
138
+
139
+ # Offense count: 5
140
+ # Cop supports --auto-correct.
141
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
142
+ Style/TrailingBlankLines:
143
+ Enabled: false
144
+
145
+ # Offense count: 29
146
+ # Cop supports --auto-correct.
147
+ Style/UnneededPercentQ:
148
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'http://rubygems.org'
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'neo4j', '~> 4.1.1'
7
+ gem 'neo4j-core', '~> 4.0.0'
8
+ gem 'httparty'
9
+ gem 'zip'
10
+
11
+ # Add dependencies to develop your gem here.
12
+ # Include everything needed to run rake, tests, features, etc.
13
+ group :development do
14
+ gem 'rspec', '~> 3.2.0'
15
+ gem 'rspec-mocks'
16
+ gem 'rdoc', '~> 3.12'
17
+ gem 'bundler', '~> 1.0'
18
+ gem 'jeweler', '~> 2.0.1'
19
+ gem 'simplecov', '>= 0'
20
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Andy Schrage
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # neo4j_test_server
2
+ Auto-starts a local Neo4j instance for running integration tests
3
+
4
+ ## How to install
5
+
6
+ Install this neo4j_test_server from rubygems either directly:
7
+
8
+ ```bash
9
+ gem install neo4j_test_server
10
+ ```
11
+
12
+ Or through bundler
13
+
14
+ ```ruby
15
+ # in Gemfile
16
+ gem "neo4j_test_server"
17
+ ```
18
+
19
+ In `spec_helper.rb`
20
+
21
+ ```
22
+ require 'sunspot_test/rspec'
23
+ ```
24
+
25
+ ## What does it do?
26
+
27
+ This gem will automatically startup a Neo4j server running locally for testing purposes. The default server starts at
28
+ [http://localhost:7474](http://localhost:7474).
29
+
30
+ The gem also provides rspec hooks for tests that require Neo4j without requiring the server to be started for all of
31
+ your tests.
32
+
33
+ ## Writing test that use Neo4jTestServer
34
+
35
+ In `spec_helper.rb`
36
+ ```ruby
37
+ require 'neo4j_test_server'
38
+ require 'neo4j_test_server/rspec'
39
+ ```
40
+
41
+ Then in your specs, tag the specs that require a neo4j server with 'neo4j: true'
42
+
43
+ ```ruby
44
+ describe 'My Tests' do
45
+ describe 'using neo4j', neo4j: true do
46
+
47
+ end
48
+
49
+ describe 'neo4j unnecessary' do
50
+
51
+ end
52
+ end
53
+ ```
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts 'Run `bundle install` to install missing gems'
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = 'neo4j_test_server'
18
+ gem.homepage = 'http://github.com/Swimminschrage/neo4j_test_server'
19
+ gem.license = 'MIT'
20
+ gem.summary = %{Installs/Autostarts a Neo4j instance for your tests}
21
+ gem.description = %Q{Installs/Autostarts a Neo4j instance for your tests}
22
+ gem.email = "Swimminschrage@gmail.com"
23
+ gem.authors = ["Swimminschrage"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ desc "Code coverage detail"
35
+ task :simplecov do
36
+ ENV['COVERAGE'] = "true"
37
+ Rake::Task['spec'].execute
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rdoc/task'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "neo4j_test_server #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,72 @@
1
+ require 'neo4j'
2
+ require 'net/http'
3
+ require 'neo4j_test_server/neo4j_server'
4
+ require 'neo4j_test_server/installer'
5
+
6
+ # Based off of the setup uses for SunspotTest
7
+ module Neo4jTestServer
8
+ class TimeoutError < StandardError; end
9
+ class << self
10
+ attr_writer :neo4j_startup_timeout
11
+ attr_writer :server
12
+
13
+ def neo4j_startup_timeout
14
+ @neo4j_startup_timeout ||= 30
15
+ end
16
+
17
+ def setup_neo4j
18
+ start_neo4j_server
19
+ end
20
+
21
+ def start_neo4j_server
22
+ unless neo4j_running?
23
+ server.start
24
+
25
+ at_exit do
26
+ puts "Shutting down Neo4j server at '#{server}'"
27
+ server.stop
28
+ end
29
+
30
+ wait_for_server
31
+ end
32
+ end
33
+
34
+ def wait_for_server
35
+ (neo4j_startup_timeout * 10).times do
36
+ break if neo4j_running?
37
+ sleep(0.1)
38
+ end
39
+ raise TimeoutError, "Neo4j failed to startup after #{neo4j_startup_timeout} seconds." unless neo4j_running?
40
+ puts "Neo4j Running at '#{server}'"
41
+ end
42
+
43
+ def neo4j_running?
44
+ begin
45
+ Net::HTTP.get(URI.parse(ping_url))
46
+ true
47
+ rescue
48
+ false # Neo4j not running
49
+ end
50
+ end
51
+
52
+ def ping_url
53
+ "http://#{server.bind_address}:#{server.port}"
54
+ end
55
+
56
+ def server
57
+ @server ||= Neo4jTest::Server.new
58
+ end
59
+
60
+ def session
61
+ return nil unless neo4j_running?
62
+
63
+ @session ||= Neo4j::Session.open(:server_db, ping_url)
64
+ end
65
+
66
+ def clear_db
67
+ session.query('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r')
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,139 @@
1
+ require 'os'
2
+ require 'httparty'
3
+ require 'zip'
4
+
5
+ module Neo4jTest
6
+ class Installer
7
+ BadEditionError = Class.new(RuntimeError)
8
+
9
+ class << self
10
+ def bootstrap(edition)
11
+ raise BadEditionError if edition.empty?
12
+
13
+ download_neo4j_unless_exists edition
14
+ unzip_neo4j edition
15
+ rake_auth_toggle :disable
16
+ end
17
+
18
+ def file_name(edition = '')
19
+ suffix = OS::Underlying.windows? ? 'neo4j.zip' : 'neo4j-unix.tar.gz'
20
+ prefix = edition.empty? ? '' : "#{edition}-"
21
+
22
+ [prefix, suffix].join ''
23
+ end
24
+
25
+ def download_to(edition = '')
26
+ # We want to ensure that we download the Neo4j archive to the gem location. Not the project's location
27
+ File.join(File.dirname(here), file_name(edition))
28
+ end
29
+
30
+ def download_url(edition)
31
+ "http://dist.neo4j.org/neo4j-#{edition}-#{OS::Underlying.windows? ? 'windows.zip' : 'unix.tar.gz'}"
32
+ end
33
+
34
+ def download_neo4j_unless_exists(edition)
35
+ download_neo4j(edition) unless File.exist?(download_to(edition))
36
+ download_to(edition)
37
+ end
38
+
39
+ def download_neo4j(edition)
40
+ success = false
41
+
42
+ File.open(download_to(edition), 'wb') do |file|
43
+ file << request_url(download_url(edition))
44
+ success = true
45
+ end
46
+
47
+ download_to(edition)
48
+ ensure
49
+ File.delete(file_name) unless success
50
+ end
51
+
52
+ def unzip_neo4j(edition)
53
+ downloaded_file = download_to(edition)
54
+
55
+ if OS::Underlying.windows?
56
+ # Extract and move to neo4j directory
57
+ unless File.exist?(install_location)
58
+ Zip::ZipFile.open(downloaded_file) do |zip_file|
59
+ zip_file.each do |f|
60
+ f_path = File.join('.', f.name)
61
+ FileUtils.mkdir_p(File.dirname(f_path))
62
+ begin
63
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
64
+ rescue
65
+ puts "#{f.name} failed to extract."
66
+ end
67
+ end
68
+ end
69
+ FileUtils.mv "neo4j-#{edition}", install_location
70
+ end
71
+
72
+ # Install if running with Admin Privileges
73
+ if `reg query "HKU\\S-1-5-19"`.size > 0
74
+ `"#{install_location}/bin/neo4j install"`
75
+ puts 'Neo4j Installed as a service.'
76
+ end
77
+
78
+ else
79
+ `tar -xvf #{downloaded_file}`
80
+ `mv neo4j-#{edition} #{install_location}`
81
+ puts 'Neo4j Installed in to neo4j directory.'
82
+ end
83
+ end
84
+
85
+ def request_url(url)
86
+ status = HTTParty.head(url).code
87
+ fail "#{edition} is not available to download, try a different version" if status < 200 || status >= 300
88
+
89
+ HTTParty.get(url)
90
+ end
91
+
92
+ def get_environment
93
+ 'development'
94
+ end
95
+
96
+ def install_location
97
+ path = File.expand_path('../../../tmp/db/neo4j', __FILE__)
98
+ FileUtils.mkdir_p(path)
99
+ "#{path}/#{get_environment}"
100
+ end
101
+
102
+ def config_location
103
+ "#{install_location}/conf/neo4j-server.properties"
104
+ end
105
+
106
+ def rake_auth_toggle(status)
107
+ location = config_location
108
+ text = File.read(location)
109
+ replace = toggle_auth(status, text)
110
+ File.open(location, 'w') { |file| file.puts replace }
111
+ end
112
+
113
+ def config(source_text, port)
114
+ s = set_property(source_text, 'org.neo4j.server.webserver.https.enabled', 'false')
115
+ set_property(s, 'org.neo4j.server.webserver.port', port)
116
+ end
117
+
118
+ def set_property(source_text, property, value)
119
+ source_text.gsub(/#{property}\s*=\s*(\w+)/, "#{property}=#{value}")
120
+ end
121
+
122
+ # Toggles the status of Neo4j 2.2's basic auth
123
+ def toggle_auth(status, source_text)
124
+ status_string = status == :enable ? 'true' : 'false'
125
+ %w(dbms.security.authorization_enabled dbms.security.auth_enabled).each do |key|
126
+ source_text = set_property(source_text, key, status_string)
127
+ end
128
+ source_text
129
+ end
130
+
131
+ # Defining a method that represents the current location of this file for testing purposes since I cant
132
+ # seem to be able to mock out "__FILE__" in the rspec tests. I CAN however mock out this method during
133
+ # testing... :-)
134
+ def here
135
+ __FILE__
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,11 @@
1
+ require 'rbconfig'
2
+
3
+ module Neo4jTest
4
+ module Java
5
+ NULL_DEVICE = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL' : '/dev/null'
6
+
7
+ def self.installed?
8
+ system "java -version >#{NULL_DEVICE} 2>&1"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,97 @@
1
+ require 'neo4j_test_server/java'
2
+ require 'os'
3
+ require 'httparty'
4
+ require 'zip'
5
+
6
+ module Neo4jTest
7
+ class Server
8
+ # Raised if #stop is called but the server is not running
9
+ ServerError = Class.new(RuntimeError)
10
+ AlreadyRunningError = Class.new(ServerError)
11
+ NotRunningError = Class.new(ServerError)
12
+ JavaMissing = Class.new(ServerError)
13
+
14
+ attr_accessor :edition
15
+
16
+ attr_writer :neo4j_data_dir, :neo4j_home, :neo4j_jar, :bind_address, :port
17
+
18
+ def initialize(*args)
19
+ ensure_java_installed
20
+ self.edition = 'community-2.2.0'
21
+ super(*args)
22
+ end
23
+
24
+ def to_s
25
+ "http://#{bind_address}:#{port}" unless bind_address.empty? && port.empty?
26
+ end
27
+
28
+ def bootstrap
29
+ unless @bootstrapped
30
+ Neo4jTest::Installer.bootstrap edition
31
+ @bootstrapped = true
32
+ end
33
+ end
34
+
35
+ def bind_address
36
+ @bind_address ||= '127.0.0.1'
37
+ end
38
+
39
+ def port
40
+ @port ||= '7474'
41
+ end
42
+
43
+ def start_command
44
+ @start_command ||= 'start'
45
+ end
46
+
47
+ def start
48
+ bootstrap
49
+
50
+ puts 'Starting Neo4j...'
51
+ if OS::Underlying.windows?
52
+ start_windows_server(start_command)
53
+ else
54
+ start_starnix_server(start_command)
55
+ end
56
+ end
57
+
58
+ def stop
59
+ if OS::Underlying.windows?
60
+ if `reg query "HKU\\S-1-5-19"`.size > 0
61
+ `#{install_location}/bin/Neo4j.bat stop` # stop service
62
+ else
63
+ puts 'You do not have administrative rights to stop the Neo4j Service'
64
+ end
65
+ else
66
+ `#{install_location}/bin/neo4j stop`
67
+ end
68
+ end
69
+
70
+ def start_windows_server(command)
71
+ if `reg query "HKU\\S-1-5-19"`.size > 0
72
+ `#{install_location}/bin/Neo4j.bat #{command}` # start service
73
+ else
74
+ puts 'Starting Neo4j directly, not as a service.'
75
+ `#{install_location}/bin/Neo4j.bat`
76
+ end
77
+ end
78
+
79
+ def start_starnix_server(command)
80
+ `#{install_location}/bin/neo4j #{command}`
81
+ end
82
+
83
+ def ensure_java_installed
84
+ unless defined?(@java_installed)
85
+ @java_installed = Neo4jTest::Java.installed?
86
+ unless @java_installed
87
+ raise JavaMissing.new('You need a Java Runtime Environment to run the Solr server')
88
+ end
89
+ end
90
+ @java_installed
91
+ end
92
+
93
+ def install_location
94
+ Neo4jTest::Installer.install_location
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,16 @@
1
+ require 'neo4j_test_server'
2
+ require 'rspec'
3
+
4
+ RSpec.configure do |c|
5
+ c.before(:each, neo4j: true) do
6
+ puts 'Running using actual Neo4j instance....'
7
+ Neo4jTestServer.setup_neo4j
8
+ #TODO: Add any cleanup that should happen between tests
9
+
10
+ # Configure this statement to match the url for the local Neo4j instance.
11
+ Neo4j::Session.open(:server_db, 'http://127.0.0.1:7474')
12
+
13
+ # Delete all nodes/relationships from the grid
14
+ Neo4jTestServer.clear_db
15
+ end
16
+ end
@@ -0,0 +1,83 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: neo4j_test_server 1.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "neo4j_test_server"
9
+ s.version = "1.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Swimminschrage"]
14
+ s.date = "2015-04-20"
15
+ s.description = "Installs/Autostarts a Neo4j instance for your tests"
16
+ s.email = "Swimminschrage@gmail.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ ".rubocop.yml",
25
+ "Gemfile",
26
+ "LICENSE",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "lib/neo4j_test_server.rb",
31
+ "lib/neo4j_test_server/installer.rb",
32
+ "lib/neo4j_test_server/java.rb",
33
+ "lib/neo4j_test_server/neo4j_server.rb",
34
+ "lib/neo4j_test_server/rspec.rb",
35
+ "neo4j_test_server.gemspec",
36
+ "spec/neo4j_test_server_spec.rb",
37
+ "spec/spec_helper.rb"
38
+ ]
39
+ s.homepage = "http://github.com/Swimminschrage/neo4j_test_server"
40
+ s.licenses = ["MIT"]
41
+ s.rubygems_version = "2.4.6"
42
+ s.summary = "Installs/Autostarts a Neo4j instance for your tests"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 4
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<neo4j>, ["~> 4.1.1"])
49
+ s.add_runtime_dependency(%q<neo4j-core>, ["~> 4.0.0"])
50
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
51
+ s.add_runtime_dependency(%q<zip>, [">= 0"])
52
+ s.add_development_dependency(%q<rspec>, ["~> 3.2.0"])
53
+ s.add_development_dependency(%q<rspec-mocks>, [">= 0"])
54
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
57
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<neo4j>, ["~> 4.1.1"])
60
+ s.add_dependency(%q<neo4j-core>, ["~> 4.0.0"])
61
+ s.add_dependency(%q<httparty>, [">= 0"])
62
+ s.add_dependency(%q<zip>, [">= 0"])
63
+ s.add_dependency(%q<rspec>, ["~> 3.2.0"])
64
+ s.add_dependency(%q<rspec-mocks>, [">= 0"])
65
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
68
+ s.add_dependency(%q<simplecov>, [">= 0"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<neo4j>, ["~> 4.1.1"])
72
+ s.add_dependency(%q<neo4j-core>, ["~> 4.0.0"])
73
+ s.add_dependency(%q<httparty>, [">= 0"])
74
+ s.add_dependency(%q<zip>, [">= 0"])
75
+ s.add_dependency(%q<rspec>, ["~> 3.2.0"])
76
+ s.add_dependency(%q<rspec-mocks>, [">= 0"])
77
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
78
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
79
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
80
+ s.add_dependency(%q<simplecov>, [">= 0"])
81
+ end
82
+ end
83
+
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe 'Neo4jTest' do
5
+ let(:test_directory) { 'tmp/test' }
6
+
7
+ describe '::Server' do
8
+ describe '#start_neo4j_server' do
9
+ let(:server) { double(start: true, stop: true, to_s: 'DUMMY') }
10
+ before(:each) do
11
+ # Don't actually create/start a Neo4j server...
12
+ allow(Neo4jTestServer).to receive(:server).and_return(server)
13
+ end
14
+
15
+ it 'is idempotent' do
16
+ allow(Neo4jTestServer).to receive(:neo4j_running?).and_return(false, true, true)
17
+ allow(Neo4jTestServer).to receive(:wait_for_server).and_return(true)
18
+
19
+ expect(server).to receive(:start).once
20
+
21
+ # Execute the method 3 times
22
+ 3.times do
23
+ Neo4jTestServer.start_neo4j_server
24
+ end
25
+ end
26
+
27
+ it 'raises an exception if it doesnt hear from neo4j' do
28
+ allow(Neo4jTestServer).to receive(:neo4j_running?).and_return(false)
29
+
30
+ # Set the timeout to a more reasonable time for this test
31
+ Neo4jTestServer.neo4j_startup_timeout = 4 #seconds
32
+
33
+ expect { Neo4jTestServer.start_neo4j_server }.to raise_error(Neo4jTestServer::TimeoutError)
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '::Installer' do
39
+ before(:each) do
40
+ FileUtils.mkdir_p test_directory
41
+ end
42
+
43
+ after(:each) do
44
+ FileUtils.remove_dir(test_directory) if File.exist? test_directory
45
+ end
46
+
47
+ describe '#file_name' do
48
+ it 'return the correct filename for windows' do
49
+ allow(OS::Underlying).to receive(:windows?) { true }
50
+
51
+ expect(Neo4jTest::Installer.file_name).to eq 'neo4j.zip'
52
+ end
53
+
54
+ it 'returns the correct filename for unix' do
55
+ allow(OS::Underlying).to receive(:windows?) { false }
56
+
57
+ expect(Neo4jTest::Installer.file_name).to eq 'neo4j-unix.tar.gz'
58
+ end
59
+
60
+ it 'returns the correct filename given an edition' do
61
+ allow(OS::Underlying).to receive(:windows?) { true }
62
+
63
+ expect(Neo4jTest::Installer.file_name('myedition')).to eq 'myedition-neo4j.zip'
64
+ end
65
+ end
66
+
67
+ describe '#download_neo4j' do
68
+
69
+ it 'downloads the correct file' do
70
+ allow(Neo4jTest::Installer).to receive(:request_url).and_return('Test data')
71
+ allow(Neo4jTest::Installer).to receive(:download_to).and_return(File.join(test_directory, 'test.txt'))
72
+
73
+ Neo4jTest::Installer.download_neo4j 'community-2.2.0'
74
+ expect(File.exist?('tmp/test')).to be true
75
+ end
76
+ end
77
+
78
+ describe '#download_neo4j_unless_exists' do
79
+ it 'downloads the correct file the first time' do
80
+ allow(Neo4jTest::Installer).to receive(:request_url).and_return('Test data')
81
+ allow(Neo4jTest::Installer).to receive(:download_to).and_return(File.join(test_directory, 'test.txt'))
82
+
83
+ Neo4jTest::Installer.download_neo4j 'community-2.2.0'
84
+ expect(File.exist?('tmp/test')).to be true
85
+ end
86
+
87
+ it 'doesnt download on subsequent tries' do
88
+ allow(Neo4jTest::Installer).to receive(:request_url).and_return('Test data')
89
+ allow(Neo4jTest::Installer).to receive(:download_to).and_return(File.join(test_directory, 'test.txt'))
90
+
91
+ Neo4jTest::Installer.download_neo4j_unless_exists 'community-2.2.0'
92
+ expect(File.exist?('tmp/test')).to be true
93
+
94
+ expect(Neo4jTest::Installer).to_not receive(:download_neo4j)
95
+ Neo4jTest::Installer.download_neo4j_unless_exists 'community-2.2.0'
96
+ expect(File.exist?('tmp/test')).to be true
97
+ end
98
+ end
99
+
100
+ describe '#download_to' do
101
+
102
+ shared_examples 'a valid download location' do
103
+ shared_examples 'a downloadable edition' do
104
+ let(:pwd) { '/Users/testuser/.rvm/gems/ruby-2.2.1@neo4j_test/gems/neo4j-4.1.5/'}
105
+
106
+ it 'returns the correct save to location' do
107
+ allow(OS::Underlying).to receive(:windows?).and_return is_windows?
108
+ allow(Neo4jTest::Installer).to receive(:here).and_return("#{pwd}/test.rb")
109
+ expect(Neo4jTest::Installer.download_to(edition)).to eq expected_download_to
110
+ end
111
+ end
112
+
113
+ context 'given community-2.2.0 edition' do
114
+ let(:edition) { 'community-2.2.0' }
115
+ let(:expected_download_to) { File.join pwd, "#{edition}-neo4j#{ext}" }
116
+
117
+ it_behaves_like 'a downloadable edition'
118
+ end
119
+
120
+ context 'without an edition' do
121
+ let(:edition) { '' }
122
+ let(:expected_download_to) { File.join pwd, "neo4j#{ext}" }
123
+
124
+ it_behaves_like 'a downloadable edition'
125
+ end
126
+ end
127
+
128
+ context 'on a Unix machine' do
129
+ let(:ext) { '-unix.tar.gz' }
130
+ let(:is_windows?) { false }
131
+
132
+ it_behaves_like 'a valid download location'
133
+ end
134
+
135
+ context 'on a Windows machine' do
136
+ let(:ext) { '.zip'}
137
+ let(:is_windows?) { true }
138
+ it_behaves_like 'a valid download location'
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,30 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'rspec/mocks'
22
+ require 'neo4j_test_server'
23
+
24
+ # Requires supporting files with custom matchers and macros, etc,
25
+ # in ./support/ and its subdirectories.
26
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
27
+
28
+ RSpec.configure do |config|
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neo4j_test_server
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Swimminschrage
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: neo4j
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: neo4j-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: zip
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.2.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-mocks
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rdoc
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.12'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.12'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: jeweler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.0.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.0.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Installs/Autostarts a Neo4j instance for your tests
154
+ email: Swimminschrage@gmail.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files:
158
+ - LICENSE
159
+ - README.md
160
+ files:
161
+ - ".document"
162
+ - ".rspec"
163
+ - ".rubocop.yml"
164
+ - Gemfile
165
+ - LICENSE
166
+ - README.md
167
+ - Rakefile
168
+ - VERSION
169
+ - lib/neo4j_test_server.rb
170
+ - lib/neo4j_test_server/installer.rb
171
+ - lib/neo4j_test_server/java.rb
172
+ - lib/neo4j_test_server/neo4j_server.rb
173
+ - lib/neo4j_test_server/rspec.rb
174
+ - neo4j_test_server.gemspec
175
+ - spec/neo4j_test_server_spec.rb
176
+ - spec/spec_helper.rb
177
+ homepage: http://github.com/Swimminschrage/neo4j_test_server
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.4.6
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Installs/Autostarts a Neo4j instance for your tests
201
+ test_files: []