Skip to content

Enable reloading in test environment #2256

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 21 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ require "yard/mattr_accessor_handler"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/sandbox/**/*_test.rb", "test/view_component/**/*_test.rb"]
t.test_files = FileList["test/sandbox/**/*_test.rb"]
end

Rake::TestTask.new(:engine_test) do |t|
Rake::TestTask.new(:test_rake) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/rake_test.rb"]
end

Rake::TestTask.new(:test_engine) do |t|
t.libs << "test/test_engine"
t.libs << "test/test_engine/lib"
t.test_files = FileList["test/test_engine/**/*_test.rb"]
Expand Down Expand Up @@ -100,7 +106,14 @@ namespace :docs do

error_keys = registry.keys.select { |key| key.to_s.include?("Error::MESSAGE") }.map(&:to_s)

docs = ActionController::Base.new.render_to_string(
require "action_controller/test_case"

request = ActionDispatch::TestRequest.create
request.session = ActionController::TestSession.new
controller = ActionController::Base.new
controller.request = request

docs = controller.render_to_string(
ViewComponent::DocsBuilderComponent.new(
sections: [
ViewComponent::DocsBuilderComponent::Section.new(
Expand Down Expand Up @@ -128,10 +141,12 @@ namespace :docs do
)
).chomp

File.open("docs/api.md", "w") do |f|
f.puts(docs)
if !ENV["RAILS_ENV"].present?
File.open("docs/api.md", "w") do |f|
f.puts(docs)
end
end
end
end

task default: [:test, :engine_test]
task default: [:test, :test_engine, :test_rake]
1 change: 0 additions & 1 deletion lib/view_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module ViewComponent
autoload :CaptureCompatibility
autoload :Compiler
autoload :CompileCache
autoload :ComponentError
autoload :Config
autoload :Deprecation
autoload :InlineTemplate
Expand Down
6 changes: 0 additions & 6 deletions lib/view_component/component_error.rb

This file was deleted.

18 changes: 18 additions & 0 deletions test/rake_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require "test_helper"
require "rake"

module ViewComponent
class RakeTest < TestCase
def test_statsetup_task
load "Rakefile"

assert_nothing_raised do
Rake::Task["docs:build"].invoke
end

Rake::Task.clear
end
end
end
2 changes: 1 addition & 1 deletion test/sandbox/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!

config.cache_classes = true
config.enable_reloading = false

# Show full error reports and disable caching
config.consider_all_requests_local = true
Expand Down
8 changes: 0 additions & 8 deletions test/sandbox/test/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,18 +433,10 @@ def test_validations_component
end

def test_compiles_unrendered_component
# The UnreferencedComponent will get compiled at boot,
# but that might have been thrown away if code-reloading is enabled
skip unless Rails.application.config.cache_classes

assert UnreferencedComponent.compiled?
end

def test_compiles_components_without_initializers
# MissingInitializerComponent will get compiled at boot,
# but that might have been thrown away if code-reloading is enabled
skip unless Rails.application.config.cache_classes

assert MissingInitializerComponent.compiled?
end

Expand Down
15 changes: 8 additions & 7 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
require "rails/version"

if ENV["MEASURE_COVERAGE"]
SimpleCov.start do
SimpleCov.start :rails do
command_name "minitest-rails#{Rails::VERSION::STRING}-ruby#{RUBY_VERSION}"

formatter SimpleCov::Formatter::Console
end
end

require "view_component/version"

ENV["RAILS_ENV"] = "test"
require File.expand_path("sandbox/config/environment.rb", __dir__)
require "rails/test_help"
# Rails.application.eager_load!

require "bundler/setup"
require "pathname"
require "minitest/autorun"
Expand All @@ -30,15 +37,9 @@ def self.warn(message)
end
end

# Configure Rails Environment
ENV["RAILS_ENV"] = "test"

require "view_component/deprecation"
ViewComponent::Deprecation.behavior = :silence

require File.expand_path("sandbox/config/environment.rb", __dir__)
require "rails/test_help"

require "capybara/cuprite"

# Rails registers its own driver named "cuprite" which will overwrite the one we
Expand Down
Loading