Sha256: 14c46e25eedd876ad64015d1aca3f77dc19ebce34a8b0cf65ddb903c177182db

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

module WatirSplash
  # class for common functionality
  class Util
    @@ui_test_common_dir = "ui-test-common"

    class << self

      # loads ui-test-common/environment.rb
      #
      # ui-test-common has to be located at some higher level within directory
      # structure compared to project/ui-test directory
      def load_common
        dir = common_dir
        puts "Loading ui-test-common from #{dir}..."
        require File.join(dir, "environment.rb")
      end

      def load_environment
        env_file = File.join(Dir.pwd, "environment.rb")
        if File.exists?(env_file)
          require env_file
        else
          Dir.chdir("..") do
            load_environment if Dir.entries(Dir.pwd).include?("..")
          end
        end
      end

      private

      def common_dir
        Dir.chdir("..") do
          dirs = Dir.entries(Dir.pwd).find_all {|entry| File.directory?(entry)}
          if dirs.include?(@@ui_test_common_dir) && File.exists?(@@ui_test_common_dir + "/environment.rb")
            File.join(Dir.pwd, @@ui_test_common_dir)
          elsif dirs.include?("..")
            common_dir
          else
            raise "#{@@ui_test_common_dir} directory was not found! It has to exist somewhere higher in directory tree than your project's directory and it has to have environment.rb file in it!"
          end
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
watirsplash-0.2.2 lib/watirsplash/util.rb
watirsplash-0.2.1 lib/watirsplash/util.rb
watirsplash-0.2.0 lib/watirsplash/util.rb