Sha256: ec04487519a8633e025bf1bc3887a376003e7152b113e4b4b5df6f75044c419a

Contents?: true

Size: 1.19 KB

Versions: 11

Compression:

Stored size: 1.19 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
    '/tmp/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

11 entries across 11 versions & 1 rubygems

Version Path
make_it_so-0.3.8 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.3.7 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.3.6 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.3.5 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.3.4 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.2.4 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.2.3 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.1.4 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.1.3 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.1.1 spec/support/make_it_so_spec_helpers.rb
make_it_so-0.1.0 spec/support/make_it_so_spec_helpers.rb