lopata 0.1.9 → 0.1.14

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: ac7869fc182b12d3c519ad14d8adcdac5e64bee1e20b75079367b54b2d7de799
4
- data.tar.gz: 3073f91baef1a324cd299a442ce8cc69da5de995aa64d1850304e1e286827aea
3
+ metadata.gz: 39dff231d5f7bf1b95eced95c1a8ddf0c363ea6c99b391ca62b896550aca4823
4
+ data.tar.gz: cc79dbade31aa4c975cc5cd935bb106b0b16d50ba5cd622a7e92ffd73692547c
5
5
  SHA512:
6
- metadata.gz: 35ad7f2284f3f85f2ac7d6ba718857f3755cfb6db35efb8609899877707ed6a4b3e9dbd8529309a5589e3d74c747bc4672c2f16845a3ff5a4d0ebf080c99f444
7
- data.tar.gz: 32fb8a447ac3c010418ca4812c56da2b8d4bd105f49e6ea4e00a2f84f11c27ae591eb4b0bebff2e7349436314bbcd560ff973036b1763b8af64ac8df0568e173
6
+ metadata.gz: 9dd29df0812efc5c5298f8579b0385858401fd4c5ae2c0627238401138abbdc2746f9e1035251255236788e64e33a47061ddcfc4bf25425ff5af6054c80bcccd
7
+ data.tar.gz: 7c96430a0a8b573dade74592234781797e508073e6ac3ea3d7e07bd42b001abc29946998fcaed4eb4d924d47ff27b26c017c208338ad4523bf403553d8628273
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,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
- # 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
+ # 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,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