Skip to content

Commit

Permalink
Add failing test with a constant that implements hash
Browse files Browse the repository at this point in the history
If a constant implements `self.hash`, then Tapioca DSL compiler should be resilient against it.
  • Loading branch information
paracycle committed Dec 18, 2023
1 parent ffe63f4 commit f7970d8
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions spec/tapioca/cli/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,44 @@ def title=(title); end
end
end

it "generates RBI file for constants that might have overriden the hash method" do
@project.write!("lib/post.rb", <<~RB)
require "smart_properties"
class Post
include SmartProperties
property :title, accepts: String
def self.hash
raise "Cannot call `hash` on `Post`"
end
end
RB

result = @project.tapioca("dsl")

assert_equal(<<~OUT, result.out)
Loading DSL extension classes... Done
Loading Rails application... Done
Loading DSL compiler classes... Done
Compiling DSL RBI files...
create sorbet/rbi/dsl/post.rbi
Done
Checking generated RBI files... Done
No errors found
All operations performed in working directory.
Please review changes and commit them.
OUT

assert_empty_stderr(result)
assert_project_file_exist("sorbet/rbi/dsl/post.rbi")
assert_success_status(result)
end

it "generates RBI files in the correct output directory" do
@project.write!("lib/post.rb", <<~RB)
require "smart_properties"
Expand Down

0 comments on commit f7970d8

Please sign in to comment.