Skip to content

Commit

Permalink
Add test for rails g good_job:install
Browse files Browse the repository at this point in the history
  • Loading branch information
arku committed Aug 25, 2020
1 parent ccff9a1 commit 651bb09
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
14 changes: 14 additions & 0 deletions spec/lib/generators/good_job/install_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'rails_helper'
require 'generators/good_job/install_generator'

describe GoodJob::InstallGenerator, type: :generator do
it 'creates a migration for good_jobs table' do
create_dummy_app

install_good_job

expect(Dir.glob("#{dummy_app_path}/db/migrate/[0-9]*_create_good_jobs.rb")).not_to be_empty

remove_dummy_app
end
end
33 changes: 33 additions & 0 deletions spec/support/good_job_test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'fileutils'

module GoodJobTestHelper
def create_dummy_app
FileUtils.cd(tmp_path) do
`rails new dummy --skip-action-mailer --skip-action-mailbox --skip-action-cable --skip-sprockets --skip-listen --skip-javascript --skip-turbolinks --skip-system-test --skip-test-unit --skip-bootsnap --skip-spring`
end
end

def remove_dummy_app
FileUtils.rm_rf(dummy_app_path)
end

def install_good_job
File.open("#{dummy_app_path}/Gemfile", 'a') do |f|
f.puts "gem 'good_job'"
end

FileUtils.cd(dummy_app_path) do
`rails g good_job:install`
end
end

def dummy_app_path
File.join(tmp_path, 'dummy')
end

def tmp_path
@_tmp_path ||= File.join(File.dirname(__FILE__), '..')
end
end

RSpec.configure { |c| c.include GoodJobTestHelper, type: :generator }

0 comments on commit 651bb09

Please sign in to comment.