|
31 | 31 | end |
32 | 32 | end |
33 | 33 | end |
34 | | -end |
35 | 34 |
|
36 | | -RSpec.describe Unitsml::Unitsdb do |
37 | | - describe ".database" do |
38 | | - let(:context) { instance_double("Unitsdb context", id: :unitsml_ruby) } |
| 35 | + describe Unitsml::Unitsdb, ".database" do |
| 36 | + let(:context) { Struct.new(:id).new(:unitsml_ruby) } |
39 | 37 |
|
40 | 38 | before do |
41 | 39 | described_class.instance_variable_set(:@database, nil) |
|
61 | 59 | ) |
62 | 60 | end |
63 | 61 | end |
| 62 | + |
| 63 | + context "when unitsdb-ruby exposes a database loader" do |
| 64 | + before do |
| 65 | + stub_const("RUBY_ENGINE", "ruby") |
| 66 | + allow(Unitsdb).to receive(:database).and_return(:unitsdb_database) |
| 67 | + end |
| 68 | + |
| 69 | + it "uses the unitsdb-ruby loader with the UnitsML context" do |
| 70 | + expect(described_class.database).to eq(:unitsdb_database) |
| 71 | + expect(Unitsdb).to have_received(:database).with( |
| 72 | + context: :unitsml_ruby, |
| 73 | + ) |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + context "when unitsdb-ruby cannot load its packaged data directory" do |
| 78 | + before do |
| 79 | + stub_const("RUBY_ENGINE", "ruby") |
| 80 | + allow(Unitsdb).to receive(:database).and_raise( |
| 81 | + Unitsdb::Errors::DatabaseNotFoundError, |
| 82 | + ) |
| 83 | + allow(described_class) |
| 84 | + .to receive(:database_path) |
| 85 | + .and_return("/tmp/fallback-unitsdb") |
| 86 | + allow(Unitsml::Unitsdb::Database) |
| 87 | + .to receive(:from_db) |
| 88 | + .and_return(:fallback_database) |
| 89 | + end |
| 90 | + |
| 91 | + it "falls back to the UnitsML database wrapper with the same context" do |
| 92 | + expect(described_class.database).to eq(:fallback_database) |
| 93 | + expect(Unitsml::Unitsdb::Database).to have_received(:from_db).with( |
| 94 | + "/tmp/fallback-unitsdb", |
| 95 | + context: :unitsml_ruby, |
| 96 | + ) |
| 97 | + end |
| 98 | + end |
64 | 99 | end |
65 | 100 | end |
0 commit comments