Skip to content

Commit 521ce3b

Browse files
author
Brian J. Cardiff
authored
Replace minitest.cr in favor of std-lib spec (#334)
1 parent aed6390 commit 521ce3b

40 files changed

+1401
-1490
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/lib
44
/bin/shards
55
/bin/shards.dwarf
6-
/test/.repositories
7-
/test/.shards
8-
/test/.lib
6+
/spec/.repositories
7+
/spec/.shards
8+
/spec/.lib
99
/tmp

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ uninstall: phony
3636
test: test_unit test_integration
3737

3838
test_unit: phony
39-
$(CRYSTAL) run test/*_test.cr
39+
$(CRYSTAL) spec ./spec/unit/*_spec.cr
4040

4141
test_integration: bin/shards phony
42-
$(CRYSTAL) run test/integration/*_test.cr
42+
$(CRYSTAL) spec ./spec/integration/*_spec.cr
4343

4444
phony:

shard.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
version: 1.0
22
shards:
3-
minitest:
4-
github: ysbaddaden/minitest.cr
5-
version: 0.5.0
6-
73
molinillo:
84
github: crystal-lang/crystal-molinillo
95
commit: 4b78e8c577ac322c8c0363788f3e1109f19668d9

shard.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ dependencies:
88
molinillo:
99
github: crystal-lang/crystal-molinillo
1010

11-
development_dependencies:
12-
minitest:
13-
github: ysbaddaden/minitest.cr
14-
version: ">= 0.5.0"
15-
1611
targets:
1712
shards:
1813
main: src/shards.cr

spec/integration/build_spec.cr

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require "./spec_helper"
2+
3+
private def bin_path(name)
4+
File.join(application_path, "bin", name)
5+
end
6+
7+
describe "build" do
8+
before_each do
9+
Dir.mkdir(File.join(application_path, "src"))
10+
File.write(File.join(application_path, "src", "cli.cr"), "puts __FILE__")
11+
12+
Dir.mkdir(File.join(application_path, "src", "commands"))
13+
File.write(File.join(application_path, "src", "commands", "check.cr"), "puts __LINE__")
14+
15+
File.write File.join(application_path, "shard.yml"), <<-YAML
16+
name: build
17+
version: 0.1.0
18+
targets:
19+
app:
20+
main: src/cli.cr
21+
alt:
22+
main: src/cli.cr
23+
check:
24+
main: src/commands/check.cr
25+
YAML
26+
end
27+
28+
it "builds all targets" do
29+
Dir.cd(application_path) do
30+
run "shards build --no-color"
31+
32+
File.exists?(bin_path("app")).should be_true
33+
File.exists?(bin_path("alt")).should be_true
34+
File.exists?(bin_path("check")).should be_true
35+
36+
`#{bin_path("app")}`.chomp.should eq(File.join(application_path, "src", "cli.cr"))
37+
`#{bin_path("alt")}`.chomp.should eq(File.join(application_path, "src", "cli.cr"))
38+
`#{bin_path("check")}`.chomp.should eq("1")
39+
end
40+
end
41+
42+
it "builds specified targets" do
43+
Dir.cd(application_path) do
44+
run "shards build --no-color alt check"
45+
File.exists?(bin_path("app")).should be_false
46+
File.exists?(bin_path("alt")).should be_true
47+
File.exists?(bin_path("check")).should be_true
48+
end
49+
end
50+
51+
it "fails to build unknown target" do
52+
Dir.cd(application_path) do
53+
ex = expect_raises(FailedCommand) do
54+
run "shards build --no-color app unknown check"
55+
end
56+
ex.stdout.should contain("target unknown was not found")
57+
File.exists?(bin_path("app")).should be_true
58+
File.exists?(bin_path("check")).should be_false
59+
end
60+
end
61+
62+
it "reports error when target failed to compile" do
63+
File.write File.join(application_path, "src", "cli.cr"), "a = ......"
64+
65+
Dir.cd(application_path) do
66+
ex = expect_raises(FailedCommand) do
67+
run "shards build --no-color app"
68+
end
69+
ex.stdout.should contain("target app failed to compile")
70+
ex.stdout.should contain("unexpected token: ...")
71+
File.exists?(bin_path("app")).should be_false
72+
end
73+
end
74+
end
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
require "../integration_helper"
1+
require "./spec_helper"
22

3-
class CheckCommandTest < Minitest::Test
4-
def test_succeeds_when_all_dependencies_are_installed
3+
describe "check" do
4+
it "succeeds when all dependencies are installed" do
55
metadata = {
66
dependencies: {web: "*", orm: "*"},
77
development_dependencies: {mock: "*"},
@@ -12,7 +12,7 @@ class CheckCommandTest < Minitest::Test
1212
end
1313
end
1414

15-
def test_succeeds_when_dependencies_match_loose_requirements
15+
it "succeeds when dependencies match loose requirements" do
1616
with_shard({dependencies: {web: "1.2.0"}}) do
1717
run "shards install"
1818
end
@@ -22,21 +22,21 @@ class CheckCommandTest < Minitest::Test
2222
end
2323
end
2424

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

33-
def test_succeeds_without_dependencies_and_lockfile
33+
it "succeeds without dependencies and lockfile" do
3434
with_shard({name: "no_dependencies"}) do
3535
run "shards check --no-color"
3636
end
3737
end
3838

39-
def test_fails_when_dependencies_are_missing
39+
it "fails when dependencies are missing" do
4040
with_shard({dependencies: {web: "*"}}) do
4141
run "shards install"
4242
end
@@ -46,21 +46,21 @@ class CheckCommandTest < Minitest::Test
4646
development_dependencies: {mock: "*"},
4747
}
4848
with_shard(metadata) do
49-
ex = assert_raises(FailedCommand) { run "shards check --no-color" }
50-
assert_match "Dependencies aren't satisfied", ex.stdout
51-
assert_empty ex.stderr
49+
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
50+
ex.stdout.should contain("Dependencies aren't satisfied")
51+
ex.stderr.should be_empty
5252
end
5353
end
5454

55-
def test_fails_when_wrong_versions_are_installed
55+
it "fails when wrong versions are installed" do
5656
with_shard({dependencies: {web: "1.0.0"}}) do
5757
run "shards install"
5858
end
5959

6060
with_shard({dependencies: {web: "2.0.0"}}) do
61-
ex = assert_raises(FailedCommand) { run "shards check --no-color" }
62-
assert_match "Dependencies aren't satisfied", ex.stdout
63-
assert_empty ex.stderr
61+
ex = expect_raises(FailedCommand) { run "shards check --no-color" }
62+
ex.stdout.should contain("Dependencies aren't satisfied")
63+
ex.stderr.should be_empty
6464
end
6565
end
6666
end

spec/integration/init_spec.cr

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require "./spec_helper"
2+
3+
private def shard_path
4+
File.join(application_path, Shards::SPEC_FILENAME)
5+
end
6+
7+
describe "init" do
8+
it "creates shard.yml" do
9+
Dir.cd(application_path) do
10+
run "shards init"
11+
File.exists?(File.join(application_path, Shards::SPEC_FILENAME)).should be_true
12+
spec = Shards::Spec.from_file(shard_path)
13+
spec.name.should eq("integration")
14+
spec.version.should eq("0.1.0")
15+
end
16+
end
17+
18+
it "won't overwrite shard.yml" do
19+
Dir.cd(application_path) do
20+
File.write(shard_path, "")
21+
ex = expect_raises(FailedCommand) { run "shards init --no-color" }
22+
ex.stdout.should contain("#{Shards::SPEC_FILENAME} already exists")
23+
File.read(shard_path).should be_empty
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)