Class: RSpec::Scaffold::SpecLocationBuilder
- Inherits:
-
Object
- Object
- RSpec::Scaffold::SpecLocationBuilder
- Defined in:
- lib/rspec/scaffold/spec_location_builder.rb
Instance Method Summary collapse
-
#initialize(project_root, file_path) ⇒ SpecLocationBuilder
constructor
A new instance of SpecLocationBuilder.
-
#spec_location ⇒ Object
RSpec::Scaffold::SpecLocationBuilder.new(“/home/dev/projects/some_app”, “/app/models/user.rb”).spec_location.
Constructor Details
#initialize(project_root, file_path) ⇒ SpecLocationBuilder
Returns a new instance of SpecLocationBuilder.
8 9 10 11 12 |
# File 'lib/rspec/scaffold/spec_location_builder.rb', line 8 def initialize(project_root, file_path) @project_root = Pathname(project_root) @file_path = Pathname(file_path) @relative_file_path = (@file_path.relative? ? Pathname(@file_path) : ( Pathname(@file_path.to_s.sub(@project_root.to_s, '')) )) end |
Instance Method Details
#spec_location ⇒ Object
RSpec::Scaffold::SpecLocationBuilder.new(“/home/dev/projects/some_app”, “/app/models/user.rb”).spec_location
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rspec/scaffold/spec_location_builder.rb', line 15 def spec_location # for default rails app dir code @spec_location ||= if @relative_file_path.to_s[%r'\A/?app/'] # replace first 'app/' with 'spec/' and change ending a bit @project_root.join(@relative_file_path.sub(%r'\A/?app/', 'spec/')) else @project_root.join("spec").join(@relative_file_path.to_s.sub(%r'\A/', '')) end.sub(%r'\.rb\z', '_spec.rb') return @spec_location end |