Sha256: cc6ca80c3d815e6fadbf80d46aa2b683999a9cc80190b7ebb444c56a392daa41

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

DevScripts::Script.define_script :open_spec_file do
  args :file_path 

  def file_exists?
    !found_file_path.nil?
  end

  let(:file_path_without_extension) do
    file_path.gsub('.rb', '')
  end

  let(:found_file_path) do
    Dir['./spec/**/*.rb'].find do |path|
      !(path =~ /#{file_path_without_extension}_spec.rb/).nil?
    end
  end

  let(:spec_file_path) do
    if file_exists?
      found_file_path
    else
      "spec/#{file_path_without_extension}_spec.rb"
    end
  end

  let(:constant_name) do
    require 'active_support/inflector'

    spec_file_path
      .gsub(/spec\/|_spec\.rb/, '')
      .split('/')
      .map(&:camelize)
      .join('::')
  end

  before do
    if file_exists?
      puts 'file already exists, opening file'
    else
      puts 'file does not exist, writing a new file'
    end
  end

  execute do
    if !file_exists?
      create_file_in_editor spec_file_path do
        <<-RUBY
Rspec.describe #{constant_name} do
end
        RUBY
      end
    end

    open_file_in_editor spec_file_path
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dev_scripts-0.1.3 lib/dev_scripts/scripts/open_spec_file.rb
dev_scripts-0.1.1 scripts/open_spec_file.rb