lopata 0.1.11 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -25
- data/exe/lopata +11 -11
- data/lib/lopata.rb +100 -74
- data/lib/lopata/active_record.rb +135 -135
- data/lib/lopata/condition.rb +30 -30
- data/lib/lopata/configuration.rb +125 -125
- data/lib/lopata/environment.rb +35 -35
- data/lib/lopata/factory_bot.rb +72 -72
- data/lib/lopata/generators/app.rb +42 -42
- data/lib/lopata/generators/templates/Gemfile +7 -7
- data/lib/lopata/generators/templates/Lopatafile +20 -20
- data/lib/lopata/generators/templates/config/environments/qa.yml +7 -7
- data/lib/lopata/generators/templates/config/initializers/capybara.rb +1 -1
- data/lib/lopata/id.rb +22 -22
- data/lib/lopata/loader.rb +31 -27
- data/lib/lopata/observers.rb +4 -4
- data/lib/lopata/observers/backtrace_formatter.rb +103 -103
- data/lib/lopata/observers/base_observer.rb +33 -33
- data/lib/lopata/observers/console_output_observer.rb +100 -100
- data/lib/lopata/observers/web_logger.rb +130 -130
- data/lib/lopata/role.rb +109 -90
- data/lib/lopata/runner.rb +67 -67
- data/lib/lopata/scenario.rb +136 -136
- data/lib/lopata/scenario_builder.rb +497 -495
- data/lib/lopata/shared_step.rb +38 -38
- data/lib/lopata/step.rb +191 -191
- data/lib/lopata/version.rb +6 -6
- data/lib/lopata/world.rb +24 -24
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bcc4430dec94673cafa7b78a1ce7a1a9290539fdfc6c74d452db6bdbb36562e
|
4
|
+
data.tar.gz: f2cab1b0033f5d8a44d4bd9beba5b2b6c354b8ec05bd9ea91cf7ee329b1c0626
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf4791606e84c616316e54fd191687e9b21ce86d47b627228a66b5b936886a28ffde9b4d5a50a52de72296ed7b957fb3c8eaa54ca5309d637ced84b080e4aa89
|
7
|
+
data.tar.gz: f4634151931554ed5583d04dc807929d56e85072bb0203be6548b94bfda6f7dfaa3eb2387505f7027eed8692c0c16bdaa6892f420ae826654713d268440108ea
|
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
|
data/lib/lopata.rb
CHANGED
@@ -1,74 +1,100 @@
|
|
1
|
-
require 'lopata/id'
|
2
|
-
require 'lopata/configuration'
|
3
|
-
require 'lopata/environment'
|
4
|
-
require 'lopata/scenario_builder'
|
5
|
-
require 'lopata/scenario'
|
6
|
-
require 'lopata/step'
|
7
|
-
require 'lopata/shared_step'
|
8
|
-
|
9
|
-
# Namespace for all Lopata code.
|
10
|
-
module Lopata
|
11
|
-
# Define the scenario.
|
12
|
-
# @see Lopata::ScenarioBuilder.define
|
13
|
-
def self.define(*args, &block)
|
14
|
-
Lopata::ScenarioBuilder.define(*args, &block)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Skip scenario definition. Option to temporary ignore scenario
|
18
|
-
def self.xdefine(*args, &block)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Register the shared step
|
22
|
-
#
|
23
|
-
# @example
|
24
|
-
# Lopata.shared_step 'test user' do
|
25
|
-
# setup { @user = create(:user) }
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# Shared step may be used in scenarios by name:
|
29
|
-
# @example
|
30
|
-
# Lopata.define 'user' do
|
31
|
-
# setup 'test user'
|
32
|
-
#
|
33
|
-
# it 'exists' do
|
34
|
-
# expect(@user).to_not be_nil
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
# @param name [String] shared step unique name
|
38
|
-
# @param block [Block] shared step action sequence definition
|
39
|
-
def self.shared_step(name, &block)
|
40
|
-
Lopata::SharedStep.register(name, &block)
|
41
|
-
end
|
42
|
-
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
# @
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
# @
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
1
|
+
require 'lopata/id'
|
2
|
+
require 'lopata/configuration'
|
3
|
+
require 'lopata/environment'
|
4
|
+
require 'lopata/scenario_builder'
|
5
|
+
require 'lopata/scenario'
|
6
|
+
require 'lopata/step'
|
7
|
+
require 'lopata/shared_step'
|
8
|
+
|
9
|
+
# Namespace for all Lopata code.
|
10
|
+
module Lopata
|
11
|
+
# Define the scenario.
|
12
|
+
# @see Lopata::ScenarioBuilder.define
|
13
|
+
def self.define(*args, &block)
|
14
|
+
Lopata::ScenarioBuilder.define(*args, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Skip scenario definition. Option to temporary ignore scenario
|
18
|
+
def self.xdefine(*args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Register the shared step
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# Lopata.shared_step 'test user' do
|
25
|
+
# setup { @user = create(:user) }
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# Shared step may be used in scenarios by name:
|
29
|
+
# @example
|
30
|
+
# Lopata.define 'user' do
|
31
|
+
# setup 'test user'
|
32
|
+
#
|
33
|
+
# it 'exists' do
|
34
|
+
# expect(@user).to_not be_nil
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
# @param name [String] shared step unique name
|
38
|
+
# @param block [Block] shared step action sequence definition
|
39
|
+
def self.shared_step(name, &block)
|
40
|
+
Lopata::SharedStep.register(name, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Register the shared step for setup.
|
44
|
+
#
|
45
|
+
# shared_setup is a shortcat for shared_step 'name' { setup { .. } }. The block will be arrounded into the setup call.
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# Lopata.shared_setup 'test user' do
|
49
|
+
# @user = create(:user)
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# Shared step may be used in scenarios by name:
|
53
|
+
# @example
|
54
|
+
# Lopata.define 'user' do
|
55
|
+
# setup 'test user'
|
56
|
+
#
|
57
|
+
# it 'exists' do
|
58
|
+
# expect(@user).to_not be_nil
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
# @param name [String] shared step unique name
|
62
|
+
# @param block [Block] shared setup definition
|
63
|
+
def self.shared_setup(name, &block)
|
64
|
+
Lopata::SharedStep.register(name) do
|
65
|
+
setup(&block)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Yields the global configuration to a block.
|
70
|
+
# @yield [Lopata::Configuration] global configuration
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# Lopata.configure do |config|
|
74
|
+
# config.before_scenario 'setup test user'
|
75
|
+
# end
|
76
|
+
# @see Lopata::Configuration
|
77
|
+
def self.configure(&block)
|
78
|
+
yield Lopata.configuration
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns global configuration object.
|
82
|
+
# @return [Lopata::Configuration]
|
83
|
+
# @see Lopata.configure
|
84
|
+
def self.configuration
|
85
|
+
@configuration ||= Lopata::Configuration.new
|
86
|
+
end
|
87
|
+
|
88
|
+
# @private
|
89
|
+
# Internal container for global non-configuration data.
|
90
|
+
def self.world
|
91
|
+
@world ||= Lopata::World.new
|
92
|
+
end
|
93
|
+
|
94
|
+
# Return global environment object
|
95
|
+
# @return [Lopata::Environment]
|
96
|
+
# @see Lopata::Environment
|
97
|
+
def self.environment
|
98
|
+
Lopata.configuration.environment
|
99
|
+
end
|
100
|
+
end
|
data/lib/lopata/active_record.rb
CHANGED
@@ -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
|