Skip to content

Commit

Permalink
Replace minitest.cr in favor of std-lib spec (crystal-lang#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian J. Cardiff committed Mar 23, 2020
1 parent 4cc61bf commit 6053248
Show file tree
Hide file tree
Showing 40 changed files with 1,401 additions and 1,490 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/lib
/bin/shards
/bin/shards.dwarf
/test/.repositories
/test/.shards
/test/.lib
/spec/.repositories
/spec/.shards
/spec/.lib
/tmp
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ uninstall: phony
test: test_unit test_integration

test_unit: phony
$(CRYSTAL) run test/*_test.cr
$(CRYSTAL) spec ./spec/unit/*_spec.cr

test_integration: bin/shards phony
$(CRYSTAL) run test/integration/*_test.cr
$(CRYSTAL) spec ./spec/integration/*_spec.cr

phony:
4 changes: 0 additions & 4 deletions shard.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
version: 1.0
shards:
minitest:
github: ysbaddaden/minitest.cr
version: 0.5.0

molinillo:
github: crystal-lang/crystal-molinillo
commit: 4b78e8c577ac322c8c0363788f3e1109f19668d9
Expand Down
5 changes: 0 additions & 5 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ dependencies:
molinillo:
github: crystal-lang/crystal-molinillo

development_dependencies:
minitest:
github: ysbaddaden/minitest.cr
version: ">= 0.5.0"

targets:
shards:
main: src/shards.cr
Expand Down
74 changes: 74 additions & 0 deletions spec/integration/build_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
require "./spec_helper"

private def bin_path(name)
File.join(application_path, "bin", name)
end

describe "build" do
before_each do
Dir.mkdir(File.join(application_path, "src"))
File.write(File.join(application_path, "src", "cli.cr"), "puts __FILE__")

Dir.mkdir(File.join(application_path, "src", "commands"))
File.write(File.join(application_path, "src", "commands", "check.cr"), "puts __LINE__")

File.write File.join(application_path, "shard.yml"), <<-YAML
name: build
version: 0.1.0
targets:
app:
main: src/cli.cr
alt:
main: src/cli.cr
check:
main: src/commands/check.cr
YAML
end

it "builds all targets" do
Dir.cd(application_path) do
run "shards build --no-color"

File.exists?(bin_path("app")).should be_true
File.exists?(bin_path("alt")).should be_true
File.exists?(bin_path("check")).should be_true

`#{bin_path("app")}`.chomp.should eq(File.join(application_path, "src", "cli.cr"))
`#{bin_path("alt")}`.chomp.should eq(File.join(application_path, "src", "cli.cr"))
`#{bin_path("check")}`.chomp.should eq("1")
end
end

it "builds specified targets" do
Dir.cd(application_path) do
run "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
end
end

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")
File.exists?(bin_path("app")).should be_true
File.exists?(bin_path("check")).should be_false
end
end

it "reports error when target failed to compile" 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 contain("unexpected token: ...")
File.exists?(bin_path("app")).should be_false
end
end
end
34 changes: 17 additions & 17 deletions test/integration/check_test.cr → spec/integration/check_spec.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "../integration_helper"
require "./spec_helper"

class CheckCommandTest < Minitest::Test
def test_succeeds_when_all_dependencies_are_installed
describe "check" do
it "succeeds when all dependencies are installed" do
metadata = {
dependencies: {web: "*", orm: "*"},
development_dependencies: {mock: "*"},
Expand All @@ -12,7 +12,7 @@ class CheckCommandTest < Minitest::Test
end
end

def test_succeeds_when_dependencies_match_loose_requirements
it "succeeds when dependencies match loose requirements" do
with_shard({dependencies: {web: "1.2.0"}}) do
run "shards install"
end
Expand All @@ -22,21 +22,21 @@ class CheckCommandTest < Minitest::Test
end
end

def test_fails_without_lockfile
it "fails without lockfile" do
with_shard({dependencies: {web: "*"}}) do
ex = assert_raises(FailedCommand) { run "shards check --no-color" }
assert_match "Missing #{Shards::LOCK_FILENAME}", ex.stdout
assert_empty ex.stderr
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
ex.stdout.should contain("Missing #{Shards::LOCK_FILENAME}")
ex.stderr.should be_empty
end
end

def test_succeeds_without_dependencies_and_lockfile
it "succeeds without dependencies and lockfile" do
with_shard({name: "no_dependencies"}) do
run "shards check --no-color"
end
end

def test_fails_when_dependencies_are_missing
it "fails when dependencies are missing" do
with_shard({dependencies: {web: "*"}}) do
run "shards install"
end
Expand All @@ -46,21 +46,21 @@ class CheckCommandTest < Minitest::Test
development_dependencies: {mock: "*"},
}
with_shard(metadata) do
ex = assert_raises(FailedCommand) { run "shards check --no-color" }
assert_match "Dependencies aren't satisfied", ex.stdout
assert_empty ex.stderr
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
ex.stdout.should contain("Dependencies aren't satisfied")
ex.stderr.should be_empty
end
end

def test_fails_when_wrong_versions_are_installed
it "fails when wrong versions are installed" do
with_shard({dependencies: {web: "1.0.0"}}) do
run "shards install"
end

with_shard({dependencies: {web: "2.0.0"}}) do
ex = assert_raises(FailedCommand) { run "shards check --no-color" }
assert_match "Dependencies aren't satisfied", ex.stdout
assert_empty ex.stderr
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
ex.stdout.should contain("Dependencies aren't satisfied")
ex.stderr.should be_empty
end
end
end
26 changes: 26 additions & 0 deletions spec/integration/init_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "./spec_helper"

private def shard_path
File.join(application_path, Shards::SPEC_FILENAME)
end

describe "init" do
it "creates shard.yml" do
Dir.cd(application_path) do
run "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")
spec.version.should eq("0.1.0")
end
end

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")
File.read(shard_path).should be_empty
end
end
end
Loading

0 comments on commit 6053248

Please sign in to comment.