Skip to content

Commit

Permalink
Added unit tests for Store, LinkageStore, Database, and LinkageDatabase.
Browse files Browse the repository at this point in the history
  • Loading branch information
armcburney committed Jan 26, 2018
1 parent 8fafc4d commit 4523a49
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/os/mac/database/database.rb
Expand Up @@ -49,7 +49,7 @@ def create_tables
raise NotImplementedError
end

private
protected

# Takes in an array of strings, and formats them into a SQL list string
#
Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/os/mac/store/linkage_store.rb
Expand Up @@ -12,11 +12,6 @@
class LinkageStore < Store
include LinkageDatabaseTypes

# @key is the keg name for the `LinkageStore` class
#
# @return [String]
attr_reader :key

# Initializes new `LinkageStore` class
#
# @param [String] keg_name
Expand Down Expand Up @@ -69,6 +64,11 @@ def flush_condition

private

# @key is the keg name for the `LinkageStore` class
#
# @return [String]
attr_reader :key

# Fetches a subset of paths where the name = `key`
#
# @param [String] type
Expand Down
19 changes: 19 additions & 0 deletions Library/Homebrew/test/os/mac/database/database_spec.rb
@@ -0,0 +1,19 @@
require "os/mac/database/database"

describe Database do
subject { Database.new("test") }

describe "#initialize" do
it "should raise error trying to initialize" do
expect { Database.new("test") }
.to raise_error(NotImplementedError)
end
end

describe "#create_tables" do
it "should be abstract" do
expect { subject.create_tables }
.to raise_error(NotImplementedError)
end
end
end
12 changes: 12 additions & 0 deletions Library/Homebrew/test/os/mac/database/linkage_database_spec.rb
@@ -0,0 +1,12 @@
require "os/mac/database/linkage_database"

describe LinkageDatabase do
subject { LinkageDatabase.new }

describe "#create_tables" do
it "should be concrete" do
expect { subject.create_tables }
.to_not raise_error(NotImplementedError)
end
end
end
72 changes: 72 additions & 0 deletions Library/Homebrew/test/os/mac/store/linkage_store_spec.rb
@@ -0,0 +1,72 @@
require "os/mac/store/linkage_store"
require "os/mac/database/helpers/linkage_database_types"

describe LinkageStore do
include LinkageDatabaseTypes

subject { LinkageStore.new("scala") }

describe "#update!" do
it "should be concrete" do
expect { subject.update!(path_values: {}, hash_values: {}) }
.to_not raise_error(NotImplementedError)
end
end

describe "#fetch" do
describe "HASH_LINKAGE_TYPES" do
let(:type) { LinkageDatabaseTypes::HASH_LINKAGE_TYPES.sample }

it "should fetch hash values for a HASH_LINKAGE_TYPE" do
expect(subject)
.to receive(:fetch_hash_values).with(type: type)

subject.fetch(type: type)
end
end

describe "GENERALIZED_TYPES" do
let(:type) { LinkageDatabaseTypes::GENERALIZED_TYPES.sample }

it "should fetch path values for a GENERALIZED_TYPE" do
expect(subject)
.to receive(:fetch_path_values).with(type: type)

subject.fetch(type: type)
end
end

it "should be concrete" do
expect { subject.fetch(type: nil) }
.to_not raise_error(NotImplementedError)
end
end

describe "#flush_condition" do
it "should be concrete" do
expect { subject.flush_condition }
.to_not raise_error(NotImplementedError)
end

it "should return `name = '<key>'`" do
subject.stub(:key) { "scala" }
expect(subject.flush_condition).to eq("name = 'scala'")
end
end

describe "#flush_cache!" do
it "should be concrete" do
expect { subject.flush_cache! }
.to_not raise_error(NotImplementedError)
end

it "should call flush condition" do
subject.stub(:flush_condition) { "name = 'scala'" }

expect(subject)
.to receive(:flush_condition)

subject.flush_cache!
end
end
end
33 changes: 33 additions & 0 deletions Library/Homebrew/test/os/mac/store/store_spec.rb
@@ -0,0 +1,33 @@
require "os/mac/store/store"

describe Store do
subject { Store.new(double("Fake database", db: "db", name: "name")) }

describe "#update!" do
it "should be abstract" do
expect { subject.update!(nil) }
.to raise_error(NotImplementedError)
end
end

describe "#fetch" do
it "should be abstract" do
expect { subject.fetch(nil) }
.to raise_error(NotImplementedError)
end
end

describe "#flush_condition" do
it "should be abstract" do
expect { subject.flush_condition }
.to raise_error(NotImplementedError)
end
end

describe "#flush_cache!" do
it "should be abstract" do
expect { subject.flush_cache! }
.to raise_error(NotImplementedError)
end
end
end

0 comments on commit 4523a49

Please sign in to comment.