@@ -12,6 +12,8 @@ class InstallGenerator < ::Rails::Generators::Base
12
12
Copy rspec files to your application.
13
13
DESC
14
14
15
+ class_option :default_path , type : :string , default : 'spec'
16
+
15
17
def self . source_root
16
18
@source_root ||= File . expand_path ( File . join ( File . dirname ( __FILE__ ) , 'templates' ) )
17
19
end
@@ -20,12 +22,12 @@ def copy_spec_files
20
22
Dir . mktmpdir do |dir |
21
23
generate_rspec_init dir
22
24
template File . join ( dir , '.rspec' ) , '.rspec'
23
- directory File . join ( dir , 'spec' ) , 'spec'
25
+ directory File . join ( dir , 'spec' ) , default_path
24
26
end
25
27
end
26
28
27
29
def copy_rails_files
28
- template 'spec/rails_helper.rb'
30
+ template 'spec/rails_helper.rb' , " #{ default_path } /rails_helper.rb"
29
31
end
30
32
31
33
private
@@ -41,6 +43,10 @@ def generate_rspec_init(tmpdir)
41
43
42
44
replace_generator_command ( spec_helper_path )
43
45
remove_warnings_configuration ( spec_helper_path )
46
+
47
+ dot_rspec_path = File . join ( tmpdir , '.rspec' )
48
+
49
+ append_default_path ( dot_rspec_path )
44
50
end
45
51
46
52
def replace_generator_command ( spec_helper_path )
@@ -58,6 +64,15 @@ def remove_warnings_configuration(spec_helper_path)
58
64
'' ,
59
65
verbose : false
60
66
end
67
+
68
+ def append_default_path ( dot_rspec_path )
69
+ append_to_file dot_rspec_path ,
70
+ "--default-path #{ default_path } "
71
+ end
72
+
73
+ def default_path
74
+ options [ :default_path ]
75
+ end
61
76
end
62
77
end
63
78
end
0 commit comments