dbrady-tourbus 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/tourbus +22 -6
  2. data/lib/common.rb +1 -1
  3. data/lib/tour.rb +12 -3
  4. metadata +1 -1
data/bin/tourbus CHANGED
@@ -1,16 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'common'))
4
3
  require 'trollop'
5
4
  require_all_files_in_folder 'tours'
6
5
 
6
+ # load config file, we'll use these as defaults
7
+ config_file = ["./tourbus.yml", "./tours/tourbus.yml", "./config/tourbus.yml", "~/tourbus.yml"].map {|p| File.expand_path(p)}.find {|p| File.exists? p}
8
+ config = config_file ? YAML::load_file(config_file).symbolize_keys : {}
9
+
10
+ config_map = { :host => :to_s, :concurrency => :to_i, :number => :to_i, :rand => :to_i }
11
+ config_map.each {|key,conv| config[key] = config[key].send(conv) if config.key? key }
12
+
13
+ # defaults
14
+ config[:host] ||= "localhost:3000"
15
+ config[:concurrency] ||= 1
16
+ config[:number] ||= 1
17
+ config[:rand] ||= nil
18
+
7
19
  opts = Trollop.options do
8
- opt :host, "Remote hostname to test", :default => "localhost:3000"
9
- opt :concurrency, "Number of simultaneous runs to perform", :type => :integer, :default => 1
10
- opt :number, "Number of times to run the tour (in each concurrent step, so -c 10 -n 10 will run the tour 100 times)", :type => :integer, :default => 1
11
- opt :verbose, "Run in verbose mode", :type => :boolean, :default => false
20
+ opt :host, "Remote hostname to test", :default => config[:host]
21
+ opt :concurrency, "Number of simultaneous runs to perform", :type => :integer, :default => config[:concurrency]
22
+ opt :number, "Number of times to run the tour (in each concurrent step, so -c 10 -n 10 will run the tour 100 times)", :type => :integer, :default => config[:number]
12
23
  opt :list, "List tours and runs available. If tours or runs are included, filters the list", :type => :boolean, :default => nil
13
- opt :rand, "Random seed", :type => :integer, :default => nil
24
+ opt :rand, "Random seed", :type => :integer, :default => config[:rand]
14
25
  end
15
26
 
16
27
  tours = if ARGV.empty?
@@ -21,6 +32,11 @@ tours = if ARGV.empty?
21
32
 
22
33
  srand opts[:rand] || Time.now.to_i
23
34
 
35
+ require 'pp'
36
+ pp config
37
+ puts '----'
38
+ pp opts
39
+ exit
24
40
  if opts[:list]
25
41
  Tour.tours(ARGV).each do |tour|
26
42
  puts tour
data/lib/common.rb CHANGED
@@ -21,7 +21,6 @@ require 'tour_bus'
21
21
  require 'runner'
22
22
  require 'tour'
23
23
 
24
-
25
24
  class TourBusException < Exception; end
26
25
 
27
26
  def require_all_files_in_folder(folder, extension = "*.rb")
@@ -29,3 +28,4 @@ def require_all_files_in_folder(folder, extension = "*.rb")
29
28
  require file
30
29
  end
31
30
  end
31
+
data/lib/tour.rb CHANGED
@@ -28,15 +28,24 @@ class Tour
28
28
  def self.tours(filter=[])
29
29
  filter = [filter].flatten
30
30
  # All files in tours folder, stripped to basename, that match any item in filter
31
- Dir[File.join('.', 'tours', '**', '*.rb')].map {|fn| File.basename(fn, ".rb")}.select {|fn| filter.size.zero? || filter.any?{|f| fn =~ /#{f}/}}
31
+ # I do loves me a long chain. This returns an array containing
32
+ # 1. All *.rb files in tour folder (recursive)
33
+ # 2. Each filename stripped to its basename
34
+ # 3. If you passed in any filters, these basenames are rejected unless they match at least one filter
35
+ # 4. The filenames remaining are then checked to see if they define a class of the same name that inherits from Tour
36
+ Dir[File.join('.', 'tours', '**', '*.rb')].map {|fn| File.basename(fn, ".rb")}.select {|fn| filter.size.zero? || filter.any?{|f| fn =~ /#{f}/}}.select {|tour| Tour.tour? tour }
32
37
  end
33
38
 
34
39
  def self.tests(tour_name)
35
- Tour.make_tour.tests
40
+ Tour.make_tour(tour_name).tests
41
+ end
42
+
43
+ def self.tour?(tour_name)
44
+ Object.const_defined?(tour_name.classify) && tour_name.classify.constantize.ancestors.include?(Tour)
36
45
  end
37
46
 
38
47
  # Factory method, creates the named child class instance
39
- def self.make_tour(tour_name,host,tours,number,tour_id)
48
+ def self.make_tour(tour_name,host="localhost:3000",tours=[],number=1,tour_id=nil)
40
49
  tour_name.classify.constantize.new(host,tours,number,tour_id)
41
50
  end
42
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbrady-tourbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Brady