Skip to content

Commit

Permalink
test: refactor gem packaging tests to address #215
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jan 10, 2025
1 parent 1f5a99f commit 00a41e6
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 25 deletions.
7 changes: 6 additions & 1 deletion lib/tebako/deploy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# require "bundler"
require "fileutils"
require "find"

Expand Down Expand Up @@ -92,7 +93,7 @@ def install_gem(name, ver = nil)

params = [@gem_command, "install", name.to_s]
params.push("-v", ver.to_s) if ver
["--no-document", "--install-dir", @tgd].each do |param|
["--no-document", "--install-dir", @tgd, "--bindir", @tbd].each do |param|
params.push(param)
end
BuildHelpers.run_with_capture_v(params)
Expand Down Expand Up @@ -146,6 +147,10 @@ def collect_and_deploy_gem(gemspec)
copy_files(@pre_dir)

Dir.chdir(@pre_dir) do
# spec = Bundler.load_gemspec(gemspec)
# puts spec.executables.first unless spec.executables.empty?
# puts spec.bindir

BuildHelpers.run_with_capture_v([@gem_command, "build", gemspec])
install_all_gems_or_fail
end
Expand Down
6 changes: 4 additions & 2 deletions spec/deploy_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@

before do
deploy_helper.instance_variable_set(:@tgd, "/path/to/tgd")
deploy_helper.instance_variable_set(:@tbd, "/path/to/tbd")
deploy_helper.instance_variable_set(:@gem_command, gem_command)
deploy_helper.instance_variable_set(:@bundler_command, bundler_command)
allow(Open3).to receive(:capture2e).and_return(["", double("status", signaled?: false, exitstatus: 0)])
Expand All @@ -363,15 +364,16 @@
it "installs the gem with the specified version" do
expect(Open3).to receive(:capture2e)
.with(gem_command, "install", gem_name, "-v", gem_version, "--no-document",
"--install-dir", "/path/to/tgd")
"--install-dir", "/path/to/tgd", "--bindir", "/path/to/tbd")
deploy_helper.install_gem(gem_name, gem_version)
end
end

context "when gem version is not provided" do
it "installs the gem without specifying the version" do
expect(Open3).to receive(:capture2e)
.with(gem_command, "install", gem_name, "--no-document", "--install-dir", "/path/to/tgd")
.with(gem_command, "install", gem_name, "--no-document",
"--install-dir", "/path/to/tgd", "--bindir", "/path/to/tbd")
deploy_helper.install_gem(gem_name)
end
end
Expand Down
8 changes: 8 additions & 0 deletions tests/scripts/functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ test_tebako_press_04() {
# 09. Ruby gem (xxx.gem, no gemspec, no gemfile)
test_tebako_press_09() {
echo "==> Ruby gem (xxx.gem, no gemspec, no gemfile)"

# Use test-11 gemspec to build a test gem
pushd "${DIR_TESTS}/test-11" > /dev/null || fail "pushd ${DIR_TESTS}/test-11 failed"
gem build tebako-test.gemspec -o "${DIR_TESTS}/test-09/tebako-test-0.0.2.gem"
popd > /dev/null || fail "popd failed"

press_runner_"${MODE}" "${DIR_TESTS}/test-09" "tebako-test-run.rb" "test-09-package"
package_runner_"${MODE}" "./test-09-package" "| a1 | b1 |"
}
Expand All @@ -263,6 +269,8 @@ test_tebako_press_10() {
else
rc=106
fi

# Use gem built for test-09
press_runner_with_error_"${MODE}" "${DIR_TESTS}/test-09" \
"test-does-not-exist.rb" \
"test-10-package" \
Expand Down
2 changes: 1 addition & 1 deletion tests/test-01/tebako-test-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
puts "Hello! This is test-01 talking from inside DwarFS"

puts "Gem path: #{Gem.path}"
puts "Rubygems version: #{Gem::rubygems_version}"
puts "Rubygems version: #{Gem.rubygems_version}"
if defined?(TebakoRuntime::VERSION)
puts "Using tebako-runtime v#{TebakoRuntime::VERSION}"
else
Expand Down
Binary file removed tests/test-09/tebako-test-0.0.1.gem
Binary file not shown.
Binary file added tests/test-09/tebako-test-0.0.2.gem
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "tebako-test"

begin
instance = TebakoTest.new
instance.run!
end
instance = Test::TebakoTest.new
instance.run
32 changes: 19 additions & 13 deletions tests/test-11/lib/tebako-test.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# frozen_string_literal: true

require "text-table"
require_relative "version"

# Tebako test class
class TebakoTest
def msg
table = Text::Table.new
table.head = %w[A B]
table.rows = [%w[a1 b1]]
table.rows << %w[a2 b2]
puts table
end
module Test
# Tebako test class
class TebakoTest
def msg
table = Text::Table.new
table.head = %w[A B]
table.rows = [%w[a1 b1]]
table.rows << %w[a2 b2]
table
end

def run
puts <<~MSG
Running packaged tebako-test gem version #{VERSION}.
You shall see a nice text table below.
def run!
puts "Hello! This is test-11 talking from inside DwarFS"
puts "You will now see a nice table that will be drawn for you by text-table gem."
msg
#{msg}
MSG
end
end
end
5 changes: 5 additions & 0 deletions tests/test-11/lib/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module Test
VERSION = "0.0.2"
end
7 changes: 4 additions & 3 deletions tests/test-11/tebako-test.gemspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# frozen_string_literal: true
require_relative "lib/version"

Gem::Specification.new do |s|
s.name = "tebako-test"
s.version = "0.0.1"
s.version = Test::VERSION
s.summary = "A simple gem for tebako testing"
s.authors = ["Ribose"]
s.email = ["[email protected]"]
s.files = ["bin/tebako-test-run.rb", "lib/tebako-test.rb"]
s.files = Dir.glob("lib/**/*") + Dir.glob("exe/**/*")
s.homepage = "https://github.com/tamitebako"
s.license = "Unlicense"
s.bindir = "bin"
s.bindir = "exe"
s.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
s.add_dependency "text-table", "~> 1.2.4"
s.executables << "tebako-test-run.rb"
Expand Down
1 change: 0 additions & 1 deletion tests/test-20/tebako-test-run.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true


puts "Hello! This is test-20 talking from inside DwarFS"

require "net/http"
Expand Down

0 comments on commit 00a41e6

Please sign in to comment.