Sha256: 429d242c1d92961e5f786ae192465a49f754b7be80d2ecea7e768590f7c17f62
Contents?: true
Size: 981 Bytes
Versions: 3
Compression:
Stored size: 981 Bytes
Contents
module RSpec module Scaffold class FileWriter # manages outputting test scaffolds to file. def initialize(output_file, output_text) @output_file = Pathname(output_file) @output_text = output_text end # RSpec::Scaffold::FileWriter.new("/path/to/file.rb", "yay, test scaffold!") def write! # 1. skip if file already exists. if output_file_already_exists? RSpec::Scaffold.log("- #{@output_file} - already exists", :puts) return end # 2. ensure parent directories exist FileUtils.makedirs(@output_file.parent) # 3. write to file File.open(@output_file, 'wb') do |f| # 'wb' originally f << @output_text end RSpec::Scaffold.log("+ #{@output_file}") return @output_file.to_s end private def output_file_already_exists? return @exists ||= @output_file.exist? end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rspec-scaffold-2.0.1 | lib/rspec/scaffold/file_writer.rb |
rspec-scaffold-2.0.0 | lib/rspec/scaffold/file_writer.rb |
rspec-scaffold-2.0.0.beta1 | lib/rspec/scaffold/file_writer.rb |