Skip to content

Commit

Permalink
[Generators] Added generator for ActiveJob
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed Aug 27, 2014
1 parent 1f7736a commit a1a6b39
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions features/Generators.md
Expand Up @@ -23,3 +23,4 @@ The same generator pattern is available for all specs:
* observer
* integration
* feature
* job
12 changes: 12 additions & 0 deletions lib/generators/rspec/job/job_generator.rb
@@ -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
7 changes: 7 additions & 0 deletions lib/generators/rspec/job/templates/job_spec.rb.erb
@@ -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 -%>
1 change: 1 addition & 0 deletions lib/rspec/rails.rb
Expand Up @@ -8,3 +8,4 @@
require 'rspec/rails/example'
require 'rspec/rails/vendor/capybara'
require 'rspec/rails/configuration'
require 'rspec/rails/features_check'
11 changes: 11 additions & 0 deletions lib/rspec/rails/features_check.rb
@@ -0,0 +1,11 @@
module RSpec
module Rails
module FeaturesCheck
module_function

def has_activejob?
defined?(::ActiveJob)
end
end
end
end
22 changes: 22 additions & 0 deletions spec/generators/rspec/job/job_generator_spec.rb
@@ -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 a1a6b39

Please sign in to comment.