Sha256: 1be465ca156f137b8a4bb43c5f05b2edfac014304aa0c7152c6c286e0b6bab14

Contents?: true

Size: 1 KB

Versions: 19

Compression:

Stored size: 1 KB

Contents

require "bundler"
require "bump"

module SpecHelpers
  module InstanceMethods
    def write(file, content)
      folder = File.dirname(file)
      run "mkdir -p #{folder}" unless File.exist?(folder)
      File.open(file, 'w'){|f| f.write content }
    end

    def read(file)
      File.read(file)
    end

    def run(cmd, options={})
      result = `#{cmd} 2>&1`
      raise "FAILED #{cmd} --> #{result}" if $?.success? != !options[:fail]
      result
    end
  end

  module ClassMethods
    def inside_of_folder(folder)
      folder = File.expand_path(folder, File.dirname(File.dirname(__FILE__)))
      around do |example|
        run "rm -rf #{folder} && mkdir #{folder}"
        Dir.chdir folder do
          `git init && git commit --allow-empty -am 'initial'` # so we never accidentally do commit to the current repo
          example.call
        end
        run "rm -rf #{folder}"
      end
    end
  end
end

RSpec.configure do |c|
  c.include SpecHelpers::InstanceMethods
  c.extend SpecHelpers::ClassMethods
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
bump-0.5.2 spec/spec_helper.rb
bump-0.5.1 spec/spec_helper.rb
bumpz-0.5.3 spec/spec_helper.rb
bumpz-0.5.0 spec/spec_helper.rb
bump-0.5.0 spec/spec_helper.rb
bump-0.4.3 spec/spec_helper.rb
bump-0.4.2 spec/spec_helper.rb
bump-0.4.1 spec/spec_helper.rb
bump-0.4.0 spec/spec_helper.rb
bump-0.3.12 spec/spec_helper.rb
bump-0.3.11 spec/spec_helper.rb
bump-0.3.10 spec/spec_helper.rb
bump-0.3.9 spec/spec_helper.rb
bump-0.3.8 spec/spec_helper.rb
bump-0.3.7 spec/spec_helper.rb
bump-0.3.6 spec/spec_helper.rb
bump-0.3.5 spec/spec_helper.rb
bump-0.3.4 spec/spec_helper.rb
bump-0.3.3 spec/spec_helper.rb