Skip to content

Commit 402eea6

Browse files
committed
Starting move back to running e2e specs right in Crystal
1 parent cac863f commit 402eea6

File tree

9 files changed

+147
-2
lines changed

9 files changed

+147
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "../spec_helper"
2+
3+
include WithProjectCleanup
4+
include ShouldRunSuccessfully
5+
6+
describe "Lucky CLI", tags: "end_to_end" do
7+
describe "building an API app without authentication" do
8+
it "generates the app and runs the included specs" do
9+
with_project_cleanup do
10+
should_run_successfully "crystal run src/lucky.cr -- init.custom test-project --api --no-auth"
11+
12+
FileUtils.cd "test-project" do
13+
should_run_successfully "crystal tool format --check spec src config"
14+
should_run_successfully "crystal script/setup.cr"
15+
should_run_successfully "crystal build src/test_project.cr"
16+
should_run_successfully "crystal spec"
17+
should_run_successfully "crystal run ../src/lucky.cr -- tasks"
18+
end
19+
end
20+
end
21+
end
22+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "../spec_helper"
2+
3+
include WithProjectCleanup
4+
include ShouldRunSuccessfully
5+
6+
describe "Lucky CLI", tags: "end_to_end" do
7+
describe "building an API app with authentication included" do
8+
it "generates the app and runs the included specs" do
9+
with_project_cleanup do
10+
should_run_successfully "crystal run src/lucky.cr -- init.custom test-project --api"
11+
12+
FileUtils.cd "test-project" do
13+
should_run_successfully "crystal tool format --check spec src config"
14+
should_run_successfully "crystal script/setup.cr"
15+
should_run_successfully "crystal build src/test_project.cr"
16+
should_run_successfully "crystal spec"
17+
should_run_successfully "crystal run ../src/lucky.cr -- tasks"
18+
end
19+
end
20+
end
21+
end
22+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "../spec_helper"
2+
3+
include WithProjectCleanup
4+
include ShouldRunSuccessfully
5+
6+
describe "Lucky CLI", tags: "end_to_end" do
7+
describe "building a full browser app without authentication" do
8+
it "generates the app and runs the included specs" do
9+
with_project_cleanup do
10+
should_run_successfully "crystal run src/lucky.cr -- init.custom test-project --no-auth"
11+
12+
FileUtils.cd "test-project" do
13+
should_run_successfully "crystal tool format --check spec src config"
14+
should_run_successfully "crystal script/setup.cr"
15+
should_run_successfully "crystal build src/test_project.cr"
16+
should_run_successfully "crystal spec"
17+
should_run_successfully "crystal run ../src/lucky.cr -- tasks"
18+
end
19+
end
20+
end
21+
end
22+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "../spec_helper"
2+
3+
include WithProjectCleanup
4+
include ShouldRunSuccessfully
5+
6+
describe "Lucky CLI", tags: "end_to_end" do
7+
describe "building a full browser app with authentication included" do
8+
it "generates the app and runs the included specs" do
9+
with_project_cleanup do
10+
should_run_successfully "crystal run src/lucky.cr -- init.custom test-project"
11+
12+
FileUtils.cd "test-project" do
13+
should_run_successfully "crystal tool format --check spec src config"
14+
should_run_successfully "crystal script/setup.cr"
15+
should_run_successfully "crystal build src/test_project.cr"
16+
should_run_successfully "crystal spec"
17+
should_run_successfully "crystal run ../src/lucky.cr -- tasks"
18+
end
19+
end
20+
end
21+
end
22+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "../spec_helper"
2+
3+
include WithProjectCleanup
4+
include ShouldRunSuccessfully
5+
6+
describe "Lucky CLI", tags: "end_to_end" do
7+
describe "building a full browser app with authentication and sec tester included" do
8+
it "generates the app and runs the included specs" do
9+
with_project_cleanup do
10+
should_run_successfully "crystal run src/lucky.cr -- init.custom test-project --with-sec-test"
11+
12+
FileUtils.cd "test-project" do
13+
should_run_successfully "crystal tool format --check spec src config"
14+
should_run_successfully "crystal script/setup.cr"
15+
should_run_successfully "crystal build src/test_project.cr"
16+
should_run_successfully "crystal spec"
17+
should_run_successfully "crystal run ../src/lucky.cr -- tasks"
18+
end
19+
end
20+
end
21+
end
22+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module ShouldRunSuccessfully
2+
private def should_run_successfully(command) : Nil
3+
result = Process.run(
4+
command,
5+
shell: true,
6+
env: ENV.to_h,
7+
output: STDOUT,
8+
error: STDERR
9+
)
10+
11+
result.exit_status.should be_successful
12+
end
13+
14+
private def be_successful
15+
eq 0
16+
end
17+
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module WithProjectCleanup
2+
private def with_project_cleanup(project_directory = "test-project", skip_db_drop = false, &) : Nil
3+
yield
4+
5+
FileUtils.cd(project_directory) {
6+
output = IO::Memory.new
7+
status = run_lucky(
8+
args: %w[db.drop],
9+
shell: true,
10+
output: output,
11+
)
12+
status.exit_code.should eq(0)
13+
output.to_s.should contain("Done dropping")
14+
} unless skip_db_drop
15+
ensure
16+
FileUtils.rm_rf project_directory
17+
end
18+
end

src/web_app_skeleton/config/server.cr.ecr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ end
6565
private def raise_missing_secret_key_in_production
6666
puts "Please set the SECRET_KEY_BASE environment variable. You can generate a secret key with 'lucky gen.secret_key'".colorize.red
6767
exit(1)
68-
end
68+
end

src/web_app_skeleton/src/app.cr.ecr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ require "./components/**"
3838
require "./pages/**"
3939
<%- end -%>
4040
require "../db/migrations/**"
41-
require "./app_server"
41+
require "./app_server"

0 commit comments

Comments
 (0)