Class: Recipes::Testing

Inherits:
Rails::AppBuilder
  • Object
show all
Defined in:
lib/potassium/recipes/testing.rb

Instance Method Summary collapse

Instance Method Details

#add_gemsObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/potassium/recipes/testing.rb', line 73

def add_gems
  gather_gems(:development, :test) do
    gather_gem('rspec-rails')
    gather_gem('factory_bot_rails')
    gather_gem('faker')
    gather_gem('guard-rspec', require: false)
    gather_gem('rspec-nc', require: false)
  end

  gather_gems(:test) do
    gather_gem('shoulda-matchers', require: false)
    gather_gem('capybara')
    gather_gem('webdrivers')
  end
end

#add_support_configuration_modulesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/potassium/recipes/testing.rb', line 43

def add_support_configuration_modules
  files = %w{
    faker_config
    factory_bot_config
    power_types_config
    shoulda_matchers_config
    system_tests_config
  }
  files << "devise_config" if selected?(:authentication)
  files.each do |config_module|
    copy_file(
      "../assets/testing/#{config_module}.rb",
      "spec/support/configurations/#{config_module}.rb"
    )
  end
end

#config_raise_delivery_errors_optionObject



89
90
91
92
93
94
# File 'lib/potassium/recipes/testing.rb', line 89

def config_raise_delivery_errors_option
  raise_delivery_errors_regexp = /config.action_mailer.raise_delivery_errors = false\n/
  gsub_file 'config/environments/development.rb', raise_delivery_errors_regexp do
    "config.action_mailer.raise_delivery_errors = true"
  end
end

#createObject



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/potassium/recipes/testing.rb', line 2

def create
  add_gems
  add_readme_header(:testing)
  recipe = self

  after(:gem_install) do
    recipe.install_rspec
    recipe.install_guard
    recipe.create_rspec_binary
  end

  config_raise_delivery_errors_option
end

#create_rspec_binaryObject



69
70
71
# File 'lib/potassium/recipes/testing.rb', line 69

def create_rspec_binary
  run "bundle binstubs rspec-core"
end

#create_support_directoriesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/potassium/recipes/testing.rb', line 27

def create_support_directories
  %w{
    custom_matchers
    shared_examples
    configurations
    helpers
    helpers/system
  }.each do |directory|
    path = "spec/support/#{directory}"
    empty_directory(path)
    create_file("#{path}/.keep")
  end

  add_support_configuration_modules
end

#install_guardObject



60
61
62
63
64
65
66
67
# File 'lib/potassium/recipes/testing.rb', line 60

def install_guard
  run "bundle exec guard init"
  run "bundle binstub guard"
  line = /guard :rspec, cmd: "bundle exec rspec" do\n/
  gsub_file 'Guardfile', line do
    "guard :rspec, cmd: \"bin/rspec\" do\n"
  end
end

#install_rspecObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/potassium/recipes/testing.rb', line 16

def install_rspec
  remove_dir 'test'
  generate "rspec:install"
  remove_file 'spec/rails_helper.rb'
  copy_file '../assets/testing/rails_helper.rb', 'spec/rails_helper.rb'
  remove_file '.rspec'
  copy_file '../assets/testing/.rspec', '.rspec'
  create_file 'spec/system/.keep'
  create_support_directories
end