-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds test coverage for the `dartsass:install` command. The command is tested against a freshly generated Rails app using the version of Rails that is currently loaded. Thus the installer can be tested with different versions of Rails in CI.
- Loading branch information
1 parent
6d076d2
commit b7c781b
Showing
2 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require "test_helper" | ||
|
||
class InstallerTest < ActiveSupport::TestCase | ||
include RailsAppHelpers | ||
|
||
test "installer" do | ||
with_new_rails_app do | ||
out, _err = run_command("bin/rails", "dartsass:install") | ||
|
||
assert_match "<DONE>", out | ||
assert_equal 0, File.size("app/assets/builds/.keep") | ||
assert_match "/app/assets/builds/*\n!/app/assets/builds/.keep", File.read(".gitignore") | ||
assert_equal File.read("#{__dir__}/../lib/install/application.scss"), File.read("app/assets/stylesheets/application.scss") | ||
assert_equal File.read("#{__dir__}/../lib/install/Procfile.dev"), File.read("Procfile.dev") | ||
assert_equal File.read("#{__dir__}/../lib/install/dev"), File.read("bin/dev") | ||
assert_equal 0700, File.stat("bin/dev").mode & 0700 | ||
|
||
if sprockets? | ||
assert_match "//= link_tree ../builds", File.read("app/assets/config/manifest.js") | ||
assert_no_match "//= link_directory ../stylesheets .css", File.read("app/assets/config/manifest.js") | ||
end | ||
end | ||
end | ||
|
||
test "installer with missing .gitignore" do | ||
with_new_rails_app do | ||
FileUtils.rm(".gitignore") | ||
out, _err = run_command("bin/rails", "dartsass:install") | ||
|
||
assert_match "<DONE>", out | ||
assert_not File.exist?(".gitignore") | ||
end | ||
end | ||
|
||
test "installer with pre-existing application.scss" do | ||
with_new_rails_app do | ||
File.write("app/assets/stylesheets/application.scss", "// pre-existing") | ||
out, _err = run_command("bin/rails", "dartsass:install") | ||
|
||
assert_match "<DONE>", out | ||
assert_equal "// pre-existing", File.read("app/assets/stylesheets/application.scss") | ||
end | ||
end | ||
|
||
test "installer with pre-existing Procfile" do | ||
with_new_rails_app do | ||
File.write("Procfile.dev", "pre: existing\n") | ||
out, _err = run_command("bin/rails", "dartsass:install") | ||
|
||
assert_match "<DONE>", out | ||
assert_equal "pre: existing\ncss: bin/rails dartsass:watch\n", File.read("Procfile.dev") | ||
end | ||
end | ||
|
||
private | ||
def with_new_rails_app(&block) | ||
super do | ||
# Override `dartsass:build` to check that installation completed and to reduce test run time. | ||
File.write("Rakefile", <<~RAKEFILE, mode: "a+") | ||
Rake::Task["dartsass:build"].clear | ||
namespace :dartsass do | ||
task build: :environment do | ||
puts "<DONE>" | ||
end | ||
end | ||
RAKEFILE | ||
|
||
block.call | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters