-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: moved Tebako Cli tests from shunit to rspec
- Loading branch information
Showing
14 changed files
with
394 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,6 @@ tebako_test.log | |
.t/ | ||
tests-actions/ | ||
.environment.version | ||
|
||
# rspec failure tracking | ||
.rspec_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--format documentation | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,6 @@ Naming/FileName: | |
|
||
Style/BlockComments: | ||
Enabled: false | ||
|
||
Gemspec/DevelopmentDependencies: | ||
EnforcedStyle: gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com). | ||
# All rights reserved. | ||
# This file is a part of tebako | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS | ||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
require "yaml" | ||
require_relative "../lib/tebako/cli_helpers" | ||
|
||
RSpec.describe Tebako::CliHelpers do # rubocop:disable Metrics/BlockLength | ||
include Tebako::CliHelpers | ||
|
||
let(:options) { {} } | ||
|
||
before do | ||
allow(self).to receive(:options).and_return(options) | ||
end | ||
|
||
describe "#l_level" do | ||
context "when log-level option is not set" do | ||
it 'returns "error"' do | ||
expect(l_level).to eq("error") | ||
end | ||
end | ||
|
||
context "when log-level option is set" do | ||
let(:options) { { "log-level" => "info" } } | ||
|
||
it "returns the value of the log-level option" do | ||
expect(l_level).to eq("info") | ||
end | ||
end | ||
end | ||
|
||
describe "#m_files" do # rubocop:disable Metrics/BlockLength | ||
context "when on a Linux platform" do | ||
before do | ||
stub_const("RUBY_PLATFORM", "linux") | ||
end | ||
|
||
it 'returns "Unix Makefiles"' do | ||
expect(m_files).to eq("Unix Makefiles") | ||
end | ||
end | ||
|
||
context "when on a macOS platform" do | ||
before do | ||
stub_const("RUBY_PLATFORM", "darwin") | ||
end | ||
|
||
it 'returns "Unix Makefiles"' do | ||
expect(m_files).to eq("Unix Makefiles") | ||
end | ||
end | ||
|
||
context "when on a Windows platform" do | ||
before do | ||
stub_const("RUBY_PLATFORM", "msys") | ||
end | ||
|
||
it 'returns "MinGW Makefiles"' do | ||
expect(m_files).to eq("MinGW Makefiles") | ||
end | ||
end | ||
|
||
context "when on an unsupported platform" do | ||
before do | ||
stub_const("RUBY_PLATFORM", "unsupported") | ||
end | ||
|
||
it "raises a Tebako::Error" do | ||
expect { m_files }.to raise_error(Tebako::Error, "unsupported is not supported yet, exiting") | ||
end | ||
end | ||
end | ||
|
||
describe "#options_from_tebafile" do | ||
let(:tebafile) { "spec/fixtures/tebafile.yml" } | ||
|
||
context "when the tebafile contains valid YAML" do | ||
it "loads options from the tebafile" do | ||
allow(YAML).to receive(:load_file).and_return({ "options" => { "key" => "value" } }) | ||
expect(options_from_tebafile(tebafile)).to eq({ "key" => "value" }) | ||
end | ||
end | ||
|
||
context "when the tebafile contains invalid YAML" do | ||
it "returns an empty hash and prints a warning" do | ||
allow(YAML).to receive(:load_file).and_raise(Psych::SyntaxError.new("file", 1, 1, 1, "message", "context")) | ||
expect { options_from_tebafile(tebafile) }.to output(/Warning: The tebafile/).to_stdout | ||
expect(options_from_tebafile(tebafile)).to eq({}) | ||
end | ||
end | ||
|
||
context "when an unexpected error occurs" do | ||
it "returns an empty hash and prints a warning" do | ||
allow(YAML).to receive(:load_file).and_raise(StandardError.new("Unexpected error")) | ||
expect { options_from_tebafile(tebafile) }.to output(/An unexpected error occurred/).to_stdout | ||
expect(options_from_tebafile(tebafile)).to eq({}) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com). | ||
# All rights reserved. | ||
# This file is a part of tebako | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS | ||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
require "tebako/cli_rubies" | ||
|
||
RSpec.describe Tebako::CliRubies do | ||
include Tebako::CliRubies | ||
|
||
describe "#version_check" do | ||
context "when the Ruby version is supported" do | ||
it "does not raise an error" do | ||
expect { version_check("3.1.6") }.not_to raise_error | ||
end | ||
end | ||
|
||
context "when the Ruby version is not supported" do | ||
it "raises a Tebako::Error" do | ||
expect do | ||
version_check("2.6.0") | ||
end.to raise_error(Tebako::Error, "Ruby version 2.6.0 is not supported yet, exiting") | ||
end | ||
end | ||
end | ||
|
||
describe "DEFAULT_RUBY_VERSION" do | ||
it "is set to 3.1.6" do | ||
expect(Tebako::CliRubies::DEFAULT_RUBY_VERSION).to eq("3.1.6") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com). | ||
# All rights reserved. | ||
# This file is a part of tebako | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS | ||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
RSpec.describe Tebako do # rubocop:disable Metrics/BlockLength | ||
describe "PACKAGING_ERRORS" do # rubocop:disable Metrics/BlockLength | ||
it "is defined" do | ||
expect(defined?(Tebako::PACKAGING_ERRORS)).to be_truthy | ||
end | ||
|
||
describe ".packaging_error" do | ||
it "raises the correct error for known error codes" do | ||
expect { Tebako.packaging_error(101) }.to raise_error(Tebako::Error, "'tebako setup' configure step failed") | ||
expect do | ||
Tebako.packaging_error(106) | ||
end.to raise_error(Tebako::Error, "Entry point does not exist or is not accessible") | ||
end | ||
|
||
it "raises a generic error message for unknown error codes" do | ||
expect { Tebako.packaging_error(999) }.to raise_error(Tebako::Error, "Unknown packaging error") | ||
end | ||
end | ||
|
||
describe "Error" do | ||
it "is defined" do | ||
expect(defined?(Tebako::Error)).to be_truthy | ||
end | ||
|
||
it "inherits from StandardError" do | ||
expect(Tebako::Error).to be < StandardError | ||
end | ||
|
||
it "can be instantiated" do | ||
expect { Tebako::Error.new }.not_to raise_error | ||
end | ||
|
||
it "initializes with the correct message and error code" do | ||
error = Tebako::Error.new("Custom error message", 123) | ||
expect(error.message).to eq("Custom error message") | ||
expect(error.error_code).to eq(123) | ||
end | ||
|
||
it "has an accessible and modifiable error_code attribute" do | ||
error = Tebako::Error.new | ||
error.error_code = 456 | ||
expect(error.error_code).to eq(456) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.