1111# -----------------------------------------------------------------------------
1212# Rails app spits out lots of startup garbage, separate this
1313def notice_me ( msg )
14- puts '* ' * 100
14+ puts "☠ #{ '❌ ' * 30 } ☠"
1515 puts "❌ #{ msg } "
1616 puts
1717end
@@ -29,6 +29,16 @@ rescue Exception => ex # Did you know LoadError inherits from Exception, not Sta
2929 notice_me "Warning: colorize gem not found, make sure you:\n - Installed colorize locally (gem install colorize)\n - This path exists: #{ colorize_init_file } \n #{ ex . message } "
3030end
3131
32+ # -----------------------------------------------------------------------------
33+ # Load the route helpers in the terminal so you can generate page URLs
34+ # admin_stark_user_path / admin_stark_user_url
35+ begin
36+ include Rails . application . routes . url_helpers
37+ puts "✅ #{ 'include' . light_yellow } #{ 'Rails.application.routes.url_helpers' . cyan } "
38+ rescue LoadError
39+ puts "Warning: factory_bot_rails gem not found"
40+ end
41+
3242# -----------------------------------------------------------------------------
3343# Enables FactoryBot in a pry session
3444begin
@@ -47,31 +57,33 @@ rescue StandardError
4757 notice_me "Warning: ./spec/support/anna_spec_helper not found"
4858end
4959
50- # -----------------------------------------------------------------------------
51- # Enables a lot more factories which explicilty need the domestic_phone_number
52- # gem for creating factories that use phone numbers
53- begin
54- require './spec/support/faker_phones.rb'
55- puts "✅ #{ 'require' . light_red } #{ "'./spec/support/faker_phones.rb'" . cyan } "
56- rescue StandardError
57- notice_me "Warning: ./spec/support/faker_phones.rb not found"
58- end
59-
60-
61- # -----------------------------------------------------------------------------
62- # Load the route helpers in the terminal so you can generate page URLs
63- # admin_stark_user_path / admin_stark_user_url
64- begin
65- include Rails . application . routes . url_helpers
66- puts "✅ #{ 'include' . light_yellow } #{ 'Rails.application.routes.url_helpers' . cyan } "
67- rescue LoadError
68- puts "Warning: factory_bot_rails gem not found"
69- end
70-
7160# =============================================================================
7261# Helper functions (not meant to be run directly)
7362# =============================================================================
7463
64+ def globRequire ( path )
65+ successes = [ ]
66+ failures = [ ]
67+ Dir . glob ( path ) . each do |file |
68+ begin
69+ require file
70+ successes << file
71+ rescue Exception => e
72+ failures << "Warning: Could not require #{ file } ? #{ e . message } "
73+ end
74+ end
75+ if successes . count > 0
76+ puts "✅ #{ 'require {' . light_red } #{ successes . join ( ', ' ) . cyan } #{ '}' . light_red } "
77+ end
78+ notice_me failures if failures . present?
79+ end
80+
81+ # -----------------------------------------------------------------------------
82+ # Enables a lot more factories which need our custom Faker plugins. I'm too
83+ # lazy to make the method a separate file and require it so that I can call
84+ # this method above the definitino
85+ globRequire ( './spec/support/faker_*.rb' )
86+
7587# -----------------------------------------------------------------------------
7688# Print a full stack trace with colorized output for easier
7789def colorized_stack_trace ( stack , base_dir )
0 commit comments