Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ gem "kramdown", "~> 2.5"
gem "minitest", "~> 5.16"

gem "rbs-inline", require: false
gem "sorbet", require: false
gem "sorbet-runtime"
gem "rubocop-rails-omakase"
36 changes: 36 additions & 0 deletions TYPE_CHECKING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Type Checking with RBS Inline and Sorbet

This project uses a combination of RBS inline annotations and Sorbet for type checking.

## RBS Inline

Type annotations in the `lib/` directory use RBS inline format with `#:` comments.

To generate RBS files from inline annotations:
```bash
bundle exec rbs-inline lib --output sig/generated
```

## Sorbet

The Sorbet gem is available for additional type checking capabilities.

### Setup

Initialize Sorbet (if not already done):
```bash
bundle exec srb init
```

### Type Checking

Run Sorbet type checker:
```bash
bundle exec srb tc
```

## Workflow

1. Write code with RBS inline annotations in `lib/` files
2. Generate RBS files: `bundle exec rbs-inline lib --output sig/generated`
3. Run type checking as needed with Sorbet
4 changes: 4 additions & 0 deletions sorbet/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--dir
.
--ignore=/test/
--ignore=/sig/
2 changes: 0 additions & 2 deletions test/integration/dev_server/test_hot_reloading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

class TestHotReloading < Minitest::Test
@@setup_done = false
#: () -> Integer
def setup
return if @@setup_done

Expand All @@ -29,7 +28,6 @@ def setup
end
end

#: () -> nil
def test_sse_broadcasting
client_socket = TCPSocket.new("localhost", @@port)

Expand Down
10 changes: 0 additions & 10 deletions test/integration/dev_server/test_serving.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
class TestServing < Minitest::Test
@@setup_done = false

#: () -> Integer?
def setup
return if @@setup_done

Expand Down Expand Up @@ -36,7 +35,6 @@ def setup
end
end

#: () -> Array[untyped]
def test_serves_all_pages
Dir.glob(Hotpages.site.dist_path.join("**/*")).each do |file|
next if File.directory?(file)
Expand All @@ -49,37 +47,32 @@ def test_serves_all_pages
end
end

#: () -> bool
def test_serves_404_page_for_non_existent_page
uri = URI("http://localhost:#{@@port}/not-exist")
res = Net::HTTP.get_response(uri)
assert_equal "404", res.code, "Failed to serve /not-exist"
end

#: () -> bool
def test_serves_without_file_extension
uri = URI("http://localhost:#{@@port}/posts/1/bar/index")
res = Net::HTTP.get_response(uri)
assert_equal "200", res.code, "Failed to serve /posts/1/bar/index"
assert_page_content "posts/1/bar/index.html", res.body
end

#: () -> bool
def test_serves_index_without_filename
uri = URI("http://localhost:#{@@port}/posts/1/bar/")
res = Net::HTTP.get_response(uri)
assert_equal "200", res.code, "Failed to serve /posts/1/bar/"
assert_page_content "posts/1/bar/index.html", res.body
end

#: () -> bool
def test_not_serves_txt_without_file_extension
uri = URI("http://localhost:#{@@port}/robot")
res = Net::HTTP.get_response(uri)
assert_equal "404", res.code, "Should not serve /robot.txt without extension"
end

#: () -> bool
def test_not_serves_ignored_path
uri = URI("http://localhost:#{@@port}/products/_page")
res = Net::HTTP.get_response(uri)
Expand All @@ -90,14 +83,12 @@ def test_not_serves_ignored_path
assert_equal "404", res.code, "Should not serve /products/_product"
end

#: () -> bool
def test_not_serves_directory_without_trailing_slash
uri = URI("http://localhost:#{@@port}/posts/1/bar")
res = Net::HTTP.get_response(uri)
assert_equal "404", res.code, "Should not serve /posts/1/bar without trailing slash"
end

#: () -> bool
def test_serves_non_html
uri = URI("http://localhost:#{@@port}/sitemap.xml")
res = Net::HTTP.get_response(uri)
Expand All @@ -107,7 +98,6 @@ def test_serves_non_html

private

#: (String, String) -> bool
def assert_page_content(expected_path, actual_content)
actual_content = actual_content.force_encoding("UTF-8").encode("UTF-8")
expected_content = File.read(Hotpages.site.dist_path.join(expected_path.delete_prefix("/")))
Expand Down
2 changes: 0 additions & 2 deletions test/integration/site_generator/test_generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require "digest"

class TestGeneration < Minitest::Test
#: () -> Integer
def setup
pid = fork do
Hotpages.extensions += [
Expand All @@ -16,7 +15,6 @@ def setup
Process.wait(pid)
end

#: () -> Array[untyped]
def test_site_generation
expected_dist = File.join(__dir__, "../../dist/expected")
actual_dist = Hotpages.site.dist_path.to_s
Expand Down
4 changes: 0 additions & 4 deletions test/lib/hotpages/support/test_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ class TestCache < Minitest::Test
Entry = Hotpages::Support::Cache::Entry
Store = Hotpages::Support::Cache::Store

#: () -> bool
def test_entry_content_of_with_newer_version
entry = Entry.new(version: 2, content: "cached content")

assert_equal "cached content", entry.content_of(1)
assert_equal "cached content", entry.content_of(2)
end

#: () -> bool
def test_entry_content_of_with_older_version
entry = Entry.new(version: 1, content: "cached content")

assert_nil entry.content_of(2)
end

#: () -> bool
def test_entry_content_of_with_nil_version
entry = Entry.new(version: nil, content: "cached content")

Expand All @@ -31,7 +28,6 @@ def test_entry_content_of_with_nil_version
assert_equal "cached content", entry.content_of(0)
end

#: () -> bool
def test_store_fetch
store = Store.new
key = "test cache key"
Expand Down
2 changes: 0 additions & 2 deletions test/lib/hotpages/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class TestConfig < Minitest::Test
Config = Hotpages::Config

#: () -> Hotpages::Config
def setup
@defaults = {
foo: "foo",
Expand All @@ -15,7 +14,6 @@ def setup
@config = Hotpages::Config.new(@defaults)
end

#: () -> bool
def test_singleton_methods
assert_respond_to @config, :foo
assert_equal "foo", @config.foo
Expand Down
10 changes: 0 additions & 10 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "hotpages"
require "rbs"
require "rbs/trace"

trace = RBS::Trace.new
trace.enable

# Fix the last modified date of the page to prevent failures
# during tests due to changes in CI, etc.
Expand All @@ -29,8 +24,3 @@ class TestSite < Hotpages::Site
Minitest.after_run do
Hotpages.teardown
end

Minitest.after_run do
trace.disable
trace.save_comments
end