cucumber-blendle-steps 0.4.0 → 0.5.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
  SHA1:
3
- metadata.gz: 06b97b7cbad119afd760ba26ad67f62439c70ed8
4
- data.tar.gz: a5b20e8b46e36f233c013c0ca016852e8dfde6d3
3
+ metadata.gz: 946f7c5d7486fc1e9fd8ff619fbe0c8ca48dbeda
4
+ data.tar.gz: c2483cf653920913aa8583d24920937adf342808
5
5
  SHA512:
6
- metadata.gz: 96e16bc8fcfb613715645effd1cd354d95de359648a289248cad716bc36d3c1add74569d5c26a34340cef96c4270ca05b6828679e50b8c6a5c2d4f933daeaa41
7
- data.tar.gz: 19dfd2789536939317ed21873efa9ffcf631b123e317d051ae9ac5a9c50e18f1447ef7b6425953de62e372139567eb421f9bad41e18d163204ef97760135fa76
6
+ metadata.gz: 8db1be035b1356c48a2ee70732f8d9b014bc6e615d74b9407abad7a7ec20d0421d2b124e8468e13b878999d3847fdb98fa44179fe5f81de09e6ba93838f5606a
7
+ data.tar.gz: f1e227098a3fc04dc9d272567e833d8af88e748175ae70feddaeeaa713f976e929f8f32cbd612c93273aa8ab1c57c875d79edbe721cd31ee2d2d5674dadea901
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [v0.4.0](https://github.com/blendle/cucumber-blendle-steps/tree/v0.4.0) (2016-01-26)
4
+ [Full Changelog](https://github.com/blendle/cucumber-blendle-steps/compare/v0.3.2...v0.4.0)
5
+
3
6
  ## [v0.3.2](https://github.com/blendle/cucumber-blendle-steps/tree/v0.3.2) (2015-12-12)
4
7
  [Full Changelog](https://github.com/blendle/cucumber-blendle-steps/compare/v0.3.1...v0.3.2)
5
8
 
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = %w(lib)
18
18
 
19
19
  spec.add_dependency 'activesupport'
20
+ spec.add_dependency 'chronic'
20
21
  spec.add_dependency 'cucumber'
21
22
  spec.add_dependency 'halidator'
22
23
  spec.add_dependency 'hyperresource'
@@ -26,6 +27,7 @@ Gem::Specification.new do |spec|
26
27
  spec.add_dependency 'rack'
27
28
  spec.add_dependency 'rspec-expectations'
28
29
  spec.add_dependency 'sequel'
30
+ spec.add_dependency 'timecop'
29
31
  spec.add_dependency 'typhoeus'
30
32
 
31
33
  spec.add_development_dependency 'bundler'
@@ -8,7 +8,7 @@ end
8
8
  #
9
9
  When(/^the client does (\d+) concurrent GET requests to "([^"]*)"$/) do |count, url|
10
10
  hydra = Typhoeus::Hydra.new
11
- @last_requests = count.to_i.times.map do
11
+ @last_requests = Array.new(count.to_i) do
12
12
  request = Typhoeus::Request.new(url, followlocation: true)
13
13
  hydra.queue(request)
14
14
  request
@@ -0,0 +1,33 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ # * Given the following endpoint configurations:
5
+ # | service | endpoint | method | status |
6
+ # | subscription | /hello/world | GET | 200 |
7
+ # | core | /hello | POST | 204 |
8
+ #
9
+ # This step definition is dependent on the mock-server implementation available
10
+ # at https://github.com/eterps/mock-server. You need to set the
11
+ # `MOCK_ENDPOINT_HOST` environment variable for this step to work.
12
+ #
13
+ Given(/^the following endpoint configurations:$/) do |table|
14
+ unless ENV['MOCK_ENDPOINT_HOST']
15
+ puts 'environment variable missing: MOCK_ENDPOINT_HOST'
16
+ next pending
17
+ end
18
+
19
+ table.hashes.each do |row|
20
+ payload = { request: {}, response: {} }
21
+
22
+ %i(method endpoint).each do |option|
23
+ payload[:request][option.to_sym] = row[option.to_s]
24
+ end
25
+
26
+ %i(status headers body).each do |option|
27
+ payload[:response][option.to_sym] = row[option.to_s]
28
+ end
29
+
30
+ payload[:request][:endpoint] = File.join(row['service'], payload[:request][:endpoint])
31
+ Net::HTTP.start(ENV['MOCK_ENDPOINT_HOST']).post('/mock/_mocks', payload.to_json)
32
+ end
33
+ end
@@ -2,6 +2,7 @@ require 'active_support/core_ext/hash/keys'
2
2
  require 'active_support/core_ext/hash/compact'
3
3
  require 'active_support/core_ext/object/blank'
4
4
  require 'active_support/core_ext/string/inflections'
5
+ require 'chronic'
5
6
  require 'sequel'
6
7
 
7
8
  # rubocop:disable Lint/Eval,Metrics/LineLength,Lint/UselessAssignment
@@ -11,12 +12,12 @@ require 'sequel'
11
12
  # | hello | 100 |
12
13
  # | world | 10 |
13
14
  #
14
- Given(/^the following (\S+) exist:$/) do |object, table|
15
+ Given(/^the following ((?:(?!should).)+) exist:$/) do |object, table|
15
16
  table.hashes.each do |row|
16
- hash = parse_row(row)
17
+ hash = parse_row(row, object)
17
18
 
18
- assert eval("#{object.singularize.capitalize}.create(hash)")
19
- step %(the following #{object.singularize} should exist:), table([hash.keys, hash.values])
19
+ assert eval("#{object.tr(' ', '_').singularize.classify}.create(hash)")
20
+ step %(the following #{object} should exist:), table([hash.keys, hash.values])
20
21
  end
21
22
  end
22
23
 
@@ -27,8 +28,8 @@ end
27
28
  Given(/^the (\S+) with (\S+) "([^"]*)"(?: and(?: the)? (\S+) "([^"]*)")? exists$/) do |object, attribute1, value1, attribute2, value2|
28
29
  hash = { attribute1 => value1, attribute2 => value2 }.symbolize_keys.compact
29
30
 
30
- assert eval("#{object.singularize.capitalize}.create(hash)")
31
- step %(the following #{object.singularize} should exist:), table([hash.keys, hash.values])
31
+ assert eval("#{object.tr(' ', '_').singularize.classify}.create(hash)")
32
+ step %(the following #{object} should exist:), table([hash.keys, hash.values])
32
33
  end
33
34
 
34
35
  # * Given the item with uid "hello" and the following description:
@@ -39,19 +40,18 @@ end
39
40
  Given(/^the (\S+) with (\S+) "([^"]*)" and the following (\S+):$/) do |object, attribute1, value1, attribute2, value2|
40
41
  hash = { attribute1 => value1, attribute2 => value2 }.symbolize_keys
41
42
 
42
- assert eval("#{object.singularize.capitalize}.create(hash)")
43
- step %(the following #{object.singularize} should exist:), table([hash.keys, hash.values])
43
+ assert eval("#{object.tr(' ', '_').singularize.classify}.create(hash)")
44
+ step %(the following #{object} should exist:), table([hash.keys, hash.values])
44
45
  end
45
46
 
46
47
  # * Then the item with uid "hello" should exist
47
48
  # * Then the item with uid "hello" should not exist
48
- # * Then the item with labels (Array) "[10234, 64325]" should exist
49
49
  #
50
- Then(/^the (\S+) with (\S+)(?: \((\S+)\))? "([^"]*)" should( not)? exist$/) do |object, attribute, type, value, negate|
51
- hash = parse_row("#{attribute} (#{type})" => value)
50
+ Then(/^the (\S+) with (\S+) "([^"]*)" should( not)? exist$/) do |object, attribute, value, negate|
51
+ hash = parse_row({ attribute => value }, object)
52
52
  assertion = negate ? 'blank?' : 'present?'
53
53
 
54
- assert eval("#{object.capitalize}.first(hash).#{assertion}"),
54
+ assert eval("#{object.tr(' ', '_').singularize.classify}.first(hash).#{assertion}"),
55
55
  %(#{object.capitalize} not found \(#{attribute}: #{value}\))
56
56
  end
57
57
 
@@ -60,13 +60,17 @@ end
60
60
  # | hello | 100 |
61
61
  # * Then the following items should not exist:
62
62
  #
63
- Then(/^the following (\S+) should( not)? exist:$/) do |object, negate, table|
63
+ Then(/^the following (.+)? should( not)? exist:$/) do |object, negate, table|
64
64
  assertion = negate ? 'blank?' : 'present?'
65
65
 
66
66
  table.hashes.each do |row|
67
- hash = parse_row(row)
67
+ hash = parse_row(row, object)
68
+ klass = object.tr(' ', '_').singularize.classify
68
69
 
69
- assert eval("#{object.capitalize}.first(hash).#{assertion}")
70
+ assert eval("#{klass}.first(hash).#{assertion}"),
71
+ "Could not find requested #{object}:\n\n" \
72
+ "- #{hash}\n" \
73
+ "+ #{Object.const_get(klass).all.map(&:values).join("\n+ ")}"
70
74
  end
71
75
  end
72
76
 
@@ -75,23 +79,38 @@ end
75
79
  # Given a Cucumber table row, parses the type "numbers (Array)" and converts the
76
80
  # string representation of the value "[1, 2, 3]" into a Sequel pg_array.
77
81
  #
78
- # @todo Rename method to a more sensible name
79
- # @todo Move method to helper file
80
- # @todo Add more types (Integer)
81
- #
82
82
  # @param [Object] row in Cucumber::Table
83
+ # @param [String] object_name to be parsed
83
84
  # @return [Hash] hash representation of key/values in table
84
85
  #
85
- def parse_row(row)
86
+ # rubocop:disable Metrics/CyclomaticComplexity
87
+ # rubocop:disable Metrics/MethodLength
88
+ # rubocop:disable Metrics/AbcSize
89
+ #
90
+ def parse_row(row, object_name)
91
+ table = object_name.tr(' ', '_')
92
+ klass = Object.const_get(table.singularize.classify)
93
+ schema = klass.db.schema(table)
94
+
86
95
  hash = row.map do |attribute, value|
87
- value = case attribute[/\s\((\w+)\)$/, 1]
88
- when 'Array'
96
+ column = schema.reverse.find { |c| c.first.to_s == attribute.to_s } || []
97
+
98
+ next [attribute.to_sym, value] unless value.is_a?(String)
99
+
100
+ value = case column.last.to_h[:type]
101
+ when :integer
102
+ value.to_i
103
+ when :datetime
104
+ Timecop.return { Chronic.parse(value) || DateTime.parse(value) }
105
+ when :boolean
106
+ value.to_s.casecmp('true')
107
+ when :string_array, :varchar_array, :bigint_array
89
108
  Sequel.pg_array(eval(value))
90
109
  else
91
110
  value
92
111
  end
93
112
 
94
- [attribute.to_s.split.first.to_sym, value]
113
+ [attribute.to_sym, value]
95
114
  end
96
115
 
97
116
  Hash[hash]
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cucumber
2
4
  # BlendleSteps
3
5
  #
4
6
  # This module defines default steps used by all of Blendle Ruby projects.
5
7
  #
6
8
  module BlendleSteps
7
- VERSION = '0.4.0'
9
+ VERSION = '0.5.0'.freeze
8
10
  end
9
11
  end
@@ -5,6 +5,7 @@ require 'cucumber/blendle/support/minitest'
5
5
  require 'cucumber/blendle/support/rack_test'
6
6
 
7
7
  require 'cucumber/blendle/steps/benchmark_steps'
8
+ require 'cucumber/blendle/steps/mock_server_steps'
8
9
  require 'cucumber/blendle/steps/model_steps'
9
10
  require 'cucumber/blendle/steps/resource_steps'
10
11
  require 'cucumber/blendle/steps/rest_steps'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-blendle-steps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Mertz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chronic
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: cucumber
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: timecop
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: typhoeus
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -265,6 +293,7 @@ files:
265
293
  - Rakefile
266
294
  - cucumber-blendle-steps.gemspec
267
295
  - lib/cucumber/blendle/steps/benchmark_steps.rb
296
+ - lib/cucumber/blendle/steps/mock_server_steps.rb
268
297
  - lib/cucumber/blendle/steps/model_steps.rb
269
298
  - lib/cucumber/blendle/steps/resource_steps.rb
270
299
  - lib/cucumber/blendle/steps/rest_steps.rb
@@ -294,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
323
  version: '0'
295
324
  requirements: []
296
325
  rubyforge_project:
297
- rubygems_version: 2.4.5.1
326
+ rubygems_version: 2.5.1
298
327
  signing_key:
299
328
  specification_version: 4
300
329
  summary: Cucumber steps used by all of Blendle Ruby projects