moto 0.9.11 → 0.9.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  require_relative 'run_status'
2
- require_relative 'listeners/base'
3
2
 
4
3
  module Moto
5
4
  module Reporting
data/lib/test/base.rb CHANGED
@@ -28,7 +28,6 @@ module Moto
28
28
 
29
29
  # Initializes test to be executed with specified params and environment
30
30
  def init(params_path)
31
- @env = Moto::Lib::Config.environment
32
31
  @params = []
33
32
  @params_path = params_path
34
33
 
@@ -40,7 +39,6 @@ module Moto
40
39
  @status.test_class_name = self.class.name
41
40
  @status.display_name = @status.test_class_name.split('::')[2..-2].join(' > ')
42
41
  @status.display_name += "_#{@params_path.split('/')[-1].chomp('.param')}" if @params_path
43
- @status.env = Moto::Lib::Config.environment
44
42
  end
45
43
 
46
44
  # Setter for :log_path
@@ -1,11 +1,13 @@
1
+ require_relative 'base'
2
+
1
3
  module MotoApp
2
4
  module Tests
3
5
  end
4
6
  end
5
7
 
6
8
  module Moto
7
- module Runner
8
- class TestGenerator
9
+ module Test
10
+ class Generator
9
11
 
10
12
  def initialize
11
13
  @internal_counter = 0
@@ -16,10 +18,11 @@ module Moto
16
18
  # Example: A test with a config file and 2 sets of parameters there will be returned as array with two elements.
17
19
  #
18
20
  # @param [Moto::Test::Metadata] test_metadata Metadata that describes test to be instantiated
21
+ # @param [Integer] variants_limit Limit how many params will be parsed per test. Default: 0 (no limit)
19
22
  # @return [Array] An array of [Moto::Test::Base] descendants
20
23
  # each entry is a Test with set of parameters injected
21
- def get_test_with_variants(test_metadata)
22
- variantize(test_metadata)
24
+ def get_test_with_variants(test_metadata, variants_limit = 0)
25
+ variantize(test_metadata, variants_limit)
23
26
  end
24
27
 
25
28
  # Converts test's path to an array of Moto::Base::Test instances that represent all test variants (params)
@@ -29,36 +32,36 @@ module Moto
29
32
  # they must be required prior to that. That might be done in overloaded app's initializer.
30
33
  #
31
34
  # @param [Moto::Test::Metadata] test_metadata Metadata that describes test to be instantiated, contains path to test
35
+ # @param [Integer] variants_limit Limit how many params will be parsed per test.
32
36
  # @return [Array] array of already initialized test's variants
33
- def variantize(test_metadata)
37
+ def variantize(test_metadata, variants_limit)
34
38
  variants = []
35
39
 
36
- # TODO CHANGED TEMPORARY
37
- #params_path = test_path_absolute.sub(/\.rb\z/, '')
38
- params_directory = File.dirname(test_metadata.test_path).to_s + '/params/**'
39
- param_files_paths = Dir.glob(params_directory)
40
- param_files_paths = [nil] if param_files_paths.empty?
40
+ # TODO CHANGED TEMPORARY
41
+ #params_path = test_path_absolute.sub(/\.rb\z/, '')
42
+ params_directory = File.dirname(test_metadata.test_path).to_s + '/params/**'
43
+ param_files_paths = Dir.glob(params_directory)
44
+ param_files_paths = [nil] if param_files_paths.empty?
41
45
 
42
- param_files_paths.each do |params_path|
46
+ param_files_paths.each do |params_path|
43
47
 
44
- #TODO environment support
45
- # Filtering out param sets that are specific to certain envs
46
- # unless params['__env'].nil?
47
- # allowed_envs = params['__env'].is_a?(String) ? [params['__env']] : params['__env']
48
- # next unless allowed_envs.include?(Moto::Lib::Config.environment)
49
- # end
48
+ # TODO Name/logname/displayname
49
+ test = generate(test_metadata)
50
+ test.init(params_path)
51
+ test.log_path = "#{File.dirname(test_metadata.test_path).to_s}/logs/#{test.name.gsub(/[^0-9A-Za-z.\-]/, '_')}.log"
52
+ @internal_counter += 1
50
53
 
51
- #TODO Name/logname/displayname
52
- test = generate(test_metadata)
53
- test.init(params_path)
54
- test.log_path = "#{File.dirname(test_metadata.test_path).to_s}/logs/#{test.name.gsub(/[^0-9A-Za-z.\-]/, '_')}.log"
55
- @internal_counter += 1
54
+ variants << test
56
55
 
57
- variants << test
56
+ # Break if limit of parametrized variants has been reached
57
+ if variants_limit > 0 && variants.length == variants_limit
58
+ break
58
59
  end
60
+ end
59
61
 
60
62
  variants
61
63
  end
64
+
62
65
  private :variantize
63
66
 
64
67
  # Generates test instances
data/lib/test/metadata.rb CHANGED
@@ -32,7 +32,7 @@ module Moto
32
32
  end
33
33
  private :text
34
34
 
35
- # @return [Array] of [String] which represent contents of #MOTO_TAGS
35
+ # @return [Array<String>] which represent contents of #MOTO_TAGS
36
36
  def tags
37
37
  if @tags.nil?
38
38
  matches = text.match(/^#(\s*)MOTO_TAGS:(.*?)$/)
@@ -0,0 +1,78 @@
1
+ require 'logger'
2
+ require 'pp'
3
+ require 'yaml'
4
+
5
+ module MotoApp
6
+ DIR = Dir.pwd
7
+ end
8
+
9
+ require_relative 'metadata'
10
+ require_relative '../version'
11
+ require_relative '../config'
12
+
13
+ module Moto
14
+ module Test
15
+ class MetadataGenerator
16
+
17
+ def self.generate(directories = nil, tags = nil, filters = nil)
18
+ tests_metadata = []
19
+
20
+ if directories
21
+ directories.each do |directory|
22
+ Dir.glob("#{MotoApp::DIR}/tests/#{directory}/**/*.rb").each do |test_path|
23
+ tests_metadata << Moto::Test::Metadata.new(test_path)
24
+ end
25
+ end
26
+ end
27
+
28
+ if tags
29
+ tests_total = Dir.glob("#{MotoApp::DIR}/tests/**/*.rb")
30
+ tests_total.each do |test_path|
31
+
32
+ metadata = Moto::Test::Metadata.new(test_path)
33
+ tests_metadata << metadata unless (tags & metadata.tags).empty?
34
+
35
+ end
36
+ end
37
+
38
+ # Make sure there are no repetitions in gathered set
39
+ tests_metadata.uniq! {|metadata| metadata.test_path}
40
+
41
+ # Filter tests by provied tags
42
+ # - test must contain ALL tags specified with -f param
43
+ # - use ~ for negation
44
+ # - test may contain other tags
45
+ if filters
46
+ filters.each do |filter|
47
+ filtered = tests_metadata.select do |metadata|
48
+ next if metadata.tags.empty?
49
+ filter_matches_any_tag?(filter, metadata.tags) || filter_negation_matches_none_tag?(filter, metadata.tags)
50
+ end
51
+ tests_metadata &= filtered
52
+ end
53
+ end
54
+
55
+ # TODO: THIS SHOULDN'T BE HERE - REMNANT OF THE PAST
56
+ # Requires custom initializer if provided by application that uses Moto
57
+ if File.exists?("#{MotoApp::DIR}/lib/initializer.rb")
58
+ require("#{MotoApp::DIR}/lib/initializer.rb")
59
+ initializer = MotoApp::Lib::Initializer.new
60
+ initializer.init
61
+ end
62
+
63
+ return tests_metadata
64
+ end
65
+
66
+ def self.filter_matches_any_tag?(filter, tags)
67
+ !filter.start_with?('~') && tags.any? {|tag| filter == tag}
68
+ end
69
+ private_class_method :filter_matches_any_tag?
70
+
71
+ def self.filter_negation_matches_none_tag?(filter, tags)
72
+ filter.start_with?('~') && tags.none? {|tag| filter[1..-1] == tag}
73
+ end
74
+ private_class_method :filter_negation_matches_none_tag?
75
+
76
+ end
77
+ end
78
+ end
data/lib/test/status.rb CHANGED
@@ -20,9 +20,6 @@ module Moto
20
20
  # Array of [Moto::Test::Result], each item represents a result of a single attempt to pass the test
21
21
  attr_reader :results
22
22
 
23
- # Environment on which test was run
24
- attr_accessor :env
25
-
26
23
  # Set of params on which test was based
27
24
  attr_accessor :params
28
25
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Moto
2
- VERSION = '0.9.11'
2
+ VERSION = '0.9.17'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.11
4
+ version: 0.9.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartek Wilczek
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-07-31 00:00:00.000000000 Z
14
+ date: 2017-08-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -84,32 +84,32 @@ extensions: []
84
84
  extra_rdoc_files: []
85
85
  files:
86
86
  - bin/moto
87
- - lib/app_generator.rb
88
- - lib/cli.rb
89
87
  - lib/config.rb
90
88
  - lib/empty_listener.rb
91
- - lib/exceptions/moto.rb
89
+ - lib/exceptions/base.rb
92
90
  - lib/exceptions/test_forced_failure.rb
93
91
  - lib/exceptions/test_forced_passed.rb
94
92
  - lib/exceptions/test_skipped.rb
95
- - lib/initializer.rb
96
- - lib/parser.rb
93
+ - lib/modes/generate/test_template_generator.rb
94
+ - lib/modes/mode_selector.rb
95
+ - lib/modes/run/dry_runner.rb
96
+ - lib/modes/run/test_provider.rb
97
+ - lib/modes/run/test_runner.rb
98
+ - lib/modes/run/thread_context.rb
99
+ - lib/modes/validate/test_validator.rb
100
+ - lib/parameter_parser.rb
97
101
  - lib/reporting/listeners/base.rb
98
102
  - lib/reporting/listeners/console.rb
99
103
  - lib/reporting/listeners/console_dots.rb
100
104
  - lib/reporting/listeners/junit_xml.rb
101
105
  - lib/reporting/listeners/webui.rb
102
- - lib/reporting/listeners/webui_deprecated.rb
103
106
  - lib/reporting/run_status.rb
104
107
  - lib/reporting/test_reporter.rb
105
- - lib/runner/dry_runner.rb
106
- - lib/runner/test_generator.rb
107
- - lib/runner/test_provider.rb
108
- - lib/runner/test_runner.rb
109
- - lib/runner/thread_context.rb
110
108
  - lib/runner_logging.rb
111
109
  - lib/test/base.rb
110
+ - lib/test/generator.rb
112
111
  - lib/test/metadata.rb
112
+ - lib/test/metadata_generator.rb
113
113
  - lib/test/result.rb
114
114
  - lib/test/status.rb
115
115
  - lib/test_logging.rb
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.6.11
137
+ rubygems_version: 2.5.2
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Moto - yet another web testing framework
data/lib/app_generator.rb DELETED
@@ -1,80 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Moto
4
- class AppGenerator
5
-
6
- # Creates directories and file with class template for a test.
7
- # @param options [Hash] Informations required perfrom the task.
8
- # options[:app_name] Name of the application that uses Moto Framework.
9
- # options[:dir] Subdirectories of MotoApp/tests/ where test should be placed.
10
- # options[:base_class] Path and filename of class from which the test will derive.
11
- # options[:force] Whether generator should forcibly overwrite previously existing file.
12
- def self.run(options)
13
-
14
- # Build list of modules basing on the name of the application and subdirectory provided by the user.
15
- # Second module is always 'tests' since it's where they should be kept.
16
- modules = [options[:app_name], 'tests'] + options[:dir].split('/')
17
- modules.map!(&:camelize)
18
-
19
- # Name of the class in the template
20
- class_name = modules.last
21
-
22
- # Evaluate fully qualified name of the class to derive from or, if not specified
23
- # use Moto's default one
24
- if options[:base_class].nil?
25
- base_class_qualified_name = 'Moto::Test::Base'
26
- else
27
- base_class_qualified_name = "#{options[:app_name]}::Lib::Test::#{options[:base_class].split('/').join('::').camelize}"
28
- end
29
-
30
- # Where to put finished template
31
- test_file = File.basename(options[:dir]) + '.rb'
32
- test_dir = MotoApp::DIR + '/tests/' + options[:dir]
33
- test_path = "#{test_dir}/#{test_file}"
34
-
35
- # Create directory
36
- FileUtils.mkdir_p(test_dir)
37
-
38
- if !File.exist?(test_path) || options[:force]
39
- # Create new file in specified location and add class' template to it
40
- File.open(test_path, 'w+') do |file|
41
-
42
- indent = 0
43
-
44
- file << "# FULL_CODE\n"
45
-
46
- if options[:base_class].nil?
47
- file << "\n"
48
- else
49
- file << "require './lib/test/#{options[:base_class]}.rb'\n\n"
50
- end
51
-
52
- modules.each do |m|
53
- file << (' ' * indent) + "module #{m}\n"
54
- indent += 2
55
- end
56
-
57
- file << (' ' * indent) + "# Class template genereated by 'moto generate'\n"
58
- file << (' ' * indent) + "class #{class_name} < #{base_class_qualified_name}\n\n"
59
- indent += 2
60
- file << (' ' * indent) + "def run\n"
61
- file << (' ' * indent) + "end\n\n"
62
- indent -= 2
63
- file << (' ' * indent) + "end\n"
64
-
65
- modules.each do
66
- indent -= 2
67
- file << (' ' * indent) + "end\n"
68
- end
69
-
70
- end
71
-
72
- puts 'Result:'
73
- puts " File: #{test_path}"
74
- puts " Class: #{class_name} < #{base_class_qualified_name}"
75
- else
76
- raise 'File already exists. Use -f or --force to overwrite existing contents.'
77
- end
78
- end
79
- end
80
- end
data/lib/cli.rb DELETED
@@ -1,120 +0,0 @@
1
- require 'logger'
2
- require 'pp'
3
- require 'yaml'
4
- require 'active_support/inflector'
5
- require 'active_support/core_ext/object/blank'
6
-
7
- module MotoApp
8
- DIR = Dir.pwd
9
- end
10
-
11
- module Moto
12
- DIR = File.dirname(File.dirname(__FILE__))
13
- end
14
-
15
- require_relative './test_logging'
16
- require_relative './runner_logging'
17
- require_relative './runner/dry_runner'
18
- require_relative './runner/test_runner'
19
- require_relative './runner/thread_context'
20
- require_relative './runner/test_generator'
21
- require_relative './test/base'
22
- require_relative './test/metadata'
23
- require_relative './version'
24
- require_relative './reporting/listeners/base'
25
- require_relative './reporting/listeners/console'
26
- require_relative './reporting/listeners/console_dots'
27
- require_relative './reporting/listeners/junit_xml'
28
- require_relative './reporting/listeners/webui'
29
- require_relative './exceptions/moto'
30
- require_relative './exceptions/test_skipped'
31
- require_relative './exceptions/test_forced_failure'
32
- require_relative './exceptions/test_forced_passed'
33
- require_relative 'config'
34
-
35
- module Moto
36
-
37
- class Cli
38
- def self.run(argv)
39
-
40
- tests_metadata = []
41
- directories = argv[:tests]
42
- tags = argv[:tags]
43
- filters = argv[:filters]
44
-
45
- if directories
46
- directories.each do |directory|
47
- Dir.glob("#{MotoApp::DIR}/tests/#{directory}/**/*.rb").each do |test_path|
48
- tests_metadata << Moto::Test::Metadata.new(test_path)
49
- end
50
- end
51
- end
52
-
53
- if tags
54
- tests_total = Dir.glob("#{MotoApp::DIR}/tests/**/*.rb")
55
- tests_total.each do |test_path|
56
-
57
- metadata = Moto::Test::Metadata.new(test_path)
58
- tests_metadata << metadata unless (tags & metadata.tags).empty?
59
-
60
- end
61
- end
62
-
63
- # Make sure there are no repetitions in gathered set
64
- tests_metadata.uniq! { |metadata| metadata.test_path }
65
-
66
- # Filter tests by provied tags
67
- # - test must contain ALL tags specified with -f param
68
- # - use ~ for negation
69
- # - test may contain other tags
70
- if filters
71
- filters.each do |filter|
72
- filtered = tests_metadata.select do |metadata|
73
- next if metadata.tags.empty?
74
- filter_matches_any_tag?(filter, metadata.tags) || filter_negation_matches_none_tag?(filter, metadata.tags)
75
- end
76
- tests_metadata &= filtered
77
- end
78
- end
79
-
80
- #TODO Display criteria used
81
- if tests_metadata.empty?
82
- puts 'No tests found for given arguments.'
83
- Kernel.exit(-1)
84
- end
85
-
86
- # Requires custom initializer if provided by application that uses Moto
87
- if File.exists?( "#{MotoApp::DIR}/lib/initializer.rb" )
88
- require("#{Moto::DIR}/lib/initializer.rb")
89
- require("#{MotoApp::DIR}/lib/initializer.rb")
90
- initializer = MotoApp::Lib::Initializer.new(self)
91
- initializer.init
92
- end
93
-
94
- run_params = {}
95
- run_params[:run_name] = argv[:run_name]
96
- run_params[:suite_name] = argv[:suite_name]
97
- run_params[:assignee] = argv[:assignee]
98
-
99
- test_reporter = Moto::Reporting::TestReporter.new(argv[:listeners], run_params)
100
-
101
- if Moto::Lib::Config.moto[:test_runner][:dry_run]
102
- runner = Moto::Runner::DryRunner.new(tests_metadata, test_reporter)
103
- else
104
- runner = Moto::Runner::TestRunner.new(tests_metadata, test_reporter, argv[:stop_on])
105
- end
106
- runner.run
107
- end
108
-
109
- def self.filter_matches_any_tag?(filter, tags)
110
- !filter.start_with?('~') && tags.any? { |tag| filter == tag }
111
- end
112
- private_class_method :filter_matches_any_tag?
113
-
114
- def self.filter_negation_matches_none_tag?(filter, tags)
115
- filter.start_with?('~') && tags.none? { |tag| filter[1..-1] == tag }
116
- end
117
- private_class_method :filter_negation_matches_none_tag?
118
-
119
- end
120
- end