Class: DRG::Tasks::SpecRunner
- Inherits:
-
Object
- Object
- DRG::Tasks::SpecRunner
- Includes:
- Log
- Defined in:
- lib/drg/tasks/spec_runner.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#initialize(file) ⇒ SpecRunner
constructor
A new instance of SpecRunner.
- #perform ⇒ Object
- #ruby_files ⇒ Object
- #spec_file(ruby_file) ⇒ Object
- #spec_path ⇒ Object
Methods included from Log
Constructor Details
#initialize(file) ⇒ SpecRunner
Returns a new instance of SpecRunner.
11 12 13 |
# File 'lib/drg/tasks/spec_runner.rb', line 11 def initialize(file) @file = Pathname.new(file) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/drg/tasks/spec_runner.rb', line 8 def file @file end |
Instance Method Details
#perform ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/drg/tasks/spec_runner.rb', line 15 def perform fail ArgumentError, %Q(File or directory does not exist: "#{file}") if !File.exists?(file) && !File.exists?("#{file}.rb") ruby_files.each do |ruby_file| file_path = Pathname.new(File.(ruby_file)) spec = DRG::Spec.generate(file_path) next unless spec rspec_file = Pathname.new(spec_file(ruby_file)) log "Generating #{rspec_file}" FileUtils.mkdir_p(rspec_file.parent) File.open(spec_file(ruby_file), 'wb') do |f| f << spec.join("\n") end end end |
#ruby_files ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/drg/tasks/spec_runner.rb', line 30 def ruby_files if File.directory?(file) Dir[File.join(file, '**', '*.rb')] else if file.extname.empty? ["#{file}.rb"] else [file] end end end |
#spec_file(ruby_file) ⇒ Object
Note:
subbing out /app/ is Rails specific
43 44 45 |
# File 'lib/drg/tasks/spec_runner.rb', line 43 def spec_file(ruby_file) File.join(spec_path, "#{ruby_file.sub('.rb', '_spec.rb')}").sub '/app/', '/' end |
#spec_path ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/drg/tasks/spec_runner.rb', line 47 def spec_path if File.directory?(File.('spec')) File.('spec') else fail "Couldn't find spec directory" end end |