Skip to content

Commit

Permalink
test: more cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Aug 6, 2024
1 parent 889ceff commit 6ae767c
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/lint-and-rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ jobs:

rspec:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-14, windows-2019 ]
env:
CODECOV_TOKEN: 795f17c3-2dc3-4253-9627-e2d0a2e59223
steps:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ tebako_test.log
tests-actions/
.environment.version

# rspec failure tracking
# rspec
.rspec_status
coverage/
90 changes: 90 additions & 0 deletions spec/cli_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,94 @@
end
end
end

describe "#version_key" do
it "returns the correct version key" do
allow(self).to receive(:source).and_return("/path/to/source")
expect(version_key).to eq("#{Tebako::VERSION} at /path/to/source")
end
end

describe "#version_cache" do
it "returns the correct version and source from the cache file" do
version_file_content = "#{Tebako::VERSION} at /path/to/source\n"
allow(self).to receive(:deps).and_return("/path/to/deps")
allow(File).to receive(:join).with("/path/to/deps", Tebako::E_VERSION_FILE).and_return("/path/to/version_file")
allow(File).to receive(:open).with("/path/to/version_file").and_yield(StringIO.new(version_file_content))
end
end

describe "#version_cache_check" do # rubocop:disable Metrics/BlockLength
before do
allow(self).to receive(:version_cache).and_return(match_data)
allow(self).to receive(:version_unknown)
allow(self).to receive(:version_mismatch)
allow(self).to receive(:version_source_mismatch)
end

context "when version cache is unknown" do
let(:match_data) { nil }

it "calls version_unknown" do
expect(self).to receive(:version_unknown)
version_cache_check
end
end

context "when version does not match" do
let(:match_data) { { version: "0.7.0", source: "/path/to/source" } }
it "calls version_mismatch" do
expect(self).to receive(:version_mismatch).with("0.7.0")
version_cache_check
end
end

context "when source does not match" do
let(:match_data) { { version: Tebako::VERSION, source: "/different/source" } }

it "calls version_source_mismatch" do
allow(self).to receive(:source).and_return("/path/to/source")
expect(self).to receive(:version_source_mismatch).with("/different/source")
version_cache_check
end
end

context "when version and source match" do
let(:match_data) { { version: Tebako::VERSION, source: "/path/to/source" } }

it "does not call any mismatch methods" do
allow(self).to receive(:source).and_return("/path/to/source")
expect(self).not_to receive(:version_unknown)
expect(self).not_to receive(:version_mismatch)
expect(self).not_to receive(:version_source_mismatch)
version_cache_check
end
end
end
describe "#version_mismatch" do
it "prints the correct message and cleans the cache" do
expect(self).to receive(:puts)
.with("Tebako cache was created by a gem version 0.9.0 and cannot be used for gem version #{Tebako::VERSION}")
expect(self).to receive(:clean_cache)
allow(Tebako).to receive(:VERSION).and_return("1.0.0")
version_mismatch("0.9.0")
end
end
describe "#version_source_mismatch" do
it "prints the correct message and cleans the output" do
expect(self).to receive(:puts)
.with("CMake cache was created for a different source directory '/different/source' " \
"and cannot be used for '/path/to/source'")
expect(self).to receive(:clean_output)
allow(self).to receive(:source).and_return("/path/to/source")
version_source_mismatch("/different/source")
end
end
describe "#version_unknown" do
it "prints the correct message and cleans the cache" do
expect(self).to receive(:puts).with("CMake cache version was not recognized, cleaning up")
expect(self).to receive(:clean_cache)
version_unknown
end
end
end

0 comments on commit 6ae767c

Please sign in to comment.