view_component/test/test_helper.rb

58 строки
1.5 KiB
Ruby
Исходник Обычный вид История

2019-08-16 20:09:33 +03:00
# frozen_string_literal: true
require "simplecov"
2020-07-27 23:46:40 +03:00
require "simplecov-console"
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
end
2019-08-16 20:09:33 +03:00
require "bundler/setup"
require "pp"
require "pathname"
require "minitest/autorun"
# Configure Rails Envinronment
ENV["RAILS_ENV"] = "test"
require File.expand_path("../config/environment.rb", __FILE__)
2019-08-16 20:09:33 +03:00
require "rails/test_help"
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!
end
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
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
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