Skip to content

Commit 73dc067

Browse files
committed
add VERSION, use rspec
1 parent af41216 commit 73dc067

File tree

10 files changed

+137
-99
lines changed

10 files changed

+137
-99
lines changed

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--require spec_helper
2+
--format documentation
3+
--color

Gemfile.lock

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
sqlite_extensions-uuid (1.0.0)
4+
sqlite_extensions-uuid (1.0.1)
55
sqlite3 (>= 2.4.0)
66

77
GEM
@@ -11,13 +11,14 @@ GEM
1111
debug (1.9.2)
1212
irb (~> 1.10)
1313
reline (>= 0.3.8)
14+
diff-lcs (1.6.0)
1415
io-console (0.7.2)
1516
irb (1.14.1)
1617
rdoc (>= 4.0.0)
1718
reline (>= 0.4.2)
1819
json (2.7.2)
1920
language_server-protocol (3.17.0.3)
20-
minitest (5.25.1)
21+
mini_portile2 (2.8.8)
2122
parallel (1.26.3)
2223
parser (3.3.5.0)
2324
ast (~> 2.4.1)
@@ -34,6 +35,19 @@ GEM
3435
regexp_parser (2.9.2)
3536
reline (0.5.10)
3637
io-console (~> 0.5)
38+
rspec (3.13.0)
39+
rspec-core (~> 3.13.0)
40+
rspec-expectations (~> 3.13.0)
41+
rspec-mocks (~> 3.13.0)
42+
rspec-core (3.13.3)
43+
rspec-support (~> 3.13.0)
44+
rspec-expectations (3.13.3)
45+
diff-lcs (>= 1.2.0, < 2.0)
46+
rspec-support (~> 3.13.0)
47+
rspec-mocks (3.13.2)
48+
diff-lcs (>= 1.2.0, < 2.0)
49+
rspec-support (~> 3.13.0)
50+
rspec-support (3.13.2)
3751
rubocop (1.66.1)
3852
json (~> 2.3)
3953
language_server-protocol (>= 3.17.0)
@@ -47,7 +61,8 @@ GEM
4761
rubocop-ast (1.32.3)
4862
parser (>= 3.3.1.0)
4963
ruby-progressbar (1.13.0)
50-
sqlite3 (2.4.0-x86_64-linux-gnu)
64+
sqlite3 (2.4.0)
65+
mini_portile2 (~> 2.8.0)
5166
stringio (3.1.1)
5267
unicode-display_width (2.6.0)
5368

@@ -56,9 +71,9 @@ PLATFORMS
5671

5772
DEPENDENCIES
5873
debug (>= 1.0.0)
59-
minitest
6074
rake
6175
rake-compiler
76+
rspec
6277
rubocop
6378
sqlite_extensions-uuid!
6479

Rakefile

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
require "bundler/gem_tasks"
44
require "rake/extensiontask"
5-
require "rake/testtask"
5+
66
require "rubocop/rake_task"
7+
RuboCop::RakeTask.new
8+
9+
require "rspec/core/rake_task"
10+
RSpec::Core::RakeTask.new(:spec)
711

812
task build: :compile
913

@@ -14,8 +18,6 @@ Rake::ExtensionTask.new("sqlite_extensions/uuid", GEMSPEC) do |ext|
1418
ext.lib_dir = "lib/sqlite_extensions/uuid"
1519
end
1620

17-
task default: %i[clobber compile]
18-
1921
task :update do
2022
sh "wget https://sqlite.org/2024/sqlite-autoconf-3460100.tar.gz"
2123
sh "tar xvf sqlite-autoconf-3460100.tar.gz"
@@ -26,14 +28,6 @@ task :update do
2628
sh "mv -v ./uuid.c ext/sqlite_extensions/uuid/"
2729
end
2830

29-
Rake::TestTask.new do |t|
30-
t.libs << "test"
31-
t.test_files = FileList["test/test_*.rb"]
32-
t.verbose = true
33-
end
34-
35-
task test: :compile
36-
37-
RuboCop::RakeTask.new
31+
task spec: :compile
3832

39-
task lint: "rubocop:autocorrect_all"
33+
task default: %i[clobber compile spec rubocop]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
module SqliteExtensions
4+
module UUID
5+
VERSION = "1.0.1"
6+
end
7+
end

spec/spec_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.configure do |config|
4+
config.disable_monkey_patching!
5+
config.warnings = true
6+
config.order = :random
7+
Kernel.srand config.seed
8+
end

spec/sqlite_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
require "sqlite_extensions/uuid"
4+
5+
# NOTE: `sqlite3` isn't required by our gem, but we need it for these tests.
6+
require "sqlite3"
7+
8+
RSpec.describe "Sqlite3 usage" do
9+
before do
10+
gemspec = instance_double(Gem::Specification, require_path: File.join(__dir__, "../lib"))
11+
allow(Gem).to receive(:loaded_specs).and_return("sqlite_extensions-uuid" => gemspec)
12+
end
13+
14+
# good enough for testing
15+
let(:uuid_regex) do
16+
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i
17+
end
18+
19+
it "works when passed as an extension to SQLite3::Database.new" do
20+
db = SQLite3::Database.new(":memory:", extensions: [SqliteExtensions::UUID.to_path])
21+
22+
result = db.execute("select uuid()")
23+
24+
expect(result).to match([[an_instance_of(String)]])
25+
uuid = result.first.first
26+
expect(uuid).to match(uuid_regex)
27+
end
28+
29+
it "works when using `enable_load_extension`" do
30+
db = SQLite3::Database.new ":memory:"
31+
db.enable_load_extension(true)
32+
db.load_extension(SqliteExtensions::UUID.to_path)
33+
34+
result = db.execute("select uuid()")
35+
36+
expect(result).to match([[an_instance_of(String)]])
37+
uuid = result.first.first
38+
expect(uuid).to match(uuid_regex)
39+
end
40+
end

spec/uuid_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require "sqlite_extensions/uuid"
4+
5+
RSpec.describe SqliteExtensions::UUID do # rubocop:disable Metrics/BlockLength
6+
it "has a version" do
7+
expect(described_class::VERSION).to eq "1.0.1"
8+
end
9+
10+
describe "#to_path" do
11+
before do
12+
gemspec = instance_double(Gem::Specification, require_path: "foo")
13+
allow(Gem).to receive(:loaded_specs).and_return("sqlite_extensions-uuid" => gemspec)
14+
end
15+
16+
it "returns the path to the compiled extension" do
17+
path = SqliteExtensions::UUID.to_path
18+
19+
expect(path).to eq "foo/sqlite_extensions/uuid/uuid"
20+
end
21+
end
22+
23+
it "has the correct gemspec info" do
24+
path = File.expand_path("../sqlite_extensions-uuid.gemspec", __dir__)
25+
gemspec = Gem::Specification.load path
26+
27+
expect(gemspec).to have_attributes(
28+
name: "sqlite_extensions-uuid",
29+
version: Gem::Version.new("1.0.1"),
30+
files: %w[
31+
ext/sqlite_extensions/uuid/extconf.rb
32+
ext/sqlite_extensions/uuid/sqlite3.h
33+
ext/sqlite_extensions/uuid/sqlite3ext.h
34+
ext/sqlite_extensions/uuid/uuid.c
35+
lib/sqlite_extensions/uuid.rb
36+
lib/sqlite_extensions/uuid/version.rb
37+
],
38+
licenses: ["MIT"],
39+
metadata: {},
40+
required_ruby_version: Gem::Requirement.new([">= 3.0.0"]),
41+
summary: "SQLite's UUID v4 extension, packaged as a gem"
42+
)
43+
require_paths = gemspec.require_paths
44+
expect(require_paths.size).to eq 2
45+
expect(require_paths.first).to end_with "sqlite_extensions-uuid-1.0.1"
46+
expect(require_paths.last).to eq "lib"
47+
end
48+
end

sqlite_extensions-uuid.gemspec

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# frozen_string_literal: true
22

3+
require_relative "lib/sqlite_extensions/uuid/version"
4+
35
Gem::Specification.new do |spec|
46
spec.name = "sqlite_extensions-uuid"
5-
spec.version = "1.0.0"
7+
spec.version = SqliteExtensions::UUID::VERSION
68
spec.authors = ["Mark Delk"]
79
spec.email = ["[email protected]"]
810

@@ -13,6 +15,7 @@ Gem::Specification.new do |spec|
1315

1416
spec.files = %w[
1517
lib/sqlite_extensions/uuid.rb
18+
lib/sqlite_extensions/uuid/version.rb
1619
ext/sqlite_extensions/uuid/sqlite3ext.h
1720
ext/sqlite_extensions/uuid/sqlite3.h
1821
ext/sqlite_extensions/uuid/uuid.c
@@ -23,8 +26,8 @@ Gem::Specification.new do |spec|
2326
spec.add_dependency "sqlite3", ">= 2.4.0"
2427

2528
spec.add_development_dependency "debug", ">= 1.0.0"
26-
spec.add_development_dependency "minitest"
2729
spec.add_development_dependency "rake"
2830
spec.add_development_dependency "rake-compiler"
31+
spec.add_development_dependency "rspec"
2932
spec.add_development_dependency "rubocop"
3033
end

test/test_helper.rb

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

test/test_uuid.rb

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

0 commit comments

Comments
 (0)