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 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
18 changes: 12 additions & 6 deletions test/sassc_rails_test.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# frozen_string_literal: true

require "test_helper"
require 'active_support/testing/isolation'

class SassRailsTest < MiniTest::Test
include ActiveSupport::Testing::Isolation

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
Expand All @@ -30,8 +37,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)
Expand Down Expand Up @@ -169,7 +175,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
Expand Down Expand Up @@ -287,7 +293,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; }'
Expand All @@ -314,7 +320,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; }'
Expand Down