lopata 0.1.12 → 0.1.16

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: 65f89b815ebe8514f78c803eab2bd2ece867e9fcdc9c28c178a721d717fd0341
4
- data.tar.gz: c418371982133703b0b97921fd870937052854e6975b4bb47f664105c56ed6b6
3
+ metadata.gz: 774b79e80dea037bec71641e42289e46c8b756e7928fb2d928e448ccf9de7429
4
+ data.tar.gz: 262c23ee9ab55b1d3258bd41124ccce45bdb968b5afeeb67b778a30c293adc80
5
5
  SHA512:
6
- metadata.gz: d54572c90bfdaea0aa91747541016d0d0b1ac1710a9d9a54c8278861643a07f5a8ea7157206a85cbaf3f3986c0dbabd14bfa741a5ce7eb7deb6bd2917d2d6b89
7
- data.tar.gz: 3d82e45bd0fd6c2901c65a4a07437a27df8b8367e1682a67b191f4829bb6bf2a11b583f319804e560e08774f806c675d82547bdb87fec623a1d6fb143d9d2b72
6
+ metadata.gz: 6415bf6ab545f56a68cd8b6cf84c7f1e4a8322fc8615afd782b86590cb458bc64c493ac783ab952fc76ab085e0c4080cf85750bc6e4da120685775f4a6b7970a
7
+ data.tar.gz: d75b4a44b1ca80254b6ffca2822a166b263131facc4cef869fb0df4c437987ad421a716933eb356dce37bf742066613e384ce63478b9ab1c11be1660834519d9
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,123 @@
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
- # Yields the global configuration to a block.
44
- # @yield [Lopata::Configuration] global configuration
45
- #
46
- # @example
47
- # Lopata.configure do |config|
48
- # config.before_scenario 'setup test user'
49
- # end
50
- # @see Lopata::Configuration
51
- def self.configure(&block)
52
- yield Lopata.configuration
53
- end
54
-
55
- # Returns global configuration object.
56
- # @return [Lopata::Configuration]
57
- # @see Lopata.configure
58
- def self.configuration
59
- @configuration ||= Lopata::Configuration.new
60
- end
61
-
62
- # @private
63
- # Internal container for global non-configuration data.
64
- def self.world
65
- @world ||= Lopata::World.new
66
- end
67
-
68
- # Return global environment object
69
- # @return [Lopata::Environment]
70
- # @see Lopata::Environment
71
- def self.environment
72
- Lopata.configuration.environment
73
- end
74
- end
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
+ # Register the shared step for context.
70
+ #
71
+ # shared_context is a shortcat for shared_step('name') { context('name') { .. } }. The block will be arrounded into the context call.
72
+ #
73
+ # @example
74
+ # Lopata.shared_context 'calculation' do
75
+ # it('correct') { expect(1 + 1).to eq 2 }
76
+ # it('incorrect') { expect(1 + 2).to eq 4 }
77
+ # end
78
+ #
79
+ # Shared context may be used in scenarios by name:
80
+ # @example
81
+ # Lopata.define 'verify calcuation in context' do
82
+ # verify 'calculation'
83
+ # end
84
+ # @param name [String] shared step unique name, will be used as a context's name
85
+ # @param block [Block] shared context definition
86
+ def self.shared_context(name, &block)
87
+ Lopata::SharedStep.register(name) do
88
+ context(name, &block)
89
+ end
90
+ end
91
+
92
+ # Yields the global configuration to a block.
93
+ # @yield [Lopata::Configuration] global configuration
94
+ #
95
+ # @example
96
+ # Lopata.configure do |config|
97
+ # config.before_scenario 'setup test user'
98
+ # end
99
+ # @see Lopata::Configuration
100
+ def self.configure(&block)
101
+ yield Lopata.configuration
102
+ end
103
+
104
+ # Returns global configuration object.
105
+ # @return [Lopata::Configuration]
106
+ # @see Lopata.configure
107
+ def self.configuration
108
+ @configuration ||= Lopata::Configuration.new
109
+ end
110
+
111
+ # @private
112
+ # Internal container for global non-configuration data.
113
+ def self.world
114
+ @world ||= Lopata::World.new
115
+ end
116
+
117
+ # Return global environment object
118
+ # @return [Lopata::Environment]
119
+ # @see Lopata::Environment
120
+ def self.environment
121
+ Lopata.configuration.environment
122
+ end
123
+ end
@@ -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