/
web_app_spec.rb
85 lines (68 loc) · 1.99 KB
/
web_app_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true
require "rack/test"
RSpec.describe "Hanami web app", :application_integration do
include Rack::Test::Methods
let(:app) { Hanami.app }
specify "Routing to actions based on their container identifiers" do
with_tmp_directory(Dir.mktmpdir) do
write "config/application.rb", <<~RUBY
require "hanami"
module TestApp
class Application < Hanami::Application
config.logger = {stream: File.new("/dev/null", "w")}
end
end
RUBY
write "config/routes.rb", <<~RUBY
module TestApp
class Routes < Hanami::Application::Routes
define do
slice :main, at: "/" do
root to: "home.index"
end
slice :admin, at: "/admin" do
get "/dashboard", to: "dashboard.show"
end
end
end
end
RUBY
write "lib/test_app/.keep", ""
write "slices/main/lib/actions/home/index.rb", <<~RUBY
require "hanami/action"
module Main
module Actions
module Home
class Index < Hanami::Action
def handle(*, res)
res.body = "Hello world"
end
end
end
end
end
RUBY
write "slices/admin/lib/actions/dashboard/show.rb", <<~RUBY
require "hanami/action"
module Admin
module Actions
module Dashboard
class Show < Hanami::Action
def handle(*, res)
res.body = "Admin dashboard here"
end
end
end
end
end
RUBY
require "hanami/boot"
get "/"
expect(last_response.status).to eq 200
expect(last_response.body).to eq "Hello world"
get "/admin/dashboard"
expect(last_response.status).to eq 200
expect(last_response.body).to eq "Admin dashboard here"
end
end
end