brine-dsl 0.11.0 → 0.12.0

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: 906c5a5791f773d74511eb23f0dd53a1ee25f29d3e7b4318f8b1b2f4299c5696
4
- data.tar.gz: 06d1b4ffc9d6a745f06b2ebb7c6164b650d3c5fa6d6cd918dcb9c406a1b98656
3
+ metadata.gz: a06ae7bee936f1179d45feff647eba71a2bb10832bba886861e0da74b81b68d5
4
+ data.tar.gz: 35dcc3f58a97e4ff814e84bed8e40d091405eb4a05f5b321212f3d0ed16b2a67
5
5
  SHA512:
6
- metadata.gz: d94513fc23ac9e9d5d21e45641821c1e90e9b06245947d68007277e033efff64fc6bc2054750e0d451c8455c8088614a52621cd63e45f3b925ef20171f8be7c0
7
- data.tar.gz: 3395d12a8fd7c8ee1b3df7e86474807ec3c666e49a3d6c974f77dad51d5175b87ece0ecbc016cd823e1beb7feba8357ec2067a4a2167400405478e444cffab6a
6
+ metadata.gz: 5105f8cd19c33eaf6f31d4daf366cb5219e5000452c50754a9fe570cc388ea9b3d2a42b51ee704bb8da70534822c86faa253461a7892172faa1f0961f53119d7
7
+ data.tar.gz: 15a09e7bd10ae9bfc4692ae7d35bf31a0a0f51e15b599b4c2d67184fe7a6e7742537b4da41922a1951c642b7a01e097dbf6f4f60cc885faa717cc2946a624a6e
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.5.5
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brine-dsl (0.11.0)
5
- cucumber (~> 2.4)
4
+ brine-dsl (0.12.0)
5
+ cucumber (= 4.0.0.rc.1)
6
6
  faraday (~> 0.12)
7
7
  faraday_middleware (~> 0.12)
8
8
  jsonpath (~> 0.8)
@@ -13,24 +13,42 @@ PATH
13
13
  GEM
14
14
  remote: http://rubygems.org/
15
15
  specs:
16
+ backports (3.15.0)
16
17
  builder (3.2.3)
17
- cucumber (2.99.0)
18
+ c21e (1.1.9)
19
+ cucumber (4.0.0.rc.1)
18
20
  builder (>= 2.1.2)
19
- cucumber-core (~> 1.5.0)
20
- cucumber-wire (~> 0.0.1)
21
- diff-lcs (>= 1.1.3)
22
- gherkin (~> 4.0)
21
+ cucumber-core (~> 4.0)
22
+ cucumber-expressions (~> 6.0, >= 6.0.1)
23
+ cucumber-formatter-dots (~> 1.0)
24
+ cucumber-wire (~> 1.0)
25
+ diff-lcs (~> 1.3)
26
+ gherkin (~> 6.0)
23
27
  multi_json (>= 1.7.5, < 2.0)
24
28
  multi_test (>= 0.1.2)
25
- cucumber-core (1.5.0)
26
- gherkin (~> 4.0)
27
- cucumber-wire (0.0.1)
29
+ cucumber-core (4.0.0)
30
+ backports (>= 3.8.0)
31
+ cucumber-tag_expressions (~> 1.1.0)
32
+ gherkin (~> 6.0)
33
+ cucumber-expressions (6.6.2)
34
+ cucumber-formatter-dots (1.1.0)
35
+ cucumber-messages
36
+ os
37
+ cucumber-messages (2.1.2)
38
+ google-protobuf (>= 3.2, <= 3.7)
39
+ cucumber-tag_expressions (1.1.1)
40
+ cucumber-wire (1.0.0)
41
+ cucumber-core (~> 4.0)
42
+ cucumber-expressions (~> 6.0)
28
43
  diff-lcs (1.3)
29
- faraday (0.15.4)
44
+ faraday (0.16.2)
30
45
  multipart-post (>= 1.2, < 3)
31
46
  faraday_middleware (0.13.1)
32
47
  faraday (>= 0.7.4, < 1.0)
33
- gherkin (4.1.3)
48
+ gherkin (6.0.17)
49
+ c21e (~> 1.1.9)
50
+ cucumber-messages (~> 2.1.2)
51
+ google-protobuf (3.7.0)
34
52
  jsonpath (0.9.9)
35
53
  multi_json
36
54
  to_regexp (~> 0.2.1)
@@ -40,27 +58,28 @@ GEM
40
58
  multi_xml (0.6.0)
41
59
  multipart-post (2.1.1)
42
60
  mustache (1.1.0)
43
- oauth2 (1.4.1)
44
- faraday (>= 0.8, < 0.16.0)
61
+ oauth2 (1.4.2)
62
+ faraday (>= 0.8, < 2.0)
45
63
  jwt (>= 1.0, < 3.0)
46
64
  multi_json (~> 1.3)
47
65
  multi_xml (~> 0.5)
48
66
  rack (>= 1.2, < 3)
67
+ os (1.0.1)
49
68
  rack (2.0.7)
50
- rake (12.3.2)
69
+ rake (12.3.3)
51
70
  rspec (3.8.0)
52
71
  rspec-core (~> 3.8.0)
53
72
  rspec-expectations (~> 3.8.0)
54
73
  rspec-mocks (~> 3.8.0)
55
- rspec-core (3.8.1)
74
+ rspec-core (3.8.2)
56
75
  rspec-support (~> 3.8.0)
57
- rspec-expectations (3.8.4)
76
+ rspec-expectations (3.8.5)
58
77
  diff-lcs (>= 1.2.0, < 2.0)
59
78
  rspec-support (~> 3.8.0)
60
- rspec-mocks (3.8.1)
79
+ rspec-mocks (3.8.2)
61
80
  diff-lcs (>= 1.2.0, < 2.0)
62
81
  rspec-support (~> 3.8.0)
63
- rspec-support (3.8.2)
82
+ rspec-support (3.8.3)
64
83
  to_regexp (0.2.1)
65
84
 
66
85
  PLATFORMS
@@ -13,15 +13,15 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.required_ruby_version = '>= 2.3.0'
15
15
 
16
- s.add_runtime_dependency 'cucumber', '~> 2.4'
17
- s.add_runtime_dependency 'mustache', '~> 1.0'
18
- s.add_runtime_dependency 'oauth2', '~> 1.4'
19
- s.add_runtime_dependency 'rspec', '~> 3.7'
20
- s.add_runtime_dependency 'jsonpath', '~> 0.8'
21
- s.add_runtime_dependency 'faraday', '~> 0.12'
22
- s.add_runtime_dependency 'faraday_middleware', '~> 0.12'
16
+ s.add_runtime_dependency 'cucumber', '4.0.0.rc.1'
17
+ s.add_runtime_dependency 'mustache', '~> 1.0'
18
+ s.add_runtime_dependency 'oauth2', '~> 1.4'
19
+ s.add_runtime_dependency 'rspec', '~> 3.7'
20
+ s.add_runtime_dependency 'jsonpath', '~> 0.8'
21
+ s.add_runtime_dependency 'faraday', '~> 0.12'
22
+ s.add_runtime_dependency 'faraday_middleware', '~> 0.12'
23
23
 
24
- s.add_development_dependency 'rake', '~> 12.3'
24
+ s.add_development_dependency 'rake', '~> 12.3'
25
25
 
26
26
  s.files = `git ls-files`.split("\n")
27
27
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,37 +1,24 @@
1
1
  ##
2
2
  # @file brine.rb
3
- # Loader file for the rest of brine.
4
- #
5
- # The primary goal of this file is to load all resources needed to use brine.
6
- # A secondary goal which should inform how that is done is that loading this
7
- # file by itself should provide new objects but not otherwise impact existing
8
- # state such as by modifying the World or defining any Steps, Transforms, etc.
9
- # Those types of changes should be done by @ref #brine_mix.
3
+ # Support loading Brine into the World.
10
4
  ##
11
5
 
12
- require 'brine/cleaning_up'
13
- require 'brine/mustache_expanding'
14
- require 'brine/performing'
15
- require 'brine/requesting'
16
- require 'brine/selecting'
17
- require 'brine/type_checking'
18
-
19
6
  ##
20
- # Load the files with side effects.
7
+ # Load all Brine files into the World.
21
8
  #
22
9
  # Expected to be called as `World(brine_mix)`
23
- # @return [module] The `Brine` module.
10
+ #
11
+ # @return [module] Return the `Brine` module.
24
12
  ##
25
13
  def brine_mix
26
- require 'brine/step_definitions/assignment'
27
- require 'brine/step_definitions/request_construction'
28
- require 'brine/step_definitions/assertions'
29
- require 'brine/step_definitions/cleanup'
30
- require 'brine/step_definitions/perform'
31
- require 'brine/step_definitions/selection'
32
-
33
- require 'brine/transforming'
14
+ require 'brine/assertions'
15
+ require 'brine/cleaning_up'
34
16
  require 'brine/hooks'
35
-
17
+ require 'brine/mustache_expanding'
18
+ require 'brine/performing'
19
+ require 'brine/requesting'
20
+ require 'brine/selecting'
21
+ require 'brine/transforming'
22
+ require 'brine/type_checking'
36
23
  Brine
37
24
  end
@@ -0,0 +1,123 @@
1
+ ##
2
+ # @file assertions.rb
3
+ # Define assertion steps to be used with a Selector
4
+ ##
5
+
6
+ require 'brine/transforming'
7
+
8
+ ##
9
+ # Assert that the selected value is equal to the parameter.
10
+ #
11
+ # @param value [Object] Specify the value which the selection should equal.
12
+ ##
13
+ Then('it is equal to {grave_param}') do |value|
14
+ perform { selector.assert_that(value, binding) {|v| eq v} }
15
+ end
16
+
17
+ ##
18
+ # Assert that the selected value is equal to the docstring.
19
+ #
20
+ # @param multi [String] Specify the value which the selection should equal.
21
+ ##
22
+ Then('it is equal to:') do |value|
23
+ perform { selector.assert_that(transformed_parameter(value), binding) {|v| eq v} }
24
+ end
25
+
26
+ ##
27
+ # Assert that the selected value matches the parameter.
28
+ #
29
+ # @param value [Object] Specify the pattern which the selection should match.
30
+ ##
31
+ Then('it is matching {grave_param}') do |value|
32
+ perform { selector.assert_that(value, binding) {|v| match v} }
33
+ end
34
+
35
+ ##
36
+ # Assert that the selected value matches the docstring.
37
+ #
38
+ # @param value [String] Specify the pattern which the selection should match.
39
+ ##
40
+ Then('it is matching:') do |value|
41
+ perform { selector.assert_that(transformed_parameter(value), binding) {|v| match v} }
42
+ end
43
+
44
+ ##
45
+ # Assert that the selected value is greater than the parameter.
46
+ #
47
+ # @param value [Object] Specify the value which the selection should be greater than.
48
+ ##
49
+ Then('it is greater than {grave_param}') do |value|
50
+ perform { selector.assert_that(value, binding) {|v| be > v} }
51
+ end
52
+
53
+ ##
54
+ # Assert that the selected value is greater than or equal to the parameter.
55
+ #
56
+ # @param value [Object] Specify the value which the selection should be greater than or equal to.
57
+ ##
58
+ Then('it is greater than or equal to {grave_param}') do |value|
59
+ perform { selector.assert_that(value, binding) {|v| be >= v} }
60
+ end
61
+
62
+ ##
63
+ # Assert that the selected value is less than the parameter.
64
+ #
65
+ # @param value [Object] Specify the value which the selection should be less than.
66
+ ##
67
+ Then('it is less than {grave_param}') do |value|
68
+ perform { selector.assert_that(value, binding) {|v| be < v} }
69
+ end
70
+
71
+ ##
72
+ # Assert that the selected value is less than or equal to the parameter.
73
+ #
74
+ # @param value [Object] Specify the value which the selection should be less than or equal to.
75
+ ##
76
+ Then('it is less than or equal to {grave_param}') do |value|
77
+ perform { selector.assert_that(value, binding) {|v| be <= v} }
78
+ end
79
+
80
+ ##
81
+ # Assert that the selected value is empty.
82
+ #
83
+ # This will be satisfied by nil or any object which returns a truthy #empty?
84
+ ##
85
+ Then('it is empty') do
86
+ perform { selector.assert_that(nil, binding) do
87
+ satisfy{|i| i.nil? || (i.respond_to?(:empty?) && i.empty?) }
88
+ end }
89
+ end
90
+
91
+ ##
92
+ # Assert that the selected value includes the parameter.
93
+ #
94
+ # @param value [Object] Specify content which should be within the selection.
95
+ ##
96
+ Then('it is including {grave_param}') do |value|
97
+ perform { selector.assert_that(value, binding) {|v| include v } }
98
+ end
99
+
100
+ ##
101
+ # Assert that the selected value includes the docstring.
102
+ #
103
+ # @param value [String] Specify content which should be within the selection.
104
+ ##
105
+ Then('it is including:') do |value|
106
+ perform { selector.assert_that(transformed_parameter(value), binding) {|v| include v } }
107
+ end
108
+
109
+ ##
110
+ # Asserted that the selected value has a length equal to the parameter.
111
+ #
112
+ # TODO: It may be better to support selection of the length attribute, maybe
113
+ # chain to another dynamic step such as `is of lenth that is ...`
114
+ #
115
+ # @param length [Object] Specify the length which the selection should have.
116
+ ##
117
+ Then('it is of length {grave_param}') do |length|
118
+ perform do
119
+ selector.assert_that(length, binding) do |l|
120
+ satisfy{|i| i.respond_to?(:length) && i.length == l}
121
+ end
122
+ end
123
+ end
@@ -2,8 +2,7 @@
2
2
  # @file cleaning_up.rb
3
3
  # Clean up resources created during test run.
4
4
  #
5
- # Will issue DELETE call for all tracked URLs which will normally be triggered
6
- # in a hook.
5
+ # Issue DELETE calls for all tracked URLs: will normally be triggered in a hook.
7
6
  #
8
7
  # The present approach for this is to explicitly track created resources to
9
8
  # which DELETE calls will be sent. Cleaning up of resources will be given some
@@ -13,9 +12,9 @@
13
12
  module Brine
14
13
 
15
14
  ##
16
- # A module providing resource cleanup.
15
+ # Provide resource cleanup.
17
16
  #
18
- # Exposes methods to keep a stack of DeleteCommands corresponding to each
17
+ # Expose methods to keep a stack of DeleteCommands corresponding to each
19
18
  # created resource which are then popped and invoked to perform the cleanup.
20
19
  #
21
20
  # LIFO behavior is adopted as it is more likely to preserve integrity,
@@ -24,7 +23,7 @@ module Brine
24
23
  module CleaningUp
25
24
 
26
25
  ##
27
- # A command object for the delete which will be executed as part of cleaning up.
26
+ # Capture the delete command which will be executed as part of cleaning up.
28
27
  #
29
28
  # The command will be retried a specified number of times if an unsuccessful status code is received.
30
29
  ##
@@ -33,10 +32,11 @@ module Brine
33
32
  ##
34
33
  # Construct a command with the required paramters to perform the delete.
35
34
  #
36
- # @param [Faraday::Connection, #delete] client The Faraday client which will send the delete message.
37
- # @param [String] path The path of the resource to be deleted.
38
- # @param [Array<Integer>] oks The response status codes which will be considered successful.
39
- # @param [Integer] attempts The number of times this command should be tried.
35
+ # @param client [Faraday::Connection, #delete] Provide the Faraday client which will send the delete message.
36
+ # @param path [String] Specify the path of the resource to be deleted.
37
+ # @param oks [Array<Integer>] Indicate response status codes which should be considered successful)
38
+ # (defaults to [200,204]).
39
+ # @param attempts [Integer] Specify the number of times this command should be tried (defaults to 3).
40
40
  ##
41
41
  def initialize(client, path, oks: [200,204], attempts: 3)
42
42
  @client = client
@@ -48,14 +48,14 @@ module Brine
48
48
  ##
49
49
  # Issue the delete based on the parameters provided during construction.
50
50
  #
51
- # @return [Boolean] true if a successful response is obtained, otherwise false.
51
+ # @return [Boolean] Return true if a successful response is obtained, otherwise false.
52
52
  ##
53
53
  def cleanup
54
54
  for _ in 1..@attempts
55
55
  begin
56
56
  resp=@client.delete(@path)
57
57
  return true if @oks.include?(resp.status)
58
- rescue ex
58
+ rescue Exception => ex
59
59
  STDERR.puts "WARNING: #{ex}"
60
60
  end
61
61
  end
@@ -73,7 +73,7 @@ module Brine
73
73
  # used to issue the creation requests and could therefore be passed to this
74
74
  # method prior to use.
75
75
  #
76
- # @param [Faraday::Connection, #delete] client The client to use to DELETE subsequently tracked resources.
76
+ # @param client [Faraday::Connection, #delete] Provide the client to DELETE subsequently tracked resources.
77
77
  ##
78
78
  def set_cleaning_client(client)
79
79
  @client = client
@@ -82,7 +82,7 @@ module Brine
82
82
  ##
83
83
  # Record resource to be later cleaned (pushes a DeleteCommand).
84
84
  #
85
- # @param [String] path The path for the created resource; will be issued a DELETE.
85
+ # @param path [String] Specify the path for the created resource: will be issued a DELETE.
86
86
  ##
87
87
  def track_created_resource(path)
88
88
  cleanup_commands << DeleteCommand.new(@client, path)
@@ -91,7 +91,7 @@ module Brine
91
91
  ##
92
92
  # Clean recorded resources (normally after a test run).
93
93
  #
94
- # @return [Boolean] true if all commands succeeded successfully, otherwise false.
94
+ # @return [Boolean] Return true if all commands succeeded successfully, otherwise false.
95
95
  ##
96
96
  def cleanup_created_resources
97
97
  # Avoid the use of any short circuiting folds.
@@ -101,11 +101,9 @@ module Brine
101
101
  private
102
102
 
103
103
  ##
104
- # The array which serves as the stack of DeleteCommands.
104
+ # Return the array which serves as the stack of DeleteCommands.
105
105
  #
106
- # Provides the property mixed in by the module.
107
- #
108
- # @return [Array<DeleteCommand>]
106
+ # @return [Array<DeleteCommand>] Return the existing or new list of commands to execute for cleanup.
109
107
  ##
110
108
  def cleanup_commands
111
109
  @cleanup_commands ||= []
@@ -118,3 +116,15 @@ module Brine
118
116
  ##
119
117
  include CleaningUp
120
118
  end
119
+
120
+ require 'brine/transforming'
121
+
122
+ ##
123
+ # Record a resource path which should be cleaned up.
124
+ #
125
+ # @param path [Object] Specify the path which should be DELETED.
126
+ # This should be a String or a Template.
127
+ ##
128
+ When('a resource is created at {grave_param}') do |path|
129
+ perform { track_created_resource(path) }
130
+ end
@@ -1,18 +1,18 @@
1
1
  ##
2
2
  # @file client_building.rb
3
- # Construction of a Faraday connection.
3
+ # Construct a Faraday connection.
4
4
  ##
5
5
 
6
6
  module Brine
7
7
 
8
8
  ##
9
- # Supports construction of a Faraday connection with some common middleware.
9
+ # Allow construction of a Faraday connection with some common middleware.
10
10
  ##
11
11
  module ClientBuilding
12
12
  require 'oauth2'
13
13
 
14
14
  ##
15
- # Parameter object used to configure OAuth2 middleware
15
+ # Define OAuth2 middleware configuration.
16
16
  #
17
17
  # This is essentially a thin wrapper around `https://github.com/oauth-xx/oauth2`
18
18
  # to provide a mini-DSL and to facilitate the middleware configuration.
@@ -20,12 +20,12 @@ module Brine
20
20
  class OAuth2Params
21
21
 
22
22
  ##
23
- # A token which has been retrieved from the authorization server.
23
+ # Store the token which has been retrieved from the authorization server.
24
24
  ##
25
25
  attr_accessor :token
26
26
 
27
27
  ##
28
- # The type of OAuth2 token which will be retrieved.
28
+ # Specify the type of OAuth2 token which will be retrieved.
29
29
  #
30
30
  # Currently only `bearer` is supported.
31
31
  ##
@@ -44,14 +44,14 @@ module Brine
44
44
  # The parameters are forwarded to OAuth2::Client.new which is used to
45
45
  # retrieve the token.
46
46
  #
47
- # @param [String] id The login id to send to request authorization.
48
- # @param [String] secret The secret to send to request authorization.
49
- # @param [Hash] opts Options with which to create a client,
50
- # see `https://github.com/oauth-xx/oauth2/blob/master/lib/oauth2/client.rb` for full details,
51
- # common options will be duplicated here.
52
- # @option opts [String] :site The OAuth2 authorization server from which to request a token.
53
- # @option opts [String] :token_url The absolute or relative path to the Token endpoint on the authorization server.
54
- # @option opts [Hash] :ssl SSL options to pass through to the transport client,
47
+ # @param id [String] Provide the login id credential with which to request authorization.
48
+ # @param secret [String] Provide the secret credential with which to request authorization.
49
+ # @param opts [Hash] Define options with which to create a client,
50
+ # see `https://github.com/oauth-xx/oauth2/blob/master/lib/oauth2/client.rb` for full details,
51
+ # common options will be duplicated here.
52
+ # @option opts [String] :site Specify the OAuth2 authorization server from which to request a token.
53
+ # @option opts [String] :token_url Specify the absolute or relative path to the Token endpoint on the authorization server.
54
+ # @option opts [Hash] :ssl Provide SSL options to pass through to the transport client,
55
55
  # `{verify: false}` may be useful for self-signed certificates.
56
56
  ##
57
57
  def fetch_from(id, secret, opts)
@@ -61,10 +61,10 @@ module Brine
61
61
  end
62
62
 
63
63
  ##
64
- # Acquire an OAuth2 token within provided configuration block.
64
+ # Acquire an OAuth2 token with the provided configuration block.
65
65
  #
66
- # @param [Block] Logic to execute with an OAuth2Params receiver;
67
- # this will normally involve an OAuth2Params#fetch_from call.
66
+ # @param [Block] Provide logic to execute with an OAuth2Params receiver;
67
+ # this will normally involve an OAuth2Params#fetch_from call.
68
68
  ##
69
69
  def use_oauth2_token(&block)
70
70
  @oauth2 = OAuth2Params.new
@@ -72,7 +72,7 @@ module Brine
72
72
  end
73
73
 
74
74
  ##
75
- # The handlers/middleware that will be wired while constructing a client.
75
+ # Expose the handlers/middleware that will be wired while constructing a client.
76
76
  #
77
77
  # This is represented as list of functions so that it can be more easily customized for
78
78
  # unexpected use cases.
@@ -98,13 +98,13 @@ module Brine
98
98
  end
99
99
 
100
100
  ##
101
- # Construct a new client to send requests to `host`.
101
+ # Return a client which will send requests to `host`.
102
102
  #
103
- # Will configure the client using `#connection_handlers`.
103
+ # This will configure the client using `#connection_handlers`.
104
104
  #
105
- # @param [String] host The hostname to which this client will send requests.
106
- # @param [String] logging Indicate the desired logging level for this client.
107
- # @return [Faraday::Connection] The configured client connection.
105
+ # @param host [String] Specify the hostname to which this client will send requests.
106
+ # @param logging [String] Indicate the desired logging level for this client.
107
+ # @return [Faraday::Connection] Return the configured client connection.
108
108
  ##
109
109
  def client_for_host(host, logging: ENV['BRINE_LOG_HTTP'])
110
110
  @logging = logging