Sha256: 417f45a8fd69401d741c0c5dc823c4e7e5c7d3027c24415b9d7f38944713ef22

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

module MakeItSoSpecHelpers
  def make_it_so!(subcommand_with_args)
    Dir.chdir(tmp_path) do
      Bundler.with_clean_env do
        `#{join_paths(bin_path, 'make_it_so')} #{subcommand_with_args}`
      end
    end
  end

  def make_tmp_path
    FileUtils.mkdir_p(tmp_path)
  end

  def purge_tmp_dir
    FileUtils.rm_rf(tmp_path)
  end

  protected
  def bin_path
    join_paths(root_path, 'bin')
  end

  def tmp_path
    File.join(Dir.tmpdir, 'make_it_so')
  end

  def root_path
    join_paths(File.dirname(__FILE__), '../../')
  end

  def join_paths(*paths)
    File.join(*paths)
  end

  def has_dir?(relative_path)
    File.directory?(join_paths(app_path, relative_path))
  end

  def has_file?(relative_path)
    FileTest.exists?(join_paths(app_path, relative_path))
  end

  def in_gemfile?(gem_name)
    File.read(join_paths(app_path, 'Gemfile')).
      match(/gem.*#{Regexp.escape(gem_name)}/).present?
  end

  def in_package_json?(path, &block)
    contents = File.read(path)
    json = JSON.parse(contents)
    yield(json)
  end
end

RSpec.configure do |config|
  config.include(MakeItSoSpecHelpers)

  config.before(:all) do
    purge_tmp_dir
    make_tmp_path
  end

  config.after(:all) do
    purge_tmp_dir
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
make_it_so-0.4.5 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.4.3 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.4.2 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.4.1 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.4.0 spec/support/make_it_so_spec_helpers.rb