2019-08-16 20:09:33 +03:00
|
|
|
# frozen_string_literal: true
|
2021-07-02 00:01:38 +03:00
|
|
|
|
2020-06-22 16:31:07 +03:00
|
|
|
require "simplecov"
|
2020-07-27 23:46:40 +03:00
|
|
|
require "simplecov-console"
|
2020-06-22 16:31:07 +03:00
|
|
|
|
2020-09-22 01:56:14 +03:00
|
|
|
if ENV["MEASURE_COVERAGE"]
|
2020-09-22 01:54:36 +03:00
|
|
|
SimpleCov.start do
|
|
|
|
command_name "rails#{ENV["RAILS_VERSION"]}-ruby#{ENV["RUBY_VERSION"]}" if ENV["RUBY_VERSION"]
|
2020-08-22 01:23:38 +03:00
|
|
|
|
2020-09-22 01:54:36 +03:00
|
|
|
formatter SimpleCov::Formatter::Console
|
|
|
|
end
|
2020-06-22 16:31:07 +03:00
|
|
|
end
|
|
|
|
|
2019-08-16 20:09:33 +03:00
|
|
|
require "bundler/setup"
|
|
|
|
require "pp"
|
|
|
|
require "pathname"
|
|
|
|
require "minitest/autorun"
|
|
|
|
|
2021-11-11 23:53:32 +03:00
|
|
|
# Configure Rails Environment
|
2020-07-02 09:39:25 +03:00
|
|
|
ENV["RAILS_ENV"] = "test"
|
|
|
|
|
2021-06-29 20:57:36 +03:00
|
|
|
require File.expand_path("../sandbox/config/environment.rb", __FILE__)
|
2019-08-16 20:09:33 +03:00
|
|
|
require "rails/test_help"
|
|
|
|
|
2021-02-17 04:36:40 +03:00
|
|
|
# Sets custom preview paths in tests.
|
|
|
|
#
|
|
|
|
# @param new_value [Array<String>] List of preview paths
|
|
|
|
# @yield Test code to run
|
|
|
|
# @return [void]
|
|
|
|
def with_preview_paths(new_value)
|
|
|
|
old_value = Rails.application.config.view_component.preview_paths
|
|
|
|
Rails.application.config.view_component.preview_paths = new_value
|
|
|
|
yield
|
|
|
|
Rails.application.config.view_component.preview_paths = old_value
|
|
|
|
end
|
|
|
|
|
2020-05-06 07:17:44 +03:00
|
|
|
def with_preview_route(new_value)
|
|
|
|
old_value = Rails.application.config.view_component.preview_route
|
|
|
|
Rails.application.config.view_component.preview_route = new_value
|
|
|
|
app.reloader.reload!
|
|
|
|
yield
|
|
|
|
Rails.application.config.view_component.preview_route = old_value
|
|
|
|
app.reloader.reload!
|
2019-12-09 19:07:12 +03:00
|
|
|
end
|
2020-06-11 06:32:00 +03:00
|
|
|
|
2020-10-04 04:33:05 +03:00
|
|
|
def with_preview_controller(new_value)
|
|
|
|
old_value = Rails.application.config.view_component.preview_controller
|
|
|
|
Rails.application.config.view_component.preview_controller = new_value
|
|
|
|
app.reloader.reload!
|
|
|
|
yield
|
|
|
|
Rails.application.config.view_component.preview_controller = old_value
|
|
|
|
app.reloader.reload!
|
|
|
|
end
|
|
|
|
|
2021-06-21 23:53:54 +03:00
|
|
|
def with_custom_component_path(new_value)
|
2021-06-29 18:37:05 +03:00
|
|
|
old_value = ViewComponent::Base.view_component_path
|
|
|
|
ViewComponent::Base.view_component_path = new_value
|
2021-06-21 23:53:54 +03:00
|
|
|
yield
|
2021-06-29 18:37:05 +03:00
|
|
|
ensure
|
|
|
|
ViewComponent::Base.view_component_path = old_value
|
2021-06-21 23:53:54 +03:00
|
|
|
end
|
|
|
|
|
2021-09-17 20:30:48 +03:00
|
|
|
def with_custom_component_parent_class(new_value)
|
|
|
|
old_value = ViewComponent::Base.component_parent_class
|
|
|
|
ViewComponent::Base.component_parent_class = new_value
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ViewComponent::Base.component_parent_class = old_value
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_application_component_class
|
|
|
|
Object.const_set("ApplicationComponent", Class.new(Object))
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
Object.send(:remove_const, :ApplicationComponent)
|
|
|
|
end
|
|
|
|
|
2021-05-10 17:52:19 +03:00
|
|
|
def with_new_cache
|
|
|
|
begin
|
|
|
|
old_cache = ViewComponent::CompileCache.cache
|
|
|
|
ViewComponent::CompileCache.cache = Set.new
|
2021-05-10 22:32:29 +03:00
|
|
|
old_cache_template_loading = ActionView::Base.cache_template_loading
|
2021-05-10 17:52:19 +03:00
|
|
|
ActionView::Base.cache_template_loading = false
|
|
|
|
|
|
|
|
yield
|
|
|
|
ensure
|
2021-05-10 22:32:29 +03:00
|
|
|
ActionView::Base.cache_template_loading = old_cache_template_loading
|
2021-05-10 17:52:19 +03:00
|
|
|
ViewComponent::CompileCache.cache = old_cache
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def without_template_annotations
|
2021-05-10 17:58:56 +03:00
|
|
|
if ActionView::Base.respond_to?(:annotate_rendered_view_with_filenames)
|
|
|
|
old_value = ActionView::Base.annotate_rendered_view_with_filenames
|
|
|
|
ActionView::Base.annotate_rendered_view_with_filenames = false
|
2021-12-17 01:44:25 +03:00
|
|
|
app.reloader.reload! if defined?(app)
|
2021-05-10 17:58:56 +03:00
|
|
|
|
|
|
|
with_new_cache do
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
|
|
|
ActionView::Base.annotate_rendered_view_with_filenames = old_value
|
2021-12-17 01:44:25 +03:00
|
|
|
app.reloader.reload! if defined?(app)
|
2021-05-10 17:58:56 +03:00
|
|
|
else
|
|
|
|
yield
|
|
|
|
end
|
2021-05-10 17:52:19 +03:00
|
|
|
end
|
|
|
|
|
2020-06-11 06:32:00 +03:00
|
|
|
def modify_file(file, content)
|
|
|
|
filename = Rails.root.join(file)
|
|
|
|
old_content = File.read(filename)
|
|
|
|
begin
|
|
|
|
File.open(filename, "wb+") { |f| f.write(content) }
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
File.open(filename, "wb+") { |f| f.write(old_content) }
|
|
|
|
end
|
|
|
|
end
|
2020-04-18 06:05:53 +03:00
|
|
|
|
|
|
|
def with_default_preview_layout(layout)
|
|
|
|
old_value = ViewComponent::Base.default_preview_layout
|
|
|
|
ViewComponent::Base.default_preview_layout = layout
|
|
|
|
yield
|
|
|
|
ViewComponent::Base.default_preview_layout = old_value
|
|
|
|
end
|
2020-08-01 18:14:57 +03:00
|
|
|
|
|
|
|
def with_render_monkey_patch_config(enabled)
|
|
|
|
old_default = ViewComponent::Base.render_monkey_patch_enabled
|
|
|
|
ViewComponent::Base.render_monkey_patch_enabled = enabled
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ViewComponent::Base.render_monkey_patch_enabled = old_default
|
|
|
|
end
|