Skip to content

Commit

Permalink
Implement check to prevent duplicate job naming (#2496)
Browse files Browse the repository at this point in the history
* Implement check to prevent duplicate job naming
  • Loading branch information
Nick Flückiger committed Apr 20, 2021
1 parent efdc7b5 commit 66a0bc0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/generators/rspec/job/job_generator.rb
Expand Up @@ -5,7 +5,8 @@ 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")
file_suffix = file_name.end_with?('job') ? 'spec.rb' : 'job_spec.rb'
template 'job_spec.rb.erb', File.join('spec/jobs', class_path, [file_name, file_suffix].join('_'))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/job/templates/job_spec.rb.erb
@@ -1,7 +1,7 @@
require 'rails_helper'

<% module_namespacing do -%>
RSpec.describe <%= class_name %>Job, <%= type_metatag(:job) %> do
RSpec.describe <%= class_name %><%= "Job" unless class_name.end_with?("Job")%>, <%= type_metatag(:job) %> do
pending "add some examples to (or delete) #{__FILE__}"
end
<% end -%>
22 changes: 17 additions & 5 deletions spec/generators/rspec/job/job_generator_spec.rb
Expand Up @@ -6,13 +6,25 @@
setup_default_destination

describe 'the generated files' do
before { run_generator %w[user] }
before { run_generator [file_name] }

subject { file('spec/jobs/user_job_spec.rb') }
context 'with file_name without job as suffix' do
let(:file_name) { '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_metatag(:job)}/) }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/describe UserJob, #{type_metatag(:job)}/) }
end

context 'with file_name with job as suffix' do
let(:file_name) { 'user_job' }

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_metatag(:job)}/) }
end
end
end

0 comments on commit 66a0bc0

Please sign in to comment.