Class: Hatchet::InitProject

Inherits:
Object
  • Object
show all
Defined in:
lib/hatchet/init_project.rb

Overview

Bootstraps a project with files for running hatchet tests

Hatchet::InitProject.new.call

puts File.exist?("spec/spec_helper.rb") # => true
puts File.exist?("") # => true

Instance Method Summary collapse

Constructor Details

#initialize(dir: ".", io: STDOUT) ⇒ InitProject

Returns a new instance of InitProject.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hatchet/init_project.rb', line 12

def initialize(dir: ".", io: STDOUT)

  @target_dir = Pathname.new(dir)
  raise "Must run in a directory with a buildpack, #{@target_dir} has no bin/ directory" unless @target_dir.join("bin").directory?

  @template_dir = Pathname.new(__dir__).join("templates")
  @thor_shell = ::Thor::Shell::Basic.new
  @io = io
  @git_ignore = @target_dir.join(".gitignore")

  FileUtils.touch(@git_ignore)
  FileUtils.touch(@target_dir.join("hatchet.lock"))
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hatchet/init_project.rb', line 26

def call
  write_target(target: ".circleci/config.yml", template: "circleci_template.erb")
  write_target(target: "Gemfile", template: "Gemfile.erb")
  write_target(target: "hatchet.json", template: "hatchet_json.erb")
  write_target(target: "spec/spec_helper.rb", template: "spec_helper.erb")
  write_target(target: "spec/hatchet/buildpack_spec.rb", template: "buildpack_spec.erb")
  write_target(target: ".github/dependabot.yml", template: "dependabot.erb")
  write_target(target: ".github/workflows/check_changelog.yml", template: "check_changelog.erb")

  add_gitignore(".rspec_status")
  add_gitignore("repos/*")

  stream("cd #{@target_dir} && bundle install")
  stream("cd #{@target_dir} && hatchet install")

  @io.puts
  @io.puts "Done, run `bundle exec rspec` to execute your tests"
  @io.puts
end