Skip to content

Commit

Permalink
Add CLI test for passing in options to ActiveRecordColumns compiler
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com>
  • Loading branch information
paracycle and Morriar committed May 1, 2024
1 parent aaa7e95 commit 4dc1368
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/spec_with_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def assert_project_file_equal(path, expected)
assert_equal(expected, @project.read(path))
end

# Assert that the contents of `path` inside `@project` includes `expected`
sig { params(path: String, expected: String).void }
def assert_project_file_includes(path, expected)
assert_includes(@project.read(path), expected)
end

# Assert that `path` exists inside `@project`
sig { params(path: String).void }
def assert_project_file_exist(path)
Expand Down
68 changes: 68 additions & 0 deletions spec/tapioca/cli/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,74 @@ class Application < Rails::Application
end
end
end

describe "options for built-in compilers" do
it "is able to pass 'untyped' to ActiveRecordColumns compiler" do
@project.write!("sorbet/tapioca/config.yml", <<~YAML)
dsl:
compiler_options:
ActiveRecordColumns:
types: untyped
YAML

@project.require_real_gem("activerecord")
@project.require_real_gem("sqlite3", "1.7.3")
@project.bundle_install!
@project.write!("lib/post.rb", <<~RB)
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Migration.suppress_messages do
ActiveRecord::Schema.define do
create_table :posts do |t|
end
end
end
class Post < ActiveRecord::Base
end
RB

result = @project.tapioca("dsl Post --only=ActiveRecordColumns")

assert_stdout_equals(<<~OUT, result)
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_includes("sorbet/rbi/dsl/post.rbi", <<~RBI)
class Post
include GeneratedAttributeMethods
module GeneratedAttributeMethods
sig { returns(T.untyped) }
def id; end
sig { params(value: T.untyped).returns(T.untyped) }
def id=(value); end
sig { returns(T::Boolean) }
def id?; end
RBI

assert_success_status(result)
end
end
end
end
end

0 comments on commit 4dc1368

Please sign in to comment.