Sha256: 2b6f6bfbce8c0449f1e982bdeedd4ff6c823617a722e37f5d1b0653b15b5e947

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'
require 'open4'

ENV['PATH'] = "#{File.expand_path('../../bin', __FILE__)}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
ENV['RUBYOPT'] = '-Ilib'

module AcceptanceSpecDSL
  module Feature
    def self.extended(base)
      base.instance_eval do
        alias :feature :describe
      end
    end
  end

  def self.included(base)
    base.instance_eval do
      alias :background :before
      alias :scenario :it
      alias :xscenario :xit
      alias :given :let
      alias :given! :let!
    end
  end
end

module TaketoAcceptanceSpec
  DEFAULT_TEST_CONFIG_PATH = "/tmp/taketo_test_cfg.rb".freeze

  attr_reader :stdout, :stderr, :exit_status

  def create_config(config)
    File.open(DEFAULT_TEST_CONFIG_PATH, "w") do |f|
      f.write(config)
    end
  end
  alias :config_exists :create_config

  def remove_config
    if File.exist?(DEFAULT_TEST_CONFIG_PATH)
      FileUtils.rm(DEFAULT_TEST_CONFIG_PATH)
    end
  end

  def run(command)
    pid, stdin, stdout, stderr = Open4.popen4("#{command} --config #{DEFAULT_TEST_CONFIG_PATH} --debug")
    @stdout = stdout.read.chomp.freeze
    @stderr = stderr.read.chomp.freeze
    _, @exit_status = Process.waitpid2(pid)
  ensure
    stdin.close if stdin
    stdout.close if stdout
    stderr.close if stderr
  end

  RSpec.configure do |config|
    config.after(:each) do
      @stdout = nil
      @stderr = nil
      @exit_status = nil
      remove_config
    end
  end
end

extend AcceptanceSpecDSL::Feature

RSpec.configure do |c|
  c.include AcceptanceSpecDSL
  c.include TaketoAcceptanceSpec
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
taketo-0.1.3 spec/acceptance_spec_helper.rb
taketo-0.1.2 spec/acceptance_spec_helper.rb
taketo-0.1.1 spec/acceptance_spec_helper.rb
taketo-0.1.0 spec/acceptance_spec_helper.rb