Files
ubicloud/clover.rb
Jeremy Evans 8ad5ae3024 Run all specs in frozen mode
This introduces ThawedMock, which allows the specs to work in frozen
mode. With ThawedMock, you register all methods on the frozen objects
you plan to mock, and it redefines the methods to call methods on
an unfrozen mocked object.  That mocked object then calls the super
method of the method on the original object.  When you use:

```ruby
  expect(obj).to receive(:method)
```

ThawedMock replaces obj with the unfrozen mocked object, so it redefines
the method on the mocked object without raising an error.

If you want to mock additional methods on classes, you need to update
spec/thawed_mock.rb to add a line such as:

```
  allow_mocking(Klass, :method1, :method2, ...)
```

If there is already a line for the class, you just add the method as
an additional argument on the line for the class.

Since all specs can now run in frozen mode, there is no point in
having separate rake tasks to run just frozen core specs and with just
frozen Database and models specs.  Remove those, and combine the
CLOVER_FREEZE_CORE and CLOVER_FREEZE_MODELS environment variables
into CLOVER_FREEZE.

I found after doing this that I also needed to require diff/lcs
to avoid rspec breaking in frozen mode.

This needed a small tweak in strand_spec, to get the correct method,
as `DB.method(:[])` now returns the method that delegates to the
mock object, and not the actual implementation.
2024-10-30 12:08:24 -07:00

41 lines
671 B
Ruby

# frozen_string_literal: true
require_relative "model"
require "roda"
class Clover < Roda
def self.freeze
# :nocov:
if Config.test? && ENV["CLOVER_FREEZE"] != "1"
Sequel::Model.descendants.each(&:finalize_associations)
else
Sequel::Model.freeze_descendants
DB.freeze
end
# :nocov:
super
end
route do |r|
if r.host.start_with?("api.")
r.run CloverApi
end
# To make test and development easier
# :nocov:
unless Config.production?
r.on "api" do
r.run CloverApi
end
end
# :nocov:
r.on "runtime" do
r.run CloverRuntime
end
r.run CloverWeb
end
end