Skip to content

Commit 3838cc7

Browse files
committed
Integration test for lock command
1 parent 0ab4d73 commit 3838cc7

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

src/commands/install.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module Shards
1717
solver.prepare(development: !Shards.production?)
1818

1919
if packages = solver.solve
20+
return if packages.empty?
21+
2022
if lockfile?
2123
validate(packages)
2224
end

src/commands/lock.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module Shards
2525
solver.prepare(development: !Shards.production?)
2626

2727
if packages = solver.solve
28+
return if packages.empty?
29+
2830
if print
2931
Shards::Lock.write(packages, STDOUT)
3032
else

test/integration/lock_test.cr

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
require "../integration_helper"
2+
3+
class LockCommandTest < Minitest::Test
4+
def test_fails_when_spec_is_missing
5+
Dir.cd(application_path) do
6+
ex = assert_raises(FailedCommand) { run "shards lock --no-color" }
7+
assert_match "Missing #{Shards::SPEC_FILENAME}", ex.stdout
8+
assert_match "Please run 'shards init'", ex.stdout
9+
end
10+
end
11+
12+
def test_doesnt_generate_lockfile_when_project_has_no_dependencies
13+
with_shard({name: "test"}) do
14+
run "shards lock"
15+
refute File.exists?(File.join(application_path, "shard.lock"))
16+
end
17+
end
18+
19+
def test_creates_lockfile
20+
metadata = {
21+
dependencies: {web: "*", orm: "*", foo: {path: rel_path(:foo)}},
22+
development_dependencies: {mock: "*"},
23+
}
24+
25+
with_shard(metadata) do
26+
run "shards lock"
27+
28+
# it locked dependencies (recursively):
29+
assert_locked "web", "2.1.0"
30+
assert_locked "orm", "0.5.0"
31+
assert_locked "pg", "0.2.1"
32+
33+
# it locked development dependencies (not recursively)
34+
assert_locked "mock", "0.1.0"
35+
refute_locked "minitest"
36+
37+
# it didn't install anything:
38+
refute_installed "web"
39+
refute_installed "orm"
40+
refute_installed "pg"
41+
refute_installed "foo"
42+
refute_installed "mock"
43+
refute_installed "shoulda"
44+
end
45+
end
46+
47+
def test_locks_is_consistent_with_lockfile
48+
metadata = {
49+
dependencies: {web: "*"},
50+
development_dependencies: {minitest: "~> 0.1"},
51+
}
52+
lock = {web: "1.0.0", minitest: "0.1.2"}
53+
54+
with_shard(metadata, lock) do
55+
run "shards lock"
56+
57+
assert_locked "web", "1.0.0"
58+
assert_locked "minitest", "0.1.2"
59+
end
60+
end
61+
62+
def test_locks_new_dependencies
63+
metadata = {dependencies: {web: "~> 1.0.0", orm: "*"}}
64+
lock = {web: "1.0.0"}
65+
66+
with_shard(metadata, lock) do
67+
run "shards lock"
68+
69+
assert_locked "web", "1.0.0"
70+
assert_locked "orm", "0.5.0"
71+
assert_locked "pg", "0.2.1"
72+
end
73+
end
74+
75+
def test_removes_dependencies
76+
metadata = {dependencies: {web: "~> 1.0.0"}}
77+
lock = {web: "1.0.0", orm: "0.5.0", pg: "0.2.1"}
78+
79+
with_shard(metadata, lock) do
80+
run "shards lock"
81+
82+
assert_locked "web", "1.0.0"
83+
refute_locked "orm", "0.5.0"
84+
refute_locked "pg", "0.2.1"
85+
end
86+
end
87+
88+
def test_updates_lockfile
89+
metadata = {
90+
dependencies: {web: "~> 1.0"},
91+
development_dependencies: {minitest: "~> 0.1"},
92+
}
93+
lock = {web: "1.0.0", minitest: "0.1.2"}
94+
95+
with_shard(metadata, lock) do
96+
run "shards lock --update"
97+
98+
assert_locked "web", "1.2.0"
99+
assert_locked "minitest", "0.1.3"
100+
end
101+
end
102+
end

0 commit comments

Comments
 (0)