Class: BrowserShooter::Configurator
- Inherits:
-
Object
- Object
- BrowserShooter::Configurator
- Defined in:
- lib/browser_shooter/configurator.rb
Instance Attribute Summary collapse
-
#suites ⇒ Object
readonly
Returns the value of attribute suites.
Class Method Summary collapse
-
.build_models(config) ⇒ Object
Creates the tests, browsers and suites arrays.
-
.filter_suites(models, opts) ⇒ Object
If special filter options has been defined in the _command options_ the suites are filtered to only play with the filtered ones.
-
.load_config(config_file_path) ⇒ Object
Load the config.yml file and return it in a Hash format.
- .load_extensions(extensions_paths) ⇒ Object
-
.load_external_tests(config) ⇒ Object
If the tests key in the config.yml is an string we load of the files in this path as tests and add them to the original config.
- .setup_output_path(output_path) ⇒ Object
Instance Method Summary collapse
-
#[](value) ⇒ Object
The hash version of the config.yml is available here.
-
#initialize(opts) ⇒ Configurator
constructor
Takes the digested command options and create and filter the models.
Constructor Details
#initialize(opts) ⇒ Configurator
Takes the digested command options and create and filter the models
6 7 8 9 10 11 12 |
# File 'lib/browser_shooter/configurator.rb', line 6 def initialize( opts ) @config = BrowserShooter::Configurator.load_config( opts[:config_file] ) models = BrowserShooter::Configurator.build_models( @config ) @suites = BrowserShooter::Configurator.filter_suites( models, opts ) BrowserShooter::Configurator.load_extensions( @config["extensions"] ) if @config["extensions"] end |
Instance Attribute Details
#suites ⇒ Object (readonly)
Returns the value of attribute suites.
3 4 5 |
# File 'lib/browser_shooter/configurator.rb', line 3 def suites @suites end |
Class Method Details
.build_models(config) ⇒ Object
Creates the tests, browsers and suites arrays.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/browser_shooter/configurator.rb', line 60 def self.build_models( config ) tests = config["tests"].map do |name, commands| test_commands = commands.split( "\n" ) BrowserShooter::Models::Test.new( name, test_commands ) end browsers = config["browsers"].map do |name, opts| BrowserShooter::Models::Browser.new( name, opts["url"], opts["type"], opts["vm"] ) end suites = config["suites"].map do |name, opts| suite_tests = BrowserShooter::Utils.find_by_names( tests, opts["tests"] ) suite_browsers = BrowserShooter::Utils.find_by_names( browsers, opts["browsers"] ) BrowserShooter::Models::Suite.new( name, suite_tests, suite_browsers ) end { :tests => tests, :browsers => browsers, :suites => suites } end |
.filter_suites(models, opts) ⇒ Object
If special filter options has been defined in the _command options_ the suites are filtered to only play with the filtered ones.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/browser_shooter/configurator.rb', line 90 def self.filter_suites( models, opts ) suites = [] if( opts[:suite] ) suite = BrowserShooter::Utils.find_by_name( models[:suites], opts[:suite] ) suites = [suite] elsif( opts[:test] && opts[:browsers] ) test = BrowserShooter::Utils.find_by_name( models[:tests], opts[:test] ) browsers = BrowserShooter::Utils.find_by_names( models[:browsers], opts[:browsers] ) suite = BrowserShooter::Models::Suite.new( "anonymous", [test], browsers ) suites = [suite] elsif( opts[:test] ) test = BrowserShooter::Utils.find_by_name( models[:tests], opts[:test] ) browsers = models[:browsers] suite = BrowserShooter::Models::Suite.new( "anonymous", [test], browsers ) suites = [suite] else suites = models[:suites] end suites end |
.load_config(config_file_path) ⇒ Object
Load the config.yml file and return it in a Hash format
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/browser_shooter/configurator.rb', line 20 def self.load_config( config_file_path ) config = { "output_path" => "~/browser_shooter", "timeout" => 40 } config.merge! YAML.load_file( config_file_path ) config["output_path"] = setup_output_path( config["output_path"] ) config["config_root_path"] = File.dirname( config_file_path ) # _tests_ key is a folder path for external test files if( config["tests"].is_a?( String ) ) config["tests"] = BrowserShooter::Configurator.load_external_tests( config ) end config end |
.load_extensions(extensions_paths) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/browser_shooter/configurator.rb', line 127 def self.load_extensions( extensions_paths ) extensions_paths.each do |extension_path| extension_path = File.( extension_path ) BrowserShooter::Logger.log( "Loading extension: #{extension_path}" ) Kernel.require( extension_path ) end end |
.load_external_tests(config) ⇒ Object
If the tests key in the config.yml is an string we load of the files in this path as tests and add them to the original config.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/browser_shooter/configurator.rb', line 42 def self.load_external_tests( config ) tests_path = File.join( config["config_root_path"], config["tests"] ) BrowserShooter::Logger.log( "Loading external tests: #{tests_path}" ) raise ArgumentError, "External tests dir path doesn't exist: 'tests_path'" if !File.exists?( tests_path ) tests = {} Dir.glob( "#{tests_path}/*.test" ).each do |test_path| test_name = File.basename( test_path, ".test" ) tests[ test_name ] = File.read( test_path ) end return tests end |
.setup_output_path(output_path) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/browser_shooter/configurator.rb', line 120 def self.setup_output_path( output_path ) output_path = File.( "#{output_path}/#{BrowserShooter::Utils.}" ) BrowserShooter::Logger.log( "output_path: #{output_path}" ) output_path end |
Instance Method Details
#[](value) ⇒ Object
The hash version of the config.yml is available here
15 16 17 |
# File 'lib/browser_shooter/configurator.rb', line 15 def [](value) @config[value] end |