lopata 0.1.12 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +1,31 @@
1
- module Lopata
2
- # @private
3
- class Condition
4
- attr_reader :condition, :positive
5
- def initialize(condition, positive: true)
6
- @condition, @positive = condition, positive
7
- end
8
-
9
- alias positive? positive
10
-
11
- def match?(scenario)
12
- matched = match_metadata?(scenario)
13
- positive? ? matched : !matched
14
- end
15
-
16
- def match_metadata?(scenario)
17
- metadata = scenario.metadata
18
- case condition
19
- when Hash
20
- condition.keys.all? { |k| metadata[k] == condition[k] }
21
- when Array
22
- condition.map { |key| metadata[key] }.all?
23
- when TrueClass, FalseClass
24
- condition
25
- else
26
- metadata[condition]
27
- end
28
- end
29
-
30
- end
1
+ module Lopata
2
+ # @private
3
+ class Condition
4
+ attr_reader :condition, :positive
5
+ def initialize(condition, positive: true)
6
+ @condition, @positive = condition, positive
7
+ end
8
+
9
+ alias positive? positive
10
+
11
+ def match?(scenario)
12
+ matched = match_metadata?(scenario)
13
+ positive? ? matched : !matched
14
+ end
15
+
16
+ def match_metadata?(scenario)
17
+ metadata = scenario.metadata
18
+ case condition
19
+ when Hash
20
+ condition.keys.all? { |k| metadata[k] == condition[k] }
21
+ when Array
22
+ condition.map { |key| metadata[key] }.all?
23
+ when TrueClass, FalseClass
24
+ condition
25
+ else
26
+ metadata[condition]
27
+ end
28
+ end
29
+
30
+ end
31
31
  end
@@ -1,126 +1,126 @@
1
- module Lopata
2
- # Stores runtime configuration information
3
- #
4
- # @see Lopata.configure
5
- # @see Lopata.configuration
6
- class Configuration
7
- # Build an object to store runtime configuration options and set defaults
8
- def initialize
9
- @before_start_hooks = []
10
- @before_scenario_steps = []
11
- @after_scenario_steps = []
12
- @observers = [Lopata::Observers::ConsoleOutputObserver.new]
13
- @role_descriptions = {}
14
- @env = :qa
15
- end
16
-
17
- # Add the hook to be called before scenarios running
18
- # The block will be called after framework initialization and before scenarios parsing.
19
- # It usually allow to require and initialize the libraries used for project testing.
20
- #
21
- # @example
22
- # Lopata.configure do |c|
23
- # c.before_start do
24
- # require 'active_record'
25
- # end
26
- # end
27
- def before_start(&block)
28
- @before_start_hooks << block
29
- end
30
-
31
- # @private
32
- def run_before_start_hooks
33
- @before_start_hooks.each(&:call)
34
- end
35
-
36
- # Defines 'before scenario' steps.
37
- # Given steps will be runned before each scenario in context of scenario.
38
- # It may be shared step names, and|or block.
39
- #
40
- # @example
41
- # Lopata.configure do |c|
42
- # c.before_scenario 'setup test user'
43
- # end
44
- #
45
- # @param steps [Array<String>] name of shared steps
46
- # @param block [Proc] block of code
47
- def before_scenario(*steps, &block)
48
- before_scenario_steps.append(*steps) unless steps.empty?
49
- before_scenario_steps.append(block) if block_given?
50
- end
51
-
52
- # Defines 'after scenario' steps.
53
- # Given steps will be runned after each scenario in context of scenario.
54
- # It may be shared step names, and|or block.
55
- #
56
- # @example
57
- # Lopata.configure do |c|
58
- # c.after_scenario 'cleanup test user'
59
- # end
60
- #
61
- # @param steps [Array<String>] name of shared steps
62
- # @param block [Proc] block of code
63
- def after_scenario(*steps, &block)
64
- after_scenario_steps.append(*steps) unless steps.empty?
65
- after_scenario_steps.append(block) if block_given?
66
- end
67
-
68
- # @private
69
- attr_reader :before_scenario_steps, :after_scenario_steps
70
-
71
- # Add an observer to the set Lopata to be used for this run.
72
- #
73
- # @param observer [Lopata::Observers::BaseObserver] a observer instance.
74
- #
75
- # @see Lopata::Observers::BaseObserver
76
- def add_observer(observer)
77
- @observers << observer
78
- end
79
-
80
- # @private
81
- attr_reader :observers
82
-
83
- # @private
84
- def filters
85
- @filters ||= []
86
- end
87
-
88
- # @private
89
- attr_accessor :web_logging_params
90
-
91
- # @private
92
- def init_lopata_logging(url, project_code, build_number)
93
- require 'lopata/observers/web_logger'
94
- self.web_logging_params = { url: url, project_code: project_code, build_number: build_number }
95
- add_observer Lopata::Observers::WebLogger.new
96
- end
97
-
98
- # @return [Hash{Symbol => String}] map or role codes to role name.
99
- # @see Lopata::Role
100
- attr_accessor :role_descriptions
101
-
102
- # @return [Symbol,nil] user role to be used in scenario if not specified
103
- # @see Lopata::Role
104
- attr_accessor :default_role
105
-
106
- # @return [Symbol] environment code.
107
- # Default is :qa
108
- # @see Lopata::Environment
109
- attr_accessor :env
110
-
111
- # @return [Boolean] keep generated test data after scenarios running.
112
- # Default is false
113
- # Set to true for keeping generated data.
114
- # Use 'lopata --keep' modifier to set keep mode on running.
115
- # @see Lopata::ActiveRecord::Methods#cleanup
116
- attr_accessor :keep
117
-
118
- # @private
119
- attr_accessor :environment
120
-
121
- # @private
122
- def load_environment
123
- self.environment = Lopata::Environment.new(env)
124
- end
125
- end
1
+ module Lopata
2
+ # Stores runtime configuration information
3
+ #
4
+ # @see Lopata.configure
5
+ # @see Lopata.configuration
6
+ class Configuration
7
+ # Build an object to store runtime configuration options and set defaults
8
+ def initialize
9
+ @before_start_hooks = []
10
+ @before_scenario_steps = []
11
+ @after_scenario_steps = []
12
+ @observers = [Lopata::Observers::ConsoleOutputObserver.new]
13
+ @role_descriptions = {}
14
+ @env = :qa
15
+ end
16
+
17
+ # Add the hook to be called before scenarios running
18
+ # The block will be called after framework initialization and before scenarios parsing.
19
+ # It usually allow to require and initialize the libraries used for project testing.
20
+ #
21
+ # @example
22
+ # Lopata.configure do |c|
23
+ # c.before_start do
24
+ # require 'active_record'
25
+ # end
26
+ # end
27
+ def before_start(&block)
28
+ @before_start_hooks << block
29
+ end
30
+
31
+ # @private
32
+ def run_before_start_hooks
33
+ @before_start_hooks.each(&:call)
34
+ end
35
+
36
+ # Defines 'before scenario' steps.
37
+ # Given steps will be runned before each scenario in context of scenario.
38
+ # It may be shared step names, and|or block.
39
+ #
40
+ # @example
41
+ # Lopata.configure do |c|
42
+ # c.before_scenario 'setup test user'
43
+ # end
44
+ #
45
+ # @param steps [Array<String>] name of shared steps
46
+ # @param block [Proc] block of code
47
+ def before_scenario(*steps, &block)
48
+ before_scenario_steps.append(*steps) unless steps.empty?
49
+ before_scenario_steps.append(block) if block_given?
50
+ end
51
+
52
+ # Defines 'after scenario' steps.
53
+ # Given steps will be runned after each scenario in context of scenario.
54
+ # It may be shared step names, and|or block.
55
+ #
56
+ # @example
57
+ # Lopata.configure do |c|
58
+ # c.after_scenario 'cleanup test user'
59
+ # end
60
+ #
61
+ # @param steps [Array<String>] name of shared steps
62
+ # @param block [Proc] block of code
63
+ def after_scenario(*steps, &block)
64
+ after_scenario_steps.append(*steps) unless steps.empty?
65
+ after_scenario_steps.append(block) if block_given?
66
+ end
67
+
68
+ # @private
69
+ attr_reader :before_scenario_steps, :after_scenario_steps
70
+
71
+ # Add an observer to the set Lopata to be used for this run.
72
+ #
73
+ # @param observer [Lopata::Observers::BaseObserver] a observer instance.
74
+ #
75
+ # @see Lopata::Observers::BaseObserver
76
+ def add_observer(observer)
77
+ @observers << observer
78
+ end
79
+
80
+ # @private
81
+ attr_reader :observers
82
+
83
+ # @private
84
+ def filters
85
+ @filters ||= []
86
+ end
87
+
88
+ # @private
89
+ attr_accessor :web_logging_params
90
+
91
+ # @private
92
+ def init_lopata_logging(url, project_code, build_number)
93
+ require 'lopata/observers/web_logger'
94
+ self.web_logging_params = { url: url, project_code: project_code, build_number: build_number }
95
+ add_observer Lopata::Observers::WebLogger.new
96
+ end
97
+
98
+ # @return [Hash{Symbol => String}] map or role codes to role name.
99
+ # @see Lopata::Role
100
+ attr_accessor :role_descriptions
101
+
102
+ # @return [Symbol,nil] user role to be used in scenario if not specified
103
+ # @see Lopata::Role
104
+ attr_accessor :default_role
105
+
106
+ # @return [Symbol] environment code.
107
+ # Default is :qa
108
+ # @see Lopata::Environment
109
+ attr_accessor :env
110
+
111
+ # @return [Boolean] keep generated test data after scenarios running.
112
+ # Default is false
113
+ # Set to true for keeping generated data.
114
+ # Use 'lopata --keep' modifier to set keep mode on running.
115
+ # @see Lopata::ActiveRecord::Methods#cleanup
116
+ attr_accessor :keep
117
+
118
+ # @private
119
+ attr_accessor :environment
120
+
121
+ # @private
122
+ def load_environment
123
+ self.environment = Lopata::Environment.new(env)
124
+ end
125
+ end
126
126
  end
@@ -1,36 +1,36 @@
1
- module Lopata
2
- # Settings of test enviromnet the scenarios to be runned.
3
- #
4
- # Lopata allows to define different environments the scenarios to be runned on.
5
- # Set environment name via command line 'lopata -e stage' or via configuration:
6
- #
7
- # Lopata.configure do |c|
8
- # c.env = :stage
9
- # end
10
- #
11
- # The environment params are loaded from './config/environments/<env>.yml'.
12
- class Environment
13
- # Loads environment configuration for given env
14
- # @param env [Symbol] environment key
15
- # Loads golobl configured environment if not given.
16
- # @see Lopata::Configuration#env
17
- def initialize(env = Lopata.configuration.env)
18
- require 'yaml'
19
- @config = {}
20
- config_filename = "./config/environments/#{Lopata.configuration.env}.yml"
21
- @config = YAML::load(File.open(config_filename)) if File.exists?(config_filename)
22
- end
23
-
24
- # Access to environment settings
25
- # @param key [Symbol] environment configuration key is set on yml configuration.
26
- def [](key)
27
- @config[key]
28
- end
29
-
30
- %w{url}.each do |opt|
31
- define_method opt do
32
- @config[opt]
33
- end
34
- end
35
- end
1
+ module Lopata
2
+ # Settings of test enviromnet the scenarios to be runned.
3
+ #
4
+ # Lopata allows to define different environments the scenarios to be runned on.
5
+ # Set environment name via command line 'lopata -e stage' or via configuration:
6
+ #
7
+ # Lopata.configure do |c|
8
+ # c.env = :stage
9
+ # end
10
+ #
11
+ # The environment params are loaded from './config/environments/<env>.yml'.
12
+ class Environment
13
+ # Loads environment configuration for given env
14
+ # @param env [Symbol] environment key
15
+ # Loads golobl configured environment if not given.
16
+ # @see Lopata::Configuration#env
17
+ def initialize(env = Lopata.configuration.env)
18
+ require 'yaml'
19
+ @config = {}
20
+ config_filename = "./config/environments/#{Lopata.configuration.env}.yml"
21
+ @config = YAML::load(File.open(config_filename)) if File.exists?(config_filename)
22
+ end
23
+
24
+ # Access to environment settings
25
+ # @param key [Symbol] environment configuration key is set on yml configuration.
26
+ def [](key)
27
+ @config[key]
28
+ end
29
+
30
+ %w{url}.each do |opt|
31
+ define_method opt do
32
+ @config[opt]
33
+ end
34
+ end
35
+ end
36
36
  end
@@ -1,72 +1,72 @@
1
- require_relative 'active_record'
2
-
3
- module Lopata
4
- # Helpers for FactoryBot usage in tests.
5
- #
6
- # Make helpers available in scenarios by
7
- #
8
- # require 'lopata/factory_bot'
9
- #
10
- # Automatically adds ActiveRecord helpers.
11
- # @see Lopata::ActiveRecord
12
- #
13
- # Allows to create ActiveRecord object by FactoryBot definitions.
14
- # All the objects created by FactoryBot helpers will be destroyed automatically
15
- # at the end of scenario.
16
- # @see Lopata::ActiveRecord::Methods#cleanup
17
- #
18
- # @example
19
- #
20
- # # Configure db connection at config/environments/qa.yml like rails:
21
- # # db:
22
- # # adapter: postgresql
23
- # # host: your.database.host
24
- # # username: username
25
- # # password: password
26
- # # database: database
27
- # require 'active_record'
28
- # require 'factory_bot'
29
- # require 'lopata/facotory_bot'
30
- #
31
- # class User < ActiveRecord::Base; end
32
- #
33
- # FactoryBot.define do
34
- # factory :user do
35
- # username { 'testuser' }
36
- # end
37
- # end
38
- #
39
- # Lopata.define 'User creation' do
40
- # setup do
41
- # @user = create(:user)
42
- # end
43
- # # No cleanup needed - @user will be destroyed automatically
44
- # # cleanup :user
45
- #
46
- # it 'works' do
47
- # expect(@user).to_not be_nil
48
- # end
49
- # end
50
- #
51
- module FactoryBot
52
- # To be included in Lopata::Scenario
53
- module Methods
54
- # Wrapper for FactoryBot#create
55
- # Calls the FactoryBot#create with given paramters and returns it result.
56
- # Additionally store the created object for destroying at the end of scenario.
57
- # @see Lopata::ActiveRecord::Methods#cleanup
58
- def create(*params)
59
- cleanup_later ::FactoryBot.create(*params)
60
- end
61
- end
62
-
63
- # To be included in Lopata::ScenarioBuilder
64
- module DSL
65
- end
66
- end
67
- end
68
-
69
- Lopata::Scenario.include Lopata::FactoryBot::Methods
70
- Lopata::ScenarioBuilder.include Lopata::FactoryBot::DSL
71
-
72
- ::FactoryBot.find_definitions
1
+ require_relative 'active_record'
2
+
3
+ module Lopata
4
+ # Helpers for FactoryBot usage in tests.
5
+ #
6
+ # Make helpers available in scenarios by
7
+ #
8
+ # require 'lopata/factory_bot'
9
+ #
10
+ # Automatically adds ActiveRecord helpers.
11
+ # @see Lopata::ActiveRecord
12
+ #
13
+ # Allows to create ActiveRecord object by FactoryBot definitions.
14
+ # All the objects created by FactoryBot helpers will be destroyed automatically
15
+ # at the end of scenario.
16
+ # @see Lopata::ActiveRecord::Methods#cleanup
17
+ #
18
+ # @example
19
+ #
20
+ # # Configure db connection at config/environments/qa.yml like rails:
21
+ # # db:
22
+ # # adapter: postgresql
23
+ # # host: your.database.host
24
+ # # username: username
25
+ # # password: password
26
+ # # database: database
27
+ # require 'active_record'
28
+ # require 'factory_bot'
29
+ # require 'lopata/facotory_bot'
30
+ #
31
+ # class User < ActiveRecord::Base; end
32
+ #
33
+ # FactoryBot.define do
34
+ # factory :user do
35
+ # username { 'testuser' }
36
+ # end
37
+ # end
38
+ #
39
+ # Lopata.define 'User creation' do
40
+ # setup do
41
+ # @user = create(:user)
42
+ # end
43
+ # # No cleanup needed - @user will be destroyed automatically
44
+ # # cleanup :user
45
+ #
46
+ # it 'works' do
47
+ # expect(@user).to_not be_nil
48
+ # end
49
+ # end
50
+ #
51
+ module FactoryBot
52
+ # To be included in Lopata::Scenario
53
+ module Methods
54
+ # Wrapper for FactoryBot#create
55
+ # Calls the FactoryBot#create with given paramters and returns it result.
56
+ # Additionally store the created object for destroying at the end of scenario.
57
+ # @see Lopata::ActiveRecord::Methods#cleanup
58
+ def create(*params)
59
+ cleanup_later ::FactoryBot.create(*params)
60
+ end
61
+ end
62
+
63
+ # To be included in Lopata::ScenarioBuilder
64
+ module DSL
65
+ end
66
+ end
67
+ end
68
+
69
+ Lopata::Scenario.include Lopata::FactoryBot::Methods
70
+ Lopata::ScenarioBuilder.include Lopata::FactoryBot::DSL
71
+
72
+ ::FactoryBot.find_definitions