lopata 0.1.13 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19371c76dcc39807c50470e95f365a09c1c33a8193a25b9d98d4d5648f5eaa59
4
- data.tar.gz: 25c3b8ea2efe44f5cf31f51cea04aa05f2ea35f364ed2167f9cdd466fa6a5e46
3
+ metadata.gz: b016b2963faca94942b2f9800c37be27e85221241a00c3f888775380983ebd13
4
+ data.tar.gz: 100227eb53c7642def09cf3c9edc64b0036ba2ddb766feeb441d159ca02e73d0
5
5
  SHA512:
6
- metadata.gz: 7b7378f73bd4fe3c7ce18bcd7e7a0d5f45b05cafac689d764ad3030f879ad1e0c1843e67ddd886ba68643632c33eea9824efbe0b370dea76fe911e03d95fc355
7
- data.tar.gz: af7ba11d74022ab03a11a62bec31291edba71e6b5c93f1229b765a159e2ce3d14813af5f2967c1d054d7f5e2fc656b593bdce876fbcb9a03cade19a0fbcb3753
6
+ metadata.gz: 646a6432a265c98966b2938564a57fb06e321a3b6cc67722b3021815586002e26e27fa4282eb5647404e5ca8582453747ee669b015e3e3ae666f3e706cbf3bfd
7
+ data.tar.gz: 9e4d413066ed6714024fa3df2252eb8c6256892036e1a9a89ab36f391a21db211b9c82d8b5afb3b89b293b4926e9af028527fa7360aa9ca17fe61d0b6796e2cd
data/README.md CHANGED
@@ -1,26 +1,26 @@
1
- # Lopata
2
-
3
- Functional acceptance testing using Ruby.
4
-
5
- ## Installation
6
-
7
- gem install lopata
8
-
9
- ## Usage
10
-
11
- Create new lopata project:
12
-
13
- lopata new <project-name>
14
-
15
- Setup environment: edit <project-name>/config/environments/qa.yml for setup project for testing.
16
-
17
- Write tests: puts tests in <project-name>/scenarios folder. Define shared steps in <project-name>/shared_steps folder.
18
-
19
- Run tests:
20
-
21
- cd <project-name>
22
- lopata
23
-
24
- ## Documentation
25
-
1
+ # Lopata
2
+
3
+ Functional acceptance testing using Ruby.
4
+
5
+ ## Installation
6
+
7
+ gem install lopata
8
+
9
+ ## Usage
10
+
11
+ Create new lopata project:
12
+
13
+ lopata new <project-name>
14
+
15
+ Setup environment: edit <project-name>/config/environments/qa.yml for setup project for testing.
16
+
17
+ Write tests: puts tests in <project-name>/scenarios folder. Define shared steps in <project-name>/shared_steps folder.
18
+
19
+ Run tests:
20
+
21
+ cd <project-name>
22
+ lopata
23
+
24
+ ## Documentation
25
+
26
26
  See [features description](https://github.com/avolochnev/lopata/tree/master/features) for documentation.
data/exe/lopata CHANGED
@@ -1,11 +1,11 @@
1
- #!/usr/bin/env ruby
2
- require 'bundler/setup'
3
- require 'lopata/runner'
4
-
5
- # use default command with arguments if given command is unknown.
6
- argv = ARGV.dup
7
- unless Lopata::Runner.all_commands.keys.map(&:to_s).include? argv.first
8
- argv.unshift 'test'
9
- end
10
-
11
- Lopata::Runner.start argv
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'lopata/runner'
4
+
5
+ # use default command with arguments if given command is unknown.
6
+ argv = ARGV.dup
7
+ unless Lopata::Runner.all_commands.keys.map(&:to_s).include? argv.first
8
+ argv.unshift 'test'
9
+ end
10
+
11
+ Lopata::Runner.start argv
@@ -1,136 +1,136 @@
1
- module Lopata
2
- # Helpers for ActiveRecord usage in tests.
3
- #
4
- # Make helpers available in scenarios by
5
- #
6
- # require 'lopata/active_record'
7
- #
8
- # @example
9
- #
10
- # # Configure db connection at config/environments/qa.yml like rails:
11
- # # db:
12
- # # adapter: postgresql
13
- # # host: your.database.host
14
- # # username: username
15
- # # password: password
16
- # # database: database
17
- # require 'active_record'
18
- # require 'lopata/active_record'
19
- #
20
- # class User < ActiveRecord::Base; end
21
- #
22
- # Lopata.define 'User creation' do
23
- # setup do
24
- # @user = User.create!(username: 'testuser')
25
- # end
26
- # # Remove user from database after scenario
27
- # cleanup :user
28
- #
29
- # it 'works' do
30
- # expect(@user).to_not be_nil
31
- # end
32
- # end
33
- #
34
- module ActiveRecord
35
- # To be included in Lopata::Scenario. The methods may be used in runtime.
36
- module Methods
37
- # Destroy ActiveRecord objects.
38
- #
39
- # Does nothing if 'keep' mode is enabled:
40
- #
41
- # Lopata.configure do |c|
42
- # c.keep = true
43
- # end
44
- #
45
- # @param objects [Array<ActiveRecord::Base, Array<ActiveRecord::Base>, nil>] to be destroyed
46
- # @see Lopata::Configuration#keep
47
- def cleanup(*objects)
48
- return if Lopata.configuration.keep
49
- objects.flatten.compact.each do |o|
50
- begin
51
- o.reload.destroy!
52
- rescue ::ActiveRecord::RecordNotFound
53
- # Already destroyed - skip
54
- rescue ::ActiveRecord::InvalidForeignKey
55
- # Possible async job created new relationships (e.g. history records). Try again once.
56
- o.reload.destroy!
57
- end
58
- end
59
- end
60
-
61
- # Reload ActiveRecord objects
62
- #
63
- # @example
64
- #
65
- # # use in steps
66
- # reload @a, @b
67
- # # instead of
68
- # @a.reload; @b.reload
69
- #
70
- # @param objects [Array<ActiveRecord::Base, Array<ActiveRecord::Base>, nil>] to be reloaded
71
- def reload(*objects)
72
- objects.flatten.compact.each(&:reload)
73
- end
74
-
75
- # Marks object to be destroyed at the end of scenario
76
- #
77
- # @param object [ActiveRecord::Base] the object to be destoryed at the end of scenario
78
- # @return the given object, so chains can be build
79
- def cleanup_later(object)
80
- return nil unless object
81
- @created_objects ||= []
82
- @created_objects << object
83
- object
84
- end
85
-
86
- # Find ActiveRecord object of given class by params.
87
- # Marks the returned object to be destroyed at the end of scenario.
88
- #
89
- # @example
90
- # action do
91
- # # UI actions creating the user
92
- # @user = find_created(User, username: 'testuser')
93
- # end
94
- # it 'created' do
95
- # expect(@user).to_not be_nil
96
- # end
97
- # # No cleanup needed
98
- # # cleanup :user
99
- #
100
- # @param cls [Class] active record model class
101
- # @param params [Hash] options for record finding
102
- # @return [ActiveRecord::Base, nil] the object or nil if not found
103
- # @see #cleanup_later called on the hood
104
- def find_created(cls, params)
105
- cleanup_later cls.where(params).take
106
- end
107
- end
108
-
109
- # To be included in Lopata::ScenarioBuilder. The methods may be used in build time.
110
- module DSL
111
- # Mark instance variables to call #destroy at teardown phase of scenario or context running.
112
- #
113
- # Does nothing if 'keep' mode is enabled.
114
- #
115
- # @param vars [Array<Symbol, String>] instance variable names to be destroyed on teardown phase.
116
- def cleanup(*vars, &block)
117
- unless vars.empty?
118
- teardown do
119
- cleanup vars.map { |v| instance_variable_get "@#{v}" }
120
- end
121
- end
122
- teardown &block if block_given?
123
- end
124
- end
125
- end
126
- end
127
-
128
- Lopata.configure do |c|
129
- c.after_scenario { cleanup @created_objects }
130
- end
131
-
132
- params = Lopata.environment['db']
133
- ActiveRecord::Base.establish_connection(params) if params
134
-
135
- Lopata::Scenario.include Lopata::ActiveRecord::Methods
1
+ module Lopata
2
+ # Helpers for ActiveRecord usage in tests.
3
+ #
4
+ # Make helpers available in scenarios by
5
+ #
6
+ # require 'lopata/active_record'
7
+ #
8
+ # @example
9
+ #
10
+ # # Configure db connection at config/environments/qa.yml like rails:
11
+ # # db:
12
+ # # adapter: postgresql
13
+ # # host: your.database.host
14
+ # # username: username
15
+ # # password: password
16
+ # # database: database
17
+ # require 'active_record'
18
+ # require 'lopata/active_record'
19
+ #
20
+ # class User < ActiveRecord::Base; end
21
+ #
22
+ # Lopata.define 'User creation' do
23
+ # setup do
24
+ # @user = User.create!(username: 'testuser')
25
+ # end
26
+ # # Remove user from database after scenario
27
+ # cleanup :user
28
+ #
29
+ # it 'works' do
30
+ # expect(@user).to_not be_nil
31
+ # end
32
+ # end
33
+ #
34
+ module ActiveRecord
35
+ # To be included in Lopata::Scenario. The methods may be used in runtime.
36
+ module Methods
37
+ # Destroy ActiveRecord objects.
38
+ #
39
+ # Does nothing if 'keep' mode is enabled:
40
+ #
41
+ # Lopata.configure do |c|
42
+ # c.keep = true
43
+ # end
44
+ #
45
+ # @param objects [Array<ActiveRecord::Base, Array<ActiveRecord::Base>, nil>] to be destroyed
46
+ # @see Lopata::Configuration#keep
47
+ def cleanup(*objects)
48
+ return if Lopata.configuration.keep
49
+ objects.flatten.compact.each do |o|
50
+ begin
51
+ o.reload.destroy!
52
+ rescue ::ActiveRecord::RecordNotFound
53
+ # Already destroyed - skip
54
+ rescue ::ActiveRecord::InvalidForeignKey
55
+ # Possible async job created new relationships (e.g. history records). Try again once.
56
+ o.reload.destroy!
57
+ end
58
+ end
59
+ end
60
+
61
+ # Reload ActiveRecord objects
62
+ #
63
+ # @example
64
+ #
65
+ # # use in steps
66
+ # reload @a, @b
67
+ # # instead of
68
+ # @a.reload; @b.reload
69
+ #
70
+ # @param objects [Array<ActiveRecord::Base, Array<ActiveRecord::Base>, nil>] to be reloaded
71
+ def reload(*objects)
72
+ objects.flatten.compact.each(&:reload)
73
+ end
74
+
75
+ # Marks object to be destroyed at the end of scenario
76
+ #
77
+ # @param object [ActiveRecord::Base] the object to be destoryed at the end of scenario
78
+ # @return the given object, so chains can be build
79
+ def cleanup_later(object)
80
+ return nil unless object
81
+ @created_objects ||= []
82
+ @created_objects << object
83
+ object
84
+ end
85
+
86
+ # Find ActiveRecord object of given class by params.
87
+ # Marks the returned object to be destroyed at the end of scenario.
88
+ #
89
+ # @example
90
+ # action do
91
+ # # UI actions creating the user
92
+ # @user = find_created(User, username: 'testuser')
93
+ # end
94
+ # it 'created' do
95
+ # expect(@user).to_not be_nil
96
+ # end
97
+ # # No cleanup needed
98
+ # # cleanup :user
99
+ #
100
+ # @param cls [Class] active record model class
101
+ # @param params [Hash] options for record finding
102
+ # @return [ActiveRecord::Base, nil] the object or nil if not found
103
+ # @see #cleanup_later called on the hood
104
+ def find_created(cls, params)
105
+ cleanup_later cls.where(params).take
106
+ end
107
+ end
108
+
109
+ # To be included in Lopata::ScenarioBuilder. The methods may be used in build time.
110
+ module DSL
111
+ # Mark instance variables to call #destroy at teardown phase of scenario or context running.
112
+ #
113
+ # Does nothing if 'keep' mode is enabled.
114
+ #
115
+ # @param vars [Array<Symbol, String>] instance variable names to be destroyed on teardown phase.
116
+ def cleanup(*vars, &block)
117
+ unless vars.empty?
118
+ teardown do
119
+ cleanup vars.map { |v| instance_variable_get "@#{v}" }
120
+ end
121
+ end
122
+ teardown &block if block_given?
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ Lopata.configure do |c|
129
+ c.after_scenario { cleanup @created_objects }
130
+ end
131
+
132
+ params = Lopata.environment['db']
133
+ ActiveRecord::Base.establish_connection(params) if params
134
+
135
+ Lopata::Scenario.include Lopata::ActiveRecord::Methods
136
136
  Lopata::ScenarioBuilder.include Lopata::ActiveRecord::DSL
@@ -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