Sha256: ea2237752e2ad11408b92a7d26066fd06ba4bb73fa318b6433771dcf99373a38

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require 'yaml'

module Utilities
  @path = 'config/config.yml'

  class << self
    def browser=(browser)
      config['browser'] = browser
      overwrite_yaml
    end

    def page_path=(path)
      config['page_path'] = path
      overwrite_yaml
    end

    def spec_path=(path)
      config['spec_path'] = path
      overwrite_yaml
    end

    def feature_path=(path)
      config['feature_path'] = path
      overwrite_yaml
    end

    def helper_path=(path)
      config['helper_path'] = path
      overwrite_yaml
    end

    def url=(url)
      config['url'] = url
      overwrite_yaml
    end

    def platform=(platform)
      config['platform'] = platform
      overwrite_yaml
    end

    def browser_options=(*opts)
      args = opts.flatten
      browser_args = config['browser_arguments']
      browser_args[args.first&.to_sym] = browser_args + args[1..]
      overwrite_yaml
    end

    def delete_browser_options
      config.delete('browser_options')
      overwrite_yaml
    end

    def run(opts = nil)
      command = File.directory?('spec') ? 'rspec spec/' : 'cucumber features'
      system "#{command} #{opts}"
    end

    def parallel_run(opts = nil, _settings = nil)
      command = File.directory?('spec') ? 'parallel_rspec spec/' : 'parallel_cucumber features'
      system "#{command} #{opts}"
    end

    private

    def overwrite_yaml
      File.open(@path, 'w') { |file| YAML.dump(config, file) }
    end

    def config
      @config ||= File.exist?(@path) ? YAML.load_file(@path) : nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_raider-0.9.0 lib/utilities/utilities.rb