Skip to content
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

Fix test suite for Rails 7 #178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Run test cases in separate test directories
This is in preparation to be able to run the tests in isolation, because
recent versions of Rails does not allow multiple to calls to
`initialize!`.
  • Loading branch information
voxik committed Feb 27, 2023
commit 9b653021e7a5a192758968a81b0dc81c68f298d0
15 changes: 9 additions & 6 deletions test/sassc_rails_test.rb
Original file line number Diff line number Diff line change
@@ -4,14 +4,18 @@

class SassRailsTest < MiniTest::Test
attr_reader :app
attr_reader :test_dir

def setup
Rails.application = nil

@test_dir = Dir.mktmpdir("sassc-rails")
FileUtils.cp_r File.join(File.dirname(__FILE__), "dummy"), test_dir

@app = Class.new(Rails::Application)
@app.config.active_support.deprecation = :log
@app.config.eager_load = false
@app.config.root = File.join(File.dirname(__FILE__), "dummy")
@app.config.root = File.join(test_dir, "dummy")
@app.config.log_level = :debug

# reset config back to default
@@ -30,8 +34,7 @@ def setup
end

def teardown
directory = "#{Rails.root}/tmp"
FileUtils.remove_dir(directory) if File.directory?(directory)
FileUtils.remove_dir(test_dir) if File.directory?(test_dir)
end

def render_asset(asset)
@@ -169,7 +172,7 @@ def test_line_comments_active_in_dev

css_output = render_asset("css_scss_handler.css")
assert_match %r{/* line 1}, css_output
assert_match %r{.+test/dummy/app/assets/stylesheets/css_scss_handler.css.scss}, css_output
assert_match %r{.+#{test_dir}/dummy/app/assets/stylesheets/css_scss_handler.css.scss}, css_output
end

def test_context_is_being_passed_to_erb_render
@@ -287,7 +290,7 @@ def test_globbed_imports_work_when_globbed_file_is_changed
begin
initialize!

new_file = File.join(File.dirname(__FILE__), 'dummy', 'app', 'assets', 'stylesheets', 'globbed', 'new_glob.scss')
new_file = File.join(test_dir, 'dummy', 'app', 'assets', 'stylesheets', 'globbed', 'new_glob.scss')

File.open(new_file, 'w') do |file|
file.puts '.new-file-test { color: #000; }'
@@ -314,7 +317,7 @@ def test_globbed_imports_work_when_globbed_file_is_added

css_output = render_asset("glob_test.css")
refute_match /changed-file-test/, css_output
new_file = File.join(File.dirname(__FILE__), 'dummy', 'app', 'assets', 'stylesheets', 'globbed', 'new_glob.scss')
new_file = File.join(test_dir, 'dummy', 'app', 'assets', 'stylesheets', 'globbed', 'new_glob.scss')

File.open(new_file, 'w') do |file|
file.puts '.changed-file-test { color: #000; }'