Sha256: 9cd0699e4aa9504628cb0ba32732fd2c69f55e5c87bfc08fd1072f13c7891349

Contents?: true

Size: 1.55 KB

Versions: 22

Compression:

Stored size: 1.55 KB

Contents

require 'rubygems'
require 'tempfile'
require 'spec/expectations'
require 'fileutils'
require 'forwardable'

class CucumberWorld
  extend Forwardable
  def_delegators CucumberWorld, :examples_dir, :self_test_dir, :working_dir, :cucumber_lib_dir

  def self.examples_dir(subdir=nil)
    @examples_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '../../examples'))
    subdir ? File.join(@examples_dir, subdir) : @examples_dir
  end

  def self.self_test_dir
    @self_test_dir ||= examples_dir('self_test')
  end

  def self.working_dir
    @working_dir ||= examples_dir('self_test/tmp')
  end

  def cucumber_lib_dir
    @cucumber_lib_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
  end

  def initialize
    @current_dir = self_test_dir
  end

  private
  attr_reader :last_exit_status, :last_stdout, :last_stderr

  def create_file(file_name, file_content)
    file_content.gsub!("CUCUMBER_LIB", "'#{cucumber_lib_dir}'") # Some files, such as Rakefiles need to use the lib dir
    in_current_dir do
      File.open(file_name, 'w') { |f| f << file_content }
    end
  end

  def in_current_dir(&block)
    Dir.chdir(@current_dir, &block)
  end

  def run(command)
    stderr_file = Tempfile.new('cucumber')
    stderr_file.close
    in_current_dir do
      @last_stdout = `#{command} 2> #{stderr_file.path}`
      @last_exit_status = $?.exitstatus
    end
    @last_stderr = IO.read(stderr_file.path)
  end

end

World do
  CucumberWorld.new
end

Before do
  FileUtils.rm_rf CucumberWorld.working_dir
  FileUtils.mkdir CucumberWorld.working_dir
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
aslakhellesoy-cucumber-0.3.0.1 features/support/env.rb
aslakhellesoy-cucumber-0.3.0 features/support/env.rb
aslakhellesoy-cucumber-0.3.1.1 features/support/env.rb
aslakhellesoy-cucumber-0.3.1 features/support/env.rb
aslakhellesoy-cucumber-0.3.2 features/support/env.rb
aslakhellesoy-cucumber-0.3.3.1 features/support/env.rb
aslakhellesoy-cucumber-0.3.3.2 features/support/env.rb
aslakhellesoy-cucumber-0.3.3.3 features/support/env.rb
aslakhellesoy-cucumber-0.3.3.4 features/support/env.rb
aslakhellesoy-cucumber-0.3.3.5 features/support/env.rb
aslakhellesoy-cucumber-0.3.3.6 features/support/env.rb
aslakhellesoy-cucumber-0.3.3 features/support/env.rb
aslakhellesoy-cucumber-0.3.4 features/support/env.rb
aslakhellesoy-cucumber-0.3.5 features/support/env.rb
aslakhellesoy-cucumber-0.3.6.1 features/support/env.rb
cucumber-0.3.1 features/support/env.rb
cucumber-0.3.0 features/support/env.rb
cucumber-0.3.5 features/support/env.rb
cucumber-0.3.4 features/support/env.rb
cucumber-0.3.6 features/support/env.rb