|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "isolation/abstract_unit" |
| 4 | + |
| 5 | +module TestHelpersTests |
| 6 | + class GenerationTest < ActiveSupport::TestCase |
| 7 | + include ActiveSupport::Testing::Isolation |
| 8 | + |
| 9 | + def test_build_app |
| 10 | + build_app |
| 11 | + |
| 12 | + assert File.exist?("#{app_path}/config/database.yml") |
| 13 | + assert File.exist?("#{app_path}/config/routes.rb") |
| 14 | + assert File.exist?("#{app_path}/config/initializers") |
| 15 | + end |
| 16 | + |
| 17 | + def test_teardown_app |
| 18 | + build_app |
| 19 | + teardown_app |
| 20 | + |
| 21 | + assert_not File.exist?(app_path) |
| 22 | + end |
| 23 | + |
| 24 | + def test_add_to_config |
| 25 | + build_app |
| 26 | + |
| 27 | + config_file = "#{app_path}/config/application.rb" |
| 28 | + |
| 29 | + assert_not_empty File.open(config_file, &:read) |
| 30 | + |
| 31 | + add_to_config <<-RUBY |
| 32 | + config.zomg = 'zomg' |
| 33 | + RUBY |
| 34 | + |
| 35 | + config = File.open(config_file, &:read) |
| 36 | + |
| 37 | + # preserves indentation |
| 38 | + assert_match(/ config\.zomg = 'zomg'$/, config, "Expected `#{config_file}` to include `config.zomg = 'zomg'`, but did not:\n #{config}") |
| 39 | + end |
| 40 | + |
| 41 | + def test_remove_from_config |
| 42 | + build_app |
| 43 | + |
| 44 | + config_file = "#{app_path}/config/application.rb" |
| 45 | + |
| 46 | + assert_not_empty File.open(config_file, &:read) |
| 47 | + |
| 48 | + add_to_config <<-RUBY |
| 49 | + config.zomg = 'zomg' |
| 50 | + RUBY |
| 51 | + |
| 52 | + remove_from_config "config.zomg = 'zomg'" |
| 53 | + |
| 54 | + config = File.open(config_file, &:read) |
| 55 | + |
| 56 | + assert_no_match(/config\.zomg = 'zomg'$/, config, "Expected `#{config_file}` to include `config.zomg = 'zomg'`, but did not:\n #{config}") |
| 57 | + |
| 58 | + add_to_config <<-RUBY |
| 59 | + config.duplicates = :none |
| 60 | + config.duplicates = :none |
| 61 | + RUBY |
| 62 | + |
| 63 | + # removes all occurrences |
| 64 | + remove_from_config "config.duplicates = :none" |
| 65 | + |
| 66 | + config = File.open(config_file, &:read) |
| 67 | + |
| 68 | + assert_no_match(/config\.duplicates = :none$/, config, "Expected `#{config_file}` to include `config.duplicates = :none`, but did not:\n #{config}") |
| 69 | + end |
| 70 | + end |
| 71 | +end |
0 commit comments