Permalink
Browse files

[Generators] Added generator for ActiveJob

  • Loading branch information...
seuros committed Aug 22, 2014
1 parent 1f7736a commit 5646d1f735ef1d61c3d99ed560543b15d16af724
@@ -23,3 +23,4 @@ The same generator pattern is available for all specs:
* observer
* integration
* feature
* job
@@ -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
@@ -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 -%>
@@ -8,3 +8,4 @@
require 'rspec/rails/example'
require 'rspec/rails/vendor/capybara'
require 'rspec/rails/configuration'
require 'rspec/rails/features_check'
@@ -0,0 +1,11 @@
module RSpec
module Rails
module FeaturesCheck
module_function
def has_activejob?
defined?(::ActiveJob)
end
end
end
end
@@ -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

0 comments on commit 5646d1f

Please sign in to comment.