Skip to content

Commit

Permalink
Fix some tests and things
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Medeiros committed Jul 6, 2020
1 parent 49f176b commit cfd6139
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 23 deletions.
4 changes: 2 additions & 2 deletions spec/dependencies/crystal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
versions, latest = versions_for :crystal

versions.each do |version|
it "installs version #{version} correctly" do
it "installs v#{version} correctly" do
test_dep 'crystal', version: version, match: version
end
end

it "installs version #{latest} as the default" do
it "installs v#{latest} as the default" do
test_dep 'crystal', match: latest
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/dependencies/golang_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
versions, latest = versions_for :golang

versions.each do |version|
it "installs version #{version} correctly" do
it "installs v#{version} correctly" do
test_dep 'golang', version: version, cmd: 'go version', match: version
end
end

it "installs version #{latest} as the default" do
it "installs v#{latest} as the default" do
test_dep 'golang', cmd: 'go version', match: latest
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/dependencies/memcached_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
versions, latest = versions_for :memcached

versions.each do |version|
it "installs version #{version} correctly" do
it "installs v#{version} correctly" do
test_dep 'memcached', version: version, match: version
end
end

it "installs version #{latest} as the default" do
it "installs v#{latest} as the default" do
test_dep 'memcached', match: latest
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/dependencies/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
versions, latest = versions_for :mysql

versions.each do |version|
it "installs version #{version} correctly" do
it "installs v#{version} correctly" do
test_dep 'mysql', version: version, match: version
end
end

it "installs version #{latest} as the default" do
it "installs v#{latest} as the default" do
test_dep 'mysql', match: latest
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/dependencies/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
versions, latest = versions_for :node

versions.each do |version|
it "installs version #{version} correctly" do
it "installs v#{version} correctly" do
test_dep 'node', version: version, match: version
end
end

it "installs version #{latest} as the default" do
it "installs v#{latest} as the default" do
test_dep 'node', match: latest
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/dependencies/postgres_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
versions, latest = versions_for :postgresql

versions.each do |version|
it "installs version #{version} correctly" do
it "installs v#{version} correctly" do
test_dep 'postgresql', cmd: 'psql --version', version: version, match: version
end
end

it "installs version #{latest} as the default" do
it "installs v#{latest} as the default" do
test_dep 'postgresql', cmd: 'psql --version', match: latest
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/dependencies/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
versions, latest = versions_for :redis

versions.each do |version|
it "installs version #{version} correctly" do
it "installs v#{version} correctly" do
test_dep 'redis', cmd: 'redis-cli --version', version: version, match: version
end
end

it "installs version #{latest} as the default" do
it "installs v#{latest} as the default" do
test_dep 'redis', cmd: 'redis-cli --version', match: latest
end
end
Expand Down
37 changes: 34 additions & 3 deletions spec/dependencies/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,43 @@
versions, latest = versions_for :ruby

versions.each do |version|
it "installs version #{version} correctly" do
test_dep 'ruby', version: version, match: version
describe "v#{version}" do
around(:each) do |example|
with_payload(deps: {'ruby' => version}) do |root|
@root = root
loon %w(up)

assert_stderr_empty
assert_status 0
example.run
end
end

it "installs correctly" do
loon %w(exec ruby --version)
assert_stdout version
end

it "sets the gem environment up" do
loon %w(exec env)
assert_stdout "GEM_HOME=#{@root}/.loon/data/gem"
assert_stdout "GEM_PATH=#{@root}/.loon/data/gem"
assert_stdout %r(PATH=.*#{@root}/.loon/data/gem/bin)
end

it "installs gems in the right location" do
loon %w(exec gem install rake)
assert_path "#{@root}/.loon/data/gem/bin/rake"
end

it "installs bundler" do
assert_path "#{@root}/.loon/data/gem/bin/bundle"
assert_path "#{@root}/.loon/data/gem/bin/bundler"
end
end
end

it "installs version #{latest} as the default" do
it "installs v#{latest} as the default" do
test_dep 'ruby', match: latest
end
end
Expand Down
22 changes: 16 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def assert_stderr_empty
end

def assert_stdout(str)
expect(@last_stdout).to include(str)
case str
when String then expect(@last_stdout).to include(str)
when Regexp then expect(@last_stdout).to match(str)
else raise "Not sure how to deal with #{str.class}"
end

end

def assert_finalizer(type, content = nil)
Expand All @@ -50,7 +55,7 @@ def assert_finalizer(type, content = nil)
end

def assert_path(path)
expect(Dir.exist?(path)).to be_truthy
expect(File.exist?(path)).to be_truthy
end
end

Expand All @@ -66,13 +71,15 @@ def test_dep(name, version: nil, cmd: nil, match:)
name
end

with_payload(deps: dep) do |project|
loon %w(up), dir: project
loon ['exec', cmd], dir: project
with_payload(deps: dep) do
loon %w(up)
loon ['exec', cmd]

assert_stderr_empty
assert_stdout match
assert_status 0
ensure
loon %(down)
end
end

Expand All @@ -90,7 +97,10 @@ def with_payload(name: "Test", url: "Test", deps: [], tasks: {})
File.open(File.join(tmpdir, 'loon.yml'), 'w') do |f|
f.write(yml)
end
@project_dir = tmpdir
yield tmpdir
ensure
@project_dir = nil
end
end

Expand Down Expand Up @@ -151,7 +161,7 @@ def loon(*args)
script.write <<~SH
__integration_test() {
exec 9>"#{finalizer.path}"
cd #{opts[:dir] || Dir.pwd}
cd #{opts[:dir] || @project_dir || Dir.pwd}
#{cmd}
ret=$?
exec 9<&-
Expand Down

0 comments on commit cfd6139

Please sign in to comment.