view_component/test/test_helper.rb

50 строки
1.2 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"
SimpleCov.start do
2020-07-27 23:46:40 +03:00
formatter SimpleCov::Formatter::Console
end
2020-07-28 00:02:08 +03:00
if ENV["RAILS_VERSION"] != "master"
2020-07-27 23:56:29 +03:00
SimpleCov.minimum_coverage 100
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