Skip to content

Commit

Permalink
Add suspenders:development_environment generator
Browse files Browse the repository at this point in the history
To do:

- [ ] Decide which options we want to include from the existing
  generator
- [ ] Decide on the generator name
- [ ] Manually test on a real app

Reference:
https://github.com/thoughtbot/suspenders/blob/55cb5c246fe53aea4cf53436c7c208b40ad13e85/lib/suspenders/generators/app_generator.rb#L80-L92
  • Loading branch information
crackofdusk committed Dec 11, 2023
1 parent cb5dff8 commit eab6dbe
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/generators/suspenders/development_environment_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Suspenders
module Generators
class DevelopmentEnvironmentGenerator < Rails::Generators::Base
def raise_on_missing_assets_in_test
environment "config.assets.raise_runtime_errors = true", env: "test"
end

def raise_on_missing_assets_in_development
environment "config.assets.raise_runtime_errors = true", env: "development"
end
end
end
end
47 changes: 47 additions & 0 deletions test/generators/suspenders/development_environment_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require "test_helper"
require "generators/suspenders/development_environment_generator"

module Suspenders
module Generators
class DevelopmentEnvironmentGenerator::DefaultTest < Rails::Generators::TestCase
include Suspenders::TestHelpers

tests Suspenders::Generators::DevelopmentEnvironmentGenerator
destination Rails.root
setup :prepare_destination
teardown :restore_destination

test "raise on missing assets in tests" do
run_generator

assert_file app_root("config/environments/test.rb") do |file|
assert_match(
/^ +config.assets.raise_runtime_errors = true$/,
file
)
end
end

test "raise on missing assets in development" do
run_generator

assert_file app_root("config/environments/development.rb") do |file|
assert_match(
/^ +config.assets.raise_runtime_errors = true$/,
file
)
end
end

def prepare_destination
backup_file "config/environments/test.rb"
backup_file "config/environments/development.rb"
end

def restore_destination
restore_file "config/environments/test.rb"
restore_file "config/environments/development.rb"
end
end
end
end

0 comments on commit eab6dbe

Please sign in to comment.