Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions spec/integration/build_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe "build" do

it "builds all targets" do
Dir.cd(application_path) do
run "shards build --no-color"
capture %w[shards build --no-color]

File.exists?(bin_path("app")).should be_true
File.exists?(bin_path("alt")).should be_true
Expand All @@ -41,7 +41,7 @@ describe "build" do

it "builds specified targets" do
Dir.cd(application_path) do
run "shards build --no-color alt check"
capture %w[shards build --no-color alt check]
File.exists?(bin_path("app")).should be_false
File.exists?(bin_path("alt")).should be_true
File.exists?(bin_path("check")).should be_true
Expand All @@ -50,10 +50,8 @@ describe "build" do

it "fails to build unknown target" do
Dir.cd(application_path) do
ex = expect_raises(FailedCommand) do
run "shards build --no-color app unknown check"
end
ex.stdout.should contain("target unknown was not found")
result = expect_failure(capture_result %w[shards build --no-color app unknown check])
result.stdout.should contain("target unknown was not found")
File.exists?(bin_path("app")).should be_true
File.exists?(bin_path("check")).should be_false
end
Expand All @@ -63,11 +61,9 @@ describe "build" do
File.write File.join(application_path, "src", "cli.cr"), "a = ......"

Dir.cd(application_path) do
ex = expect_raises(FailedCommand) do
run "shards build --no-color app"
end
ex.stdout.should contain("target app failed to compile")
ex.stdout.should match(/unexpected token: "?.../)
result = expect_failure(capture_result %w[shards build --no-color app])
result.stdout.should contain("target app failed to compile")
result.stdout.should match(/unexpected token: "?.../)
File.exists?(bin_path("app")).should be_false
end
end
Expand All @@ -81,8 +77,8 @@ describe "build" do
CODE

Dir.cd(application_path) do
err = run "shards build --no-color app", clear_env: true
err.should match(/eprecated/)
result = expect_success(capture_result %w[shards build --no-color app], clear_env: true)
result.stderr.should match(/eprecated/)
File.exists?(bin_path("app")).should be_true
end
end
Expand All @@ -94,10 +90,8 @@ describe "build" do
YAML

Dir.cd(application_path) do
ex = expect_raises(FailedCommand) do
run "shards build --no-color"
end
ex.stdout.should contain("Targets not defined in shard.yml")
result = expect_failure(capture_result %w[shards build --no-color])
result.stdout.should contain("Targets not defined in shard.yml")
File.exists?(bin_path("")).should be_false
end
end
Expand Down
52 changes: 26 additions & 26 deletions spec/integration/check_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,60 @@ describe "check" do
development_dependencies: {mock: "*"},
}
with_shard(metadata) do
run "shards install"
run "shards check"
capture %w[shards install]
capture %w[shards check]
end
end

it "succeeds when dependencies match loose requirements" do
with_shard({dependencies: {web: "1.2.0"}}) do
run "shards install"
capture %w[shards install]
end

with_shard({dependencies: {web: "~> 1.1"}}) do
run "shards check"
capture %w[shards check]
end
end

it "fails without lockfile" do
with_shard({dependencies: {web: "*"}}) do
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
ex.stdout.should contain("Missing #{Shards::LOCK_FILENAME}")
ex.stderr.should be_empty
result = expect_failure(capture_result %w[shards check --no-color])
result.stdout.should contain("Missing #{Shards::LOCK_FILENAME}")
result.stderr.should be_empty
end
end

it "succeeds without dependencies and lockfile" do
with_shard({name: "no_dependencies"}) do
run "shards check --no-color"
capture %w[shards check --no-color]
end
end

it "fails when dependencies are missing" do
with_shard({dependencies: {web: "*"}}) do
run "shards install"
capture %w[shards install]
end

metadata = {
dependencies: {web: "*", orm: "*"},
development_dependencies: {mock: "*"},
}
with_shard(metadata) do
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
ex.stdout.should contain("Dependencies aren't satisfied")
ex.stderr.should be_empty
result = expect_failure(capture_result %w[shards check --no-color])
result.stdout.should contain("Dependencies aren't satisfied")
result.stderr.should be_empty
end
end

it "fails when wrong versions are installed" do
with_shard({dependencies: {web: "1.0.0"}}) do
run "shards install"
capture %w[shards install]
end

with_shard({dependencies: {web: "2.0.0"}}) do
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
ex.stdout.should contain("Dependencies aren't satisfied")
ex.stderr.should be_empty
result = expect_failure(capture_result %w[shards check --no-color])
result.stdout.should contain("Dependencies aren't satisfied")
result.stderr.should be_empty
end
end

Expand All @@ -71,36 +71,36 @@ describe "check" do
},
}
with_shard(metadata) do
run "shards install"
run "shards check"
capture %w[shards install]
capture %w[shards check]
end
end

it "fails when another source was installed" do
with_shard({dependencies: {awesome: "0.1.0"}}) do
run "shards install"
capture %w[shards install]
end

with_shard({dependencies: {awesome: {git: git_url(:forked_awesome)}}}) do
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
ex.stdout.should contain("Dependencies aren't satisfied")
ex.stderr.should be_empty
result = expect_failure(capture_result %w[shards check --no-color])
result.stdout.should contain("Dependencies aren't satisfied")
result.stderr.should be_empty
end
end

it "fails when override changes version to use" do
metadata = {dependencies: {awesome: "0.1.0"}}

with_shard(metadata) do
run "shards install"
capture %w[shards install]
end

override = {dependencies: {awesome: "0.2.0"}}

with_shard(metadata, nil, override) do
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
ex.stdout.should contain("Dependencies aren't satisfied")
ex.stderr.should be_empty
result = expect_failure(capture_result %w[shards check --no-color])
result.stdout.should contain("Dependencies aren't satisfied")
result.stderr.should be_empty
end
end
end
8 changes: 4 additions & 4 deletions spec/integration/help_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ describe "--help" do
}

[
"shards --help",
"shards --local --help",
"shards update --help",
%w[shards --help],
%w[shards --local --help],
%w[shards update --help],
].each do |command|
with_shard(metadata) do
output = run command
output = capture command

# it printed the help message
output.should contain("Commands:")
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/init_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end
describe "init" do
it "creates shard.yml" do
Dir.cd(application_path) do
run "shards init"
capture %w[shards init]
File.exists?(File.join(application_path, Shards::SPEC_FILENAME)).should be_true
spec = Shards::Spec.from_file(shard_path)
spec.name.should eq("integration")
Expand All @@ -18,8 +18,8 @@ describe "init" do
it "won't overwrite shard.yml" do
Dir.cd(application_path) do
File.write(shard_path, "")
ex = expect_raises(FailedCommand) { run "shards init --no-color" }
ex.stdout.should contain("#{Shards::SPEC_FILENAME} already exists")
result = expect_failure(capture_result %w[shards init --no-color])
result.stdout.should contain("#{Shards::SPEC_FILENAME} already exists")
File.read(shard_path).should be_empty
end
end
Expand Down
Loading
Loading