Skip to content

Commit 97909d2

Browse files
committed
Migrate test suite to rspec
1 parent f448291 commit 97909d2

File tree

5 files changed

+77
-97
lines changed

5 files changed

+77
-97
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ jobs:
3535
# run tests!
3636
- run:
3737
name: run tests
38-
command: bundle exec ruby test/test_suite.rb
38+
command: bundle exec rspec

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ source 'https://rubygems.org'
22

33
gemspec
44

5-
gem 'test-unit', '~> 3'
65
gem 'redis', '~> 4'
76
gem 'terminal-table', '~> 1', '>= 1.8'
7+
gem 'rspec'
88
gem 'codecov', :require => false, :group => :test
99

spec/helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'simplecov'
2+
SimpleCov.start
3+
4+
require 'codecov'
5+
SimpleCov.formatter = SimpleCov::Formatter::Codecov

spec/redisgraph_spec.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
require 'helper.rb'
2+
3+
require_relative '../lib/redisgraph.rb'
4+
5+
describe RedisGraph do
6+
# TODO it would be nice to have something like DisposableRedis
7+
# Connect to a Redis server on localhost:6379
8+
before(:all) do
9+
begin
10+
@r = RedisGraph.new("rubytest")
11+
rescue Redis::BaseError => e
12+
puts e
13+
puts "RedisGraph tests require that a Redis server with the graph module loaded be running on localhost:6379"
14+
exit 1
15+
end
16+
end
17+
18+
# Ensure that the graph "rubytest" does not exist
19+
after(:all) do
20+
@r.delete
21+
end
22+
23+
# Test functions - each validates one or more EXPLAIN and QUERY calls
24+
25+
context "nodes" do
26+
it "should create nodes properly" do
27+
query_str = """CREATE (t:node {name: 'src'})"""
28+
x = @r.query(query_str)
29+
plan = @r.explain(query_str)
30+
expect(plan).to include("Create")
31+
expect(x.resultset).to be_nil
32+
expect(x.stats[:labels_added]).to eq(1)
33+
expect(x.stats[:nodes_created]).to eq(1)
34+
expect(x.stats[:properties_set]).to eq(1)
35+
end
36+
37+
it "should delete nodes properly" do
38+
query_str = """MATCH (t:node) WHERE t.name = 'src' DELETE t"""
39+
plan = @r.explain(query_str)
40+
expect(plan).to include("Delete")
41+
x = @r.query(query_str)
42+
expect(x.resultset).to be_nil
43+
expect(x.stats[:nodes_deleted]).to eq(1)
44+
end
45+
end
46+
47+
context "edges" do
48+
it "should create edges properly" do
49+
query_str = """CREATE (p:node {name: 'src1'})-[:edge]->(:node {name: 'dest1'}), (:node {name: 'src2'})-[:edge]->(q:node_type_2 {name: 'dest2'})"""
50+
plan = @r.explain(query_str)
51+
expect(plan).to include("Create")
52+
x = @r.query(query_str)
53+
expect(x.resultset).to be_nil
54+
expect(x.stats[:nodes_created]).to eq(4)
55+
expect(x.stats[:properties_set]).to eq(4)
56+
expect(x.stats[:relationships_created]).to eq(2)
57+
end
58+
59+
it "should traverse edges properly" do
60+
query_str = """MATCH (a)-[:edge]->(b:node) RETURN a, b"""
61+
plan = @r.explain(query_str)
62+
expect(plan).to include("Traverse")
63+
x = @r.query(query_str)
64+
expect(x.resultset).to be_instance_of(Array)
65+
expect(x.columns.length).to eq(2)
66+
expect(x.resultset.length).to eq(1)
67+
expect(x.resultset[0]).to eq(["src1", "dest1"])
68+
end
69+
end
70+
end

test/test_suite.rb

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)