Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Generators] Added generator for ActiveJob
- Loading branch information
Showing
6 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ The same generator pattern is available for all specs: | |
* observer | ||
* integration | ||
* feature | ||
* job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'generators/rspec' | ||
|
||
module Rspec | ||
module Generators | ||
# @private | ||
class JobGenerator < Base | ||
def create_job_spec | ||
template 'job_spec.rb.erb', File.join('spec/jobs', class_path, "#{file_name}_job_spec.rb") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'rails_helper' | ||
|
||
<% module_namespacing do -%> | ||
RSpec.describe <%= class_name %>Job, :type => :job do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end | ||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module RSpec | ||
module Rails | ||
module FeaturesCheck | ||
module_function | ||
|
||
def has_activejob? | ||
defined?(::ActiveJob) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'spec_helper' | ||
|
||
# Generators are not automatically loaded by Rails | ||
require 'generators/rspec/job/job_generator' | ||
|
||
RSpec.describe Rspec::Generators::JobGenerator, :type => :generator, :skip => !Rspec::Rails::FeaturesCheck.has_activejob? do | ||
# Tell the generator where to put its output (what it thinks of as Rails.root) | ||
destination File.expand_path('../../../../../tmp', __FILE__) | ||
|
||
before { prepare_destination } | ||
|
||
describe 'the generated files' do | ||
before { run_generator %w(user) } | ||
|
||
subject { file('spec/jobs/user_job_spec.rb') } | ||
|
||
it { is_expected.to exist } | ||
it { is_expected.to contain(/require 'rails_helper'/) } | ||
it { is_expected.to contain(/describe UserJob, :type => :job/) } | ||
|
||
end | ||
end |