Skip to content

Commit 3daebd5

Browse files
committed
Respect RSpec default_path for generators
1 parent e68175d commit 3daebd5

File tree

14 files changed

+29
-24
lines changed

14 files changed

+29
-24
lines changed

lib/generators/rspec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rails/generators/named_base'
2+
require 'rspec/core'
23
require 'rspec/rails/feature_check'
34

45
# @private
@@ -18,6 +19,10 @@ def self.source_root(path = nil)
1819
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
1920
end
2021
end
22+
23+
def target_path(*paths)
24+
File.join(RSpec.configuration.default_path, *paths)
25+
end
2126
end
2227
end
2328
end

lib/generators/rspec/channel/channel_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Generators
55
# @private
66
class ChannelGenerator < Base
77
def create_channel_spec
8-
template 'channel_spec.rb.erb', File.join('spec/channels', class_path, "#{file_name}_channel_spec.rb")
8+
template 'channel_spec.rb.erb', target_path('channels', class_path, "#{file_name}_channel_spec.rb")
99
end
1010
end
1111
end

lib/generators/rspec/controller/controller_generator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ def generate_request_spec
1616
return unless options[:request_specs]
1717

1818
template 'request_spec.rb',
19-
File.join('spec/requests', class_path, "#{file_name}_spec.rb")
19+
target_path('requests', class_path, "#{file_name}_spec.rb")
2020
end
2121

2222
def generate_controller_spec
2323
return unless options[:controller_specs]
2424

2525
template 'controller_spec.rb',
26-
File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
26+
target_path('controllers', class_path, "#{file_name}_controller_spec.rb")
2727
end
2828

2929
def generate_view_specs
@@ -35,7 +35,7 @@ def generate_view_specs
3535
actions.each do |action|
3636
@action = action
3737
template 'view_spec.rb',
38-
File.join("spec", "views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
38+
target_path('views', file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
3939
end
4040
end
4141

@@ -44,7 +44,7 @@ def generate_routing_spec
4444
return unless options[:routing_specs]
4545

4646
template 'routing_spec.rb',
47-
File.join('spec/routing', class_path, "#{file_name}_routing_spec.rb")
47+
target_path('routing', class_path, "#{file_name}_routing_spec.rb")
4848
end
4949
end
5050
end

lib/generators/rspec/feature/feature_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class FeatureGenerator < Base
1010
def generate_feature_spec
1111
return unless options[:feature_specs]
1212

13-
template template_name, File.join('spec/features', class_path, filename)
13+
template template_name, target_path('features', class_path, filename)
1414
end
1515

1616
def template_name

lib/generators/rspec/generator/generator_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class GeneratorGenerator < Base
99
def generate_generator_spec
1010
return unless options[:generator_specs]
1111

12-
template template_name, File.join('spec/generator', class_path, filename)
12+
template template_name, target_path('generator', class_path, filename)
1313
end
1414

1515
def template_name

lib/generators/rspec/helper/helper_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class HelperGenerator < Base
99
def generate_helper_spec
1010
return unless options[:helper_specs]
1111

12-
template 'helper_spec.rb', File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
12+
template 'helper_spec.rb', target_path('helpers', class_path, "#{file_name}_helper_spec.rb")
1313
end
1414
end
1515
end

lib/generators/rspec/integration/integration_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def generate_request_spec
1515
return unless options[:request_specs]
1616

1717
template 'request_spec.rb',
18-
File.join('spec/requests', "#{name.underscore.pluralize}_spec.rb")
18+
target_path('requests', "#{name.underscore.pluralize}_spec.rb")
1919
end
2020
end
2121
end

lib/generators/rspec/job/job_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Generators
66
class JobGenerator < Base
77
def create_job_spec
88
file_suffix = file_name.end_with?('job') ? 'spec.rb' : 'job_spec.rb'
9-
template 'job_spec.rb.erb', File.join('spec/jobs', class_path, [file_name, file_suffix].join('_'))
9+
template 'job_spec.rb.erb', target_path('jobs', class_path, [file_name, file_suffix].join('_'))
1010
end
1111
end
1212
end

lib/generators/rspec/mailbox/mailbox_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Generators
66
class MailboxGenerator < Base
77
def create_mailbox_spec
88
template('mailbox_spec.rb.erb',
9-
File.join('spec/mailboxes', class_path, "#{file_name}_mailbox_spec.rb")
9+
target_path('mailboxes', class_path, "#{file_name}_mailbox_spec.rb")
1010
)
1111
end
1212
end

lib/generators/rspec/mailer/mailer_generator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ class MailerGenerator < Base
88
argument :actions, type: :array, default: [], banner: "method method"
99

1010
def generate_mailer_spec
11-
template "mailer_spec.rb", File.join('spec/mailers', class_path, "#{file_name}_spec.rb")
11+
template "mailer_spec.rb", target_path('mailers', class_path, "#{file_name}_spec.rb")
1212
end
1313

1414
def generate_fixtures_files
1515
actions.each do |action|
1616
@action, @path = action, File.join(file_path, action)
17-
template "fixture", File.join("spec/fixtures", @path)
17+
template "fixture", target_path("fixtures", @path)
1818
end
1919
end
2020

2121
def generate_preview_files
2222
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
2323

24-
template "preview.rb", File.join("spec/mailers/previews", class_path, "#{file_name}_preview.rb")
24+
template "preview.rb", target_path("mailers/previews", class_path, "#{file_name}_preview.rb")
2525
end
2626
end
2727
end

lib/generators/rspec/model/model_generator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class ModelGenerator < Base
1111
class_option :fixture, type: :boolean
1212

1313
def create_model_spec
14-
template_file = File.join(
15-
'spec/models',
14+
template_file = target_path(
15+
'models',
1616
class_path,
1717
"#{file_name}_spec.rb"
1818
)
@@ -24,7 +24,7 @@ def create_model_spec
2424
def create_fixture_file
2525
return unless missing_fixture_replacement?
2626

27-
template 'fixtures.yml', File.join('spec/fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
27+
template 'fixtures.yml', target_path('fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
2828
end
2929

3030
private

lib/generators/rspec/scaffold/scaffold_generator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def generate_view_specs
5858
def generate_routing_spec
5959
return unless options[:routing_specs]
6060

61-
template_file = File.join(
62-
'spec/routing',
61+
template_file = target_path(
62+
'routing',
6363
controller_class_path,
6464
"#{controller_file_name}_routing_spec.rb"
6565
)
@@ -72,7 +72,7 @@ def generate_routing_spec
7272

7373
def copy_view(view)
7474
template "#{view}_spec.rb",
75-
File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
75+
target_path("views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
7676
end
7777

7878
# support for namespaced-resources
@@ -121,7 +121,7 @@ def raw_value_for(attribute)
121121
end
122122

123123
def template_file(folder:, suffix: '')
124-
File.join('spec', folder, controller_class_path, "#{controller_file_name}#{suffix}_spec.rb")
124+
target_path(folder, controller_class_path, "#{controller_file_name}#{suffix}_spec.rb")
125125
end
126126

127127
def banner

lib/generators/rspec/system/system_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class SystemGenerator < Base
99
def generate_system_spec
1010
return unless options[:system_specs]
1111

12-
template template_name, File.join('spec/system', class_path, filename)
12+
template template_name, target_path('system', class_path, filename)
1313
end
1414

1515
def template_name

lib/generators/rspec/view/view_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class ViewGenerator < Base
99
class_option :template_engine, desc: "Template engine to generate view files"
1010

1111
def create_view_specs
12-
empty_directory File.join("spec", "views", file_path)
12+
empty_directory target_path("views", file_path)
1313

1414
actions.each do |action|
1515
@action = action
1616
template 'view_spec.rb',
17-
File.join("spec", "views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
17+
target_path("views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
1818
end
1919
end
2020
end

0 commit comments

Comments
 (0)