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