Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement check to prevent duplicate job naming #2496

Merged
merged 2 commits into from Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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