Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rspec testing phase for the gem #3

Merged
merged 74 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
a117081
Add rspec testing phase for the gem
gtrias Aug 20, 2024
9515d4e
Adding Gemfile and rspec
gtrias Aug 20, 2024
12702af
adding the required gems
gtrias Aug 20, 2024
6ad9a63
fix all build errors
gtrias Aug 20, 2024
8b42686
wip
gtrias Aug 21, 2024
2268f94
fix resource_struct_build
gtrias Aug 21, 2024
8d86694
checking sorbet
gtrias Aug 21, 2024
63ce9bc
added tapioca
gtrias Aug 21, 2024
7cfaa4a
added tapioca and typechecks in the CI
gtrias Aug 21, 2024
4f7b76b
some more fixes
gtrias Aug 21, 2024
e8f30e5
fix all code sorbet issues
gtrias Aug 21, 2024
86a489f
remove broken rbis
gtrias Aug 21, 2024
0b27a66
fix versions tests
gtrias Aug 21, 2024
1f10851
no sorbet errors
gtrias Aug 21, 2024
1427e88
more fixing
gtrias Aug 21, 2024
2f220cf
include maybe_spec
gtrias Aug 21, 2024
85d25ac
trying to fix generic issues with maybe
gtrias Aug 21, 2024
8ea2aee
workaround to have sorbet passing while finding for the good solution
gtrias Aug 21, 2024
329d50e
define class methods
gtrias Aug 21, 2024
82c6acc
remove maybe implementation
gtrias Aug 21, 2024
178218a
fix requires
gtrias Aug 21, 2024
6472ca3
recover serializer
gtrias Aug 22, 2024
3da3043
removing a bunch of rbi todos
gtrias Aug 22, 2024
c50f545
recover maybe
gtrias Aug 22, 2024
4934a7b
add Guard and Maybe spec
gtrias Aug 22, 2024
2c231b0
fixing few tests
gtrias Aug 22, 2024
255575f
adding rbis
gtrias Aug 22, 2024
0ddd032
adding Maybe generic to rbis
gtrias Aug 22, 2024
b47b115
included rbi
gtrias Aug 22, 2024
16760e6
move more type definitions to rbi
gtrias Aug 22, 2024
241f42a
adapting RuntimeGeneric to be taken into account by Tapioca
gtrias Aug 23, 2024
3bcf446
bring missing OutputContext
gtrias Aug 23, 2024
79df779
remove things not belonging to RR
gtrias Aug 23, 2024
88d23e3
fix few more type errors
gtrias Aug 23, 2024
416ec5f
fix runtime_generic requires
gtrias Aug 26, 2024
65dd741
fix outcome impl
gtrias Aug 26, 2024
d5c3ebd
added RegistrySingleton
gtrias Aug 26, 2024
b99ace6
fix import
gtrias Aug 26, 2024
a75c9a6
remove singleton since it must be implemented by consumers
gtrias Aug 26, 2024
6dea8b7
fixing initializer class
gtrias Aug 26, 2024
d4d8dd1
fix entity finder
gtrias Aug 26, 2024
517971e
trying to fix runtime generic
gtrias Aug 27, 2024
aa15487
wip
gtrias Aug 27, 2024
5c83771
fixing type
gtrias Aug 27, 2024
b480b96
outcome is an interface
gtrias Aug 27, 2024
80f373b
add version
gtrias Sep 3, 2024
3b64499
add missing require
gtrias Sep 3, 2024
d2479d6
fix require
gtrias Sep 3, 2024
c2914c6
remove repository boilerplate and outcome usages
gtrias Sep 3, 2024
bcf5dfa
remove outcome from RR
gtrias Sep 3, 2024
6ac6d8d
fix broken imports
gtrias Sep 3, 2024
c00faf7
fix CapabilityFactory test with DI
gtrias Sep 6, 2024
c395453
fix Maybe tests
gtrias Sep 6, 2024
9c8aed0
remove sorbet-runtime-stub
gtrias Sep 9, 2024
241b00f
disable final! to integrate with f
gtrias Sep 9, 2024
0656952
simplify RuntimeGeneric
gtrias Sep 10, 2024
080e224
stop hacking T::Generic to test if that makes a difference
gtrias Sep 10, 2024
89110e6
recover runtimegeneric
gtrias Sep 10, 2024
e2852a7
add missing []
gtrias Sep 10, 2024
f53cdfc
strip tapioca support for runtime generic
gtrias Sep 10, 2024
fb48262
different approach to make runtime generic compatible with tapioca
gtrias Sep 10, 2024
a47c6d1
fix i18n specs
atd Sep 10, 2024
006fd7f
try to fix runtime_generic
gtrias Sep 10, 2024
63079f3
more tests
gtrias Sep 10, 2024
62d3ca2
tapioca don't like super
gtrias Sep 10, 2024
411c024
fix sorbet error
gtrias Sep 10, 2024
a6665b8
call super
gtrias Sep 10, 2024
254bf2e
wip
gtrias Sep 10, 2024
f19482d
hacking
gtrias Sep 10, 2024
60f6aa8
hack
gtrias Sep 10, 2024
97faa36
successfully hacking tapioca generic
gtrias Sep 10, 2024
8a9492d
Inject ResourceRegistry.configuration in Resource.load
atd Sep 10, 2024
e870090
Fix remaining resource specs
atd Sep 13, 2024
cd9df66
Add missing dto default value
atd Sep 13, 2024
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
23 changes: 23 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run tests
on:
push:
branches:
- "**" # matches every branch
jobs:
run-rspec-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
# Not needed with a .ruby-version file
ruby-version: 3.3.3
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true
- name: Run sorbet typechecks
run: |
bundle exec srb
- name: Run rspec tests
run: |
bundle exec rspec
14 changes: 14 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activesupport'
gem 'rspec'
gem 'rspec-json_expectations', require: true
gem 'rspec-sorbet', '~> 1.9.2'
gem 'sorbet-coerce', '>= 0.2.6'
gem 'sorbet-static-and-runtime', '>= 0.5.11511'
gem 'tapioca', '~> 0.15.1', require: false

gem 'guard'
gem 'guard-rspec'
132 changes: 132 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.2.0)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
base64 (0.2.0)
bigdecimal (3.1.8)
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
diff-lcs (1.5.1)
drb (2.2.1)
erubi (1.12.0)
ffi (1.17.0-x86_64-linux-gnu)
formatador (1.1.0)
guard (2.18.1)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.13.0)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.0)
lumberjack (1.2.10)
method_source (1.1.0)
minitest (5.25.1)
nenv (0.3.0)
netrc (0.11.0)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.23.0)
polyfill (1.9.0)
prism (0.30.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rbi (0.1.13)
prism (>= 0.18.0, < 1.0.0)
sorbet-runtime (>= 0.5.9204)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-json_expectations (2.2.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-sorbet (1.9.2)
sorbet-runtime
rspec-support (3.13.1)
safe_type (1.1.1)
securerandom (0.3.1)
shellany (0.0.1)
sorbet (0.5.11531)
sorbet-static (= 0.5.11531)
sorbet-coerce (0.7.0)
polyfill (~> 1.8)
safe_type (~> 1.1, >= 1.1.1)
sorbet-runtime (>= 0.4.4704)
sorbet-runtime (0.5.11531)
sorbet-static (0.5.11531-x86_64-linux)
sorbet-static-and-runtime (0.5.11531)
sorbet (= 0.5.11531)
sorbet-runtime (= 0.5.11531)
spoom (1.4.2)
erubi (>= 1.10.0)
prism (>= 0.28.0)
sorbet-static-and-runtime (>= 0.5.10187)
thor (>= 0.19.2)
tapioca (0.15.1)
bundler (>= 2.2.25)
netrc (>= 0.11.0)
parallel (>= 1.21.0)
rbi (>= 0.1.4, < 0.2)
sorbet-static-and-runtime (>= 0.5.11087)
spoom (>= 1.2.0)
thor (>= 1.2.0)
yard-sorbet
thor (1.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
yard (0.9.36)
yard-sorbet (0.9.0)
sorbet-runtime
yard

PLATFORMS
x86_64-linux

DEPENDENCIES
activesupport
guard
guard-rspec
rspec
rspec-json_expectations
rspec-sorbet (~> 1.9.2)
sorbet-coerce (>= 0.2.6)
sorbet-static-and-runtime (>= 0.5.11511)
tapioca (~> 0.15.1)

BUNDLED WITH
2.5.11
70 changes: 70 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)

# Feel free to open issues for suggestions and improvements

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)

# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

watch(rails.controllers) do |m|
[
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("acceptance/#{m[1]}")
]
end

# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }

# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
end
27 changes: 27 additions & 0 deletions bin/tapioca
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'tapioca' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("tapioca", "tapioca")
29 changes: 0 additions & 29 deletions lib/entity_finder.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/public/capabilities/capability_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ module CapabilityConfig

interface!

# Class methods interface for capability configuration
module ClassMethods
extend T::Sig
extend T::Helpers
abstract!

# The key of the capability, this key will be used to take it from yaml configuration
sig { abstract.returns(Symbol) }
def key; end
end
Expand Down
11 changes: 8 additions & 3 deletions lib/public/capability_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ module ResourceRegistry
class CapabilityFactory
extend T::Sig

sig { params(data: T::Hash[String, T.untyped]).returns(Capabilities::CapabilityConfig) }
def self.load(data)
sig do
params(
data: T::Hash[String, T.untyped],
capabilities: T::Hash[Symbol, T.all(T::Class[Capabilities::CapabilityConfig], T.class_of(T::Struct))]
).returns(Capabilities::CapabilityConfig)
end
def self.load(data, capabilities: ResourceRegistry.configuration.capabilities)
key = data['key']
capability = ResourceRegistry.configuration.capabilities.fetch(key.to_sym)
capability = capabilities.fetch(key.to_sym)
# FIXME: This T.let should not be needed
T.let(capability, T.class_of(T::Struct)).from_hash(data)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/public/context_creator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: strict
# typed: false

module ResourceRegistry
class ContextCreator
Expand Down
18 changes: 18 additions & 0 deletions lib/public/entity_finder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# typed: strict

module ResourceRegistry
class EntityFinder
extend T::Sig

sig do
params(repository: T.class_of(Repositories::Base)).returns(T.nilable(T.class_of(T::Struct)))
end
def self.call(repository:)
entity = repository.entity

return nil if entity.is_a?(T::Types::Untyped)

entity
end
end
end
4 changes: 2 additions & 2 deletions lib/public/infer_resources.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
# typed: strict
# typed: false

require_relative '../schema_generator'
require_relative 'repositories/base'
Expand All @@ -13,7 +13,7 @@ def initialize
@schema_generator = T.let(SchemaGenerator.new, SchemaGenerator)
end

sig { params(repositories: T::Array[ResourceRegistry::Repositories::Base]).returns(T::Array[Resource]) }
sig { params(repositories: T::Array[ResourceRegistry::Repositories::Base[T.untyped]]).returns(T::Array[Resource]) }
def call(repositories:)
repositories.filter_map { |repo| generate_resource_from_repository(repo) }
end
Expand Down
4 changes: 2 additions & 2 deletions lib/public/initializer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: strict
# typed: false

require_relative 'infer_resources'
require_relative 'overrides_loader'
Expand All @@ -13,7 +13,7 @@ module ResourceRegistry
class Initializer
extend T::Sig

sig { params(repository_base_klass: Class).void }
sig { params(repository_base_klass: T::Class[ResourceRegistry::Repositories::Base[T.untyped]]).void }
def initialize(repository_base_klass: ResourceRegistry::Repositories::Base)
@repository_base_klass = repository_base_klass
end
Expand Down
Loading
Loading