spec/appbundler/app_spec.rb in appbundler-0.3.0 vs spec/appbundler/app_spec.rb in appbundler-0.4.0
- old
+ new
@@ -1,6 +1,7 @@
require 'spec_helper'
+require 'tmpdir'
require 'fileutils'
require 'mixlib/shellout'
require 'appbundler/app'
describe Appbundler do
@@ -49,10 +50,12 @@
let!(:app_spec) do
double_spec(:app, "1.0.0", [:first_level_dep_a, :first_level_dep_b])
end
+ let(:bin_path) { File.join(target_bindir, "foo") }
+
let(:app_root) { "/opt/app/embedded/apps/app" }
let(:app) do
Appbundler::App.new(app_root, target_bindir)
end
@@ -90,21 +93,32 @@
expect(app.runtime_activate).to include(%q{gem "first_level_dep_b", "= 1.2.0"})
expect(app.runtime_activate).to include(%q{gem "second_level_dep_b_a", "= 2.2.0"})
expect(app.runtime_activate).to_not include(%q{gem "app"})
end
+ it "adds symlink resolution to the code that activates the app" do
+ symlink_code = <<-E
+bin_dir = File.dirname(__FILE__)
+if File.symlink?(__FILE__)
+ bin_dir = File.dirname(File.readlink(__FILE__))
+end
+E
+
+ expect(app.load_statement_for(bin_path)).to include(symlink_code)
+ end
+
it "adds the app code to the load path" do
# Our test setup makes an executable that needs to load a path in the
# fictitious /opt/app/embedded/apps/app/lib path, so the relative path
# will traverse all the way to the root and then back up. Therefore, the
# expected output is dependent on how many directories deep this source
# clone is from the root:
relpath_to_root = Pathname.new("/").relative_path_from(Pathname.new(File.dirname(__FILE__))).to_s
expected_code_path =
- %Q[$:.unshift(File.expand_path("#{relpath_to_root}/../opt/app/embedded/apps/app/lib", File.dirname(__FILE__)))]
- expect(app.runtime_activate).to include(expected_code_path)
+ %Q[$:.unshift(File.expand_path("#{relpath_to_root}/../opt/app/embedded/apps/app/lib", bin_dir))]
+ expect(app.load_statement_for(bin_path)).to include(expected_code_path)
end
it "generates code to override GEM_HOME and GEM_PATH (e.g., rvm)" do
expected = %Q{ENV["GEM_HOME"] = ENV["GEM_PATH"] = nil unless ENV["APPBUNDLER_ALLOW_RVM"] == "true"}
expect(app.env_sanitizer).to eq(expected)
@@ -205,18 +219,12 @@
gem "slop", "= 3.4.7"
gem "puma", "= 1.6.3"
gem "rest-client", "= 1.6.7"
E
expect(app.runtime_activate).to include(expected_gem_activates)
- expected_load_path = %q[$:.unshift(File.expand_path("../../fixtures/example-app/lib", File.dirname(__FILE__)))]
- expect(app.runtime_activate).to include(expected_load_path)
end
- it "should not contain exclude-me as a binary" do
- expect(app.executables).not_to include(File.join(app_root, "/bin", "exclude-me"))
- end
-
it "lists the app's executables" do
expected_executables = %w[app-binary-1 app-binary-2].map do |basename|
File.join(app_root, "/bin", basename)
end
expect(app.executables).to match_array(expected_executables)
@@ -232,26 +240,55 @@
expect(executable_content).to include(app.runtime_activate)
load_binary = executable_content.lines.to_a.last
- expected_load_path = %Q[Kernel.load(File.expand_path('../../fixtures/example-app/bin/app-binary-1', File.dirname(__FILE__)))\n]
+ expected_load_path = %Q[Kernel.load(File.expand_path('../../fixtures/example-app/bin/app-binary-1', bin_dir))\n]
expect(load_binary).to eq(expected_load_path)
end
it "generates executable stubs for all executables in the app" do
app.write_executable_stubs
binary_1 = File.join(target_bindir, "app-binary-1")
binary_2 = File.join(target_bindir, "app-binary-2")
- excluded_binary = File.join(target_bindir, "exclude-me")
expect(File.exist?(binary_1)).to be_true
expect(File.exist?(binary_2)).to be_true
- expect(File.exist?(excluded_binary)).to be_false
expect(File.executable?(binary_1)).to be_true
expect(File.executable?(binary_1)).to be_true
expect(shellout!(binary_1).stdout).to eq("binary 1 ran\n")
expect(shellout!(binary_2).stdout).to eq("binary 2 ran\n")
+ end
+
+ context "and the executable is symlinked to a different directory" do
+
+ let(:symlinks_root_dir) do
+ Dir.mktmpdir
+ end
+
+ let(:symlinks_bin_dir) do
+ d = File.join(symlinks_root_dir, "bin")
+ FileUtils.mkdir(d)
+ d
+ end
+
+ let(:binary_symlinked_path) { File.join(symlinks_bin_dir, "app-binary-1") }
+
+ let(:binary_orignal_path) { File.join(target_bindir, "app-binary-1") }
+
+ before do
+ app.write_executable_stubs
+ FileUtils.ln_s(binary_orignal_path, binary_symlinked_path)
+ end
+
+ after do
+ FileUtils.rm_rf(symlinks_root_dir)
+ end
+
+ it "correctly runs the executable via the symlinked executable" do
+ expect(shellout!(binary_symlinked_path).stdout).to eq("binary 1 ran\n")
+ end
+
end
context "on windows" do
let(:expected_ruby_relpath) do