@@ -660,41 +660,54 @@ def test_ci_files_are_skipped_if_required
660
660
end
661
661
662
662
def test_inclusion_of_kamal_files
663
- run_generator_and_bundler [ destination_root ]
663
+ generator [ destination_root ]
664
+ run_generator_instance
664
665
665
666
assert_file "config/deploy.yml"
666
667
assert_file ".env.erb"
667
668
end
668
669
669
670
def test_kamal_files_are_skipped_if_required
670
- run_generator_and_bundler [ destination_root , "--skip-kamal" ]
671
+ generator [ destination_root ] , [ "--skip-kamal" ]
672
+ run_generator_instance
673
+
674
+ assert_empty @bundle_commands . grep ( "binstubs kamal" )
675
+ assert_empty @bundle_commands . grep ( "exec kamal init" )
671
676
672
677
assert_no_file "config/deploy.yml"
673
678
assert_no_file ".env.erb"
674
679
end
675
680
676
681
def test_inclusion_of_kamal_storage_volume
677
- run_generator_and_bundler [ destination_root ]
682
+ generator [ destination_root ]
683
+ run_generator_instance
684
+
685
+ assert_equal 1 , @bundle_commands . count ( "binstubs kamal" )
686
+ assert_equal 1 , @bundle_commands . count ( "exec kamal init" )
678
687
679
688
assert_file "config/deploy.yml" do |content |
680
689
assert_match ( %r{storage:/rails/storage} , content )
681
690
end
682
691
end
683
692
684
693
def test_inclusion_of_kamal_storage_volume_if_only_skip_active_storage_is_given
685
- run_generator_and_bundler [ destination_root , "--skip-active-storage" ]
694
+ generator [ destination_root ] , [ "--skip-active-storage" ]
695
+ run_generator_instance
696
+
697
+ assert_equal 1 , @bundle_commands . count ( "binstubs kamal" )
698
+ assert_equal 1 , @bundle_commands . count ( "exec kamal init" )
686
699
687
700
assert_file "config/deploy.yml" do |content |
688
701
assert_match ( %r{storage:/rails/storage} , content )
689
702
end
690
703
end
691
704
692
705
def test_kamal_storage_volume_is_skipped_if_required
693
- run_generator_and_bundler [
694
- destination_root ,
695
- "--skip-active-storage" ,
696
- "--database=postgresql"
697
- ]
706
+ generator [ destination_root ] , [ "--skip-active-storage" , "--database=postgresql" ]
707
+ run_generator_instance
708
+
709
+ assert_equal 1 , @bundle_commands . count ( "binstubs kamal" )
710
+ assert_equal 1 , @bundle_commands . count ( "exec kamal init" )
698
711
699
712
assert_file "config/deploy.yml" do |content |
700
713
assert_no_match ( %r{storage:/rails/storage} , content )
@@ -814,15 +827,10 @@ def test_skip_active_job_option
814
827
def test_skip_javascript_option
815
828
generator ( [ destination_root ] , skip_javascript : true )
816
829
817
- command_check = -> command , *_ do
818
- if command == "importmap:install"
819
- flunk "`importmap:install` expected to not be called."
820
- end
821
- end
830
+ run_generator_instance
822
831
823
- generator . stub ( :rails_command , command_check ) do
824
- run_generator_instance
825
- end
832
+ assert_not_includes @rails_commands , "importmap:install" , "`importmap:install` expected to not be called."
833
+ assert_not_includes @rails_commands , "turbo:install stimulus:install" , "`turbo:install stimulus:install` expected to not be called."
826
834
827
835
assert_no_gem "importmap-rails"
828
836
assert_no_gem "jsbundling-rails"
@@ -840,39 +848,19 @@ def test_skip_javascript_option
840
848
def test_webpack_option
841
849
generator ( [ destination_root ] , javascript : "webpack" )
842
850
843
- webpack_called = 0
844
- command_check = -> command , *_ do
845
- case command
846
- when "javascript:install:webpack"
847
- webpack_called += 1
848
- end
849
- end
850
-
851
- generator . stub ( :rails_command , command_check ) do
852
- run_generator_instance
853
- end
851
+ run_generator_instance
854
852
855
- assert_equal 1 , webpack_called , "`javascript:install:webpack` expected to be called once , but was called #{ webpack_called } times ."
853
+ assert_includes @rails_commands , "javascript:install:webpack" , "`javascript:install:webpack` expected to be called, but wasn't ."
856
854
assert_gem "jsbundling-rails"
857
855
assert_node_files
858
856
end
859
857
860
858
def test_esbuild_option
861
859
generator ( [ destination_root ] , javascript : "esbuild" )
862
860
863
- esbuild_called = 0
864
- command_check = -> command , *_ do
865
- case command
866
- when "javascript:install:esbuild"
867
- esbuild_called += 1
868
- end
869
- end
870
-
871
- generator . stub ( :rails_command , command_check ) do
872
- run_generator_instance
873
- end
861
+ run_generator_instance
874
862
875
- assert_equal 1 , esbuild_called , "`javascript:install:esbuild` expected to be called once , but was called #{ esbuild_called } times ."
863
+ assert_includes @rails_commands , "javascript:install:esbuild" , "`javascript:install:esbuild` expected to be called, but wasn't ."
876
864
assert_gem "jsbundling-rails"
877
865
assert_node_files
878
866
end
@@ -895,19 +883,9 @@ def test_esbuild_option_with_js_argument
895
883
def test_bun_option
896
884
generator ( [ destination_root ] , javascript : "bun" )
897
885
898
- bun_called = 0
899
- command_check = -> command , *_ do
900
- case command
901
- when "javascript:install:bun"
902
- bun_called += 1
903
- end
904
- end
905
-
906
- generator . stub ( :rails_command , command_check ) do
907
- run_generator_instance
908
- end
886
+ run_generator_instance
909
887
910
- assert_equal 1 , bun_called , "`javascript:install:bun` expected to be called once , but was called #{ bun_called } times ."
888
+ assert_includes @rails_commands , "javascript:install:bun" , "`javascript:install:bun` expected to be called, but wasn't ."
911
889
assert_gem "jsbundling-rails"
912
890
end
913
891
@@ -948,20 +926,20 @@ def test_skip_javascript_option_with_skip_js_argument
948
926
end
949
927
950
928
def test_hotwire
951
- run_generator_and_bundler [ destination_root ]
929
+ generator [ destination_root ]
930
+ run_generator_instance
931
+
932
+ assert_includes @rails_commands , "turbo:install stimulus:install" , "`turbo:install stimulus:install` expected to be called, but wasn't."
952
933
assert_gem "turbo-rails"
953
934
assert_gem "stimulus-rails"
954
935
assert_file "app/views/layouts/application.html.erb" do |content |
955
936
assert_match ( /data-turbo-track/ , content )
956
937
end
957
- assert_file "app/javascript/application.js" do |content |
958
- assert_match ( /turbo/ , content )
959
- assert_match ( /controllers/ , content )
960
- end
961
938
end
962
939
963
940
def test_skip_hotwire
964
- run_generator [ destination_root , "--skip-hotwire" ]
941
+ generator [ destination_root ] , [ "--skip-hotwire" ]
942
+ run_generator_instance
965
943
966
944
assert_no_gem "turbo-rails"
967
945
assert_file "app/views/layouts/application.html.erb" do |content |
@@ -971,11 +949,11 @@ def test_skip_hotwire
971
949
end
972
950
973
951
def test_css_option_with_asset_pipeline_tailwind
974
- run_generator_and_bundler [ destination_root , "--asset-pipeline=sprockets" , "--css=tailwind" ]
952
+ generator [ destination_root ] , [ "--css=tailwind" , "--asset-pipeline=sprockets" ]
953
+ run_generator_instance
954
+
955
+ assert_includes @rails_commands , "tailwindcss:install" , "`tailwindcss:install` expected to be called, but wasn't."
975
956
assert_gem "tailwindcss-rails"
976
- assert_file "app/views/layouts/application.html.erb" do |content |
977
- assert_match ( /tailwind/ , content )
978
- end
979
957
assert_no_node_files
980
958
end
981
959
@@ -986,9 +964,11 @@ def test_css_option_with_tailwind_uses_cssbundling_gem_when_using_node
986
964
end
987
965
988
966
def test_css_option_with_asset_pipeline_sass
989
- run_generator_and_bundler [ destination_root , "--asset-pipeline=sprockets" , "--css=sass" ]
967
+ generator [ destination_root ] , [ "--css=sass" , "--asset-pipeline=sprockets" ]
968
+ run_generator_instance
969
+
970
+ assert_includes @rails_commands , "dartsass:install" , "`dartsass:install` expected to be called, but wasn't."
990
971
assert_gem "dartsass-rails"
991
- assert_file "app/assets/stylesheets/application.scss"
992
972
assert_no_node_files
993
973
end
994
974
@@ -999,9 +979,11 @@ def test_css_option_with_sass_uses_cssbundling_gem_when_using_node
999
979
end
1000
980
1001
981
def test_css_option_with_cssbundling_gem
1002
- run_generator_and_bundler [ destination_root , "--asset-pipeline=sprockets" , "--css=postcss" ]
982
+ generator [ destination_root ] , [ "--css=postcss" , "--asset-pipeline=sprockets" ]
983
+ run_generator_instance
984
+
985
+ assert_includes @rails_commands , "css:install:postcss" , "`css:install:postcss` expected to be called, but wasn't."
1003
986
assert_gem "cssbundling-rails"
1004
- assert_file "app/assets/stylesheets/application.postcss.css"
1005
987
assert_node_files
1006
988
end
1007
989
@@ -1011,6 +993,16 @@ def test_css_option_with_cssbundling_gem_does_not_force_jsbundling_gem
1011
993
assert_gem "importmap-rails"
1012
994
end
1013
995
996
+ def test_default_generator_executes_all_rails_commands
997
+ generator [ destination_root ]
998
+ run_generator_instance
999
+
1000
+ expected_commands = [
1001
+ "credentials:diff --enroll" , "importmap:install" , "turbo:install stimulus:install"
1002
+ ]
1003
+ assert_equal expected_commands , @rails_commands
1004
+ end
1005
+
1014
1006
def test_skip_dev_gems
1015
1007
run_generator [ destination_root , "--skip-dev-gems" ]
1016
1008
assert_no_gem "web-console"
@@ -1519,20 +1511,6 @@ def assert_no_node_files
1519
1511
end
1520
1512
end
1521
1513
1522
- def run_generator_and_bundler ( args )
1523
- option_args , positional_args = args . partition { |arg | arg . start_with? ( "--" ) }
1524
- option_args << "--no-skip-bundle"
1525
- generator ( positional_args , option_args )
1526
-
1527
- # Stub `rails_gemfile_entry` so that Bundler resolves `gem "rails"` to the
1528
- # current repository instead of searching for an invalid version number
1529
- # (for a version that hasn't been released yet).
1530
- rails_gemfile_entry = Rails ::Generators ::AppBase ::GemfileEntry . path ( "rails" , Rails ::Generators ::RAILS_DEV_PATH )
1531
- generator . stub ( :rails_gemfile_entry , -> { rails_gemfile_entry } ) do
1532
- quietly { run_generator_instance }
1533
- end
1534
- end
1535
-
1536
1514
def run_app_update ( app_root = destination_root , flags : "--force" )
1537
1515
Dir . chdir ( app_root ) do
1538
1516
gemfile_contents = File . read ( "Gemfile" )
0 commit comments