cucumber-blendle-steps 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25d26ba860c0da9719eee16fa5eb3fc3641b548c
4
- data.tar.gz: 02d274db34686c0fdc268b703ef9b9590204a0c3
3
+ metadata.gz: 3df02056f134d8d76ecf362e33821362dda8b1e0
4
+ data.tar.gz: f957d8489763584193f38ce7171485e80db604ed
5
5
  SHA512:
6
- metadata.gz: 4f282a1af2de84a312ab33344d9471c20b651403cf3f08204897bd0088515ff8a26dd8a4fd001f9441b97d74d71fb603fb8a3b3465f43a2d0c12edba94b592b4
7
- data.tar.gz: 6f49f335cf4f12530d428fc2972dda432b01f9fe017e0e0d289099a75ee95c898a5e07ffc5e645255e3ad828128d0ac21ffde72f076d5dcf5ba8b528342a9933
6
+ metadata.gz: c789dffa7c5417b0f7ed9969a5dfc6b66b79d37166e5bc348c90e5158a6762df35b27c40dab33fd787a1df9d717dced6b946b7bc2029f577a81fa5db7ecdc578
7
+ data.tar.gz: 01625d667f9d76161eb7fb8097750f1c42174fb651a0342eaae2cf8d0dec8cba1222df3eaee12da31367c7305781e96387e977840c63b7d0dc97233c0f6c346e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [v0.6.1](https://github.com/blendle/cucumber-blendle-steps/tree/v0.6.1) (2016-03-18)
4
+ [Full Changelog](https://github.com/blendle/cucumber-blendle-steps/compare/v0.6.0...v0.6.1)
5
+
3
6
  ## [v0.6.0](https://github.com/blendle/cucumber-blendle-steps/tree/v0.6.0) (2016-03-16)
4
7
  [Full Changelog](https://github.com/blendle/cucumber-blendle-steps/compare/v0.5.1...v0.6.0)
5
8
 
@@ -4,7 +4,9 @@ require 'time'
4
4
 
5
5
  module Cucumber
6
6
  module BlendleSteps
7
+ # :no-doc:
7
8
  class LiquidFilters
9
+ # :no-doc:
8
10
  module Date
9
11
  def date(input)
10
12
  Timecop.return { Chronic.parse(input) || DateTime.parse(input) }.utc.iso8601
@@ -22,3 +22,118 @@ end
22
22
  Then(/^all requests should have succeeded$/) do
23
23
  last_requests.map(&:code).any? { |status| status.to_s[0] != 2 }
24
24
  end
25
+
26
+ When(/^I start measuring performance$/) do
27
+ unless @scenario_tags.include?('@performance')
28
+ assert false, 'measuring performance requires the "@performance" tag to be present.'
29
+ end
30
+
31
+ step %(I start measuring time)
32
+ step %(I start measuring SQL queries)
33
+ end
34
+
35
+ # Puts the current time in the `@performance_start_time` instance variable. This
36
+ # value is then used in the "request time hasn't exceeded x milliseconds" step
37
+ # to calculate elapsed time.
38
+ #
39
+ When(/^I start measuring time$/) do
40
+ unless @scenario_tags.include?('@performance')
41
+ assert false, 'measuring time requires the "@performance" tag to be present.'
42
+ end
43
+
44
+ @performance_start_time = Timecop.return { Time.now }
45
+ end
46
+
47
+ # * Then request time hasn't exceeded 100 milliseconds
48
+ #
49
+ # Note: it is not needed to call the "I stop measuring time" step first. If the
50
+ # time recording is still running, it will be stopped during the call of this
51
+ # step.
52
+ #
53
+ Then(/^request time hasn't exceeded (\d+) milliseconds$/) do |milliseconds|
54
+ step('I stop measuring time') unless @performance_stop_time
55
+
56
+ elapsed_time = ((@performance_stop_time - @performance_start_time) * 1000.0).to_i
57
+
58
+ puts "elapsed time: #{elapsed_time}"
59
+ expect(elapsed_time).to be < milliseconds.to_i
60
+ end
61
+
62
+ # Puts the current time in the `@performance_stop_time` instance variable. This
63
+ # value is then used in the "request time hasn't exceeded x milliseconds" step
64
+ # to calculate elapsed time.
65
+ #
66
+ Then(/^I stop measuring time$/) do
67
+ @performance_stop_time = Timecop.return { Time.now }
68
+ end
69
+
70
+ # Starts the DB profiler to measure number of SQL queries made. It also enables
71
+ # debug printing of the executed queries.
72
+ #
73
+ When(/^I start measuring SQL queries/) do
74
+ unless @scenario_tags.include?('@performance')
75
+ assert false, 'counting SQL queries requires the "@performance" tag to be present.'
76
+ end
77
+
78
+ DBProfiler.start
79
+ end
80
+
81
+ # * Then exactly 5 database queries have been executed
82
+ #
83
+ Then(/^exactly (\d+) database queries have been executed/) do |query_count|
84
+ puts "queries counted: #{DBProfiler.query_count}"
85
+
86
+ expect(DBProfiler.query_count).to eql(query_count.to_i)
87
+ end
88
+
89
+ # Stops the DBProfiler, resetting the query counter, and disabling debug output
90
+ # of executed queries.
91
+ #
92
+ Then(/^I stop measuring SQL queries$/) do
93
+ DBProfiler.stop
94
+ end
95
+
96
+ Then(/^I stop measuring performance$/) do
97
+ step %(I stop measuring time)
98
+ step %(I stop measuring SQL queries)
99
+ end
100
+
101
+ # After each scenario with the `@performance` tag, the DBProfiler is stopped,
102
+ # and all measured request times are reset.
103
+ #
104
+ After('@performance') do
105
+ DBProfiler.stop
106
+
107
+ instance_variable_set(:@performance_stop_time, nil)
108
+ instance_variable_set(:@performance_start_time, nil)
109
+ end
110
+
111
+ # :no-doc:
112
+ class DBProfiler
113
+ def self.start
114
+ @count_stringio = StringIO.new
115
+ print_logger = Logger.new($stdout)
116
+ print_logger.formatter = proc { |_, _, _, msg| "#{msg}\n" }
117
+ DB.loggers.concat([print_logger, Logger.new(@count_stringio)])
118
+ end
119
+
120
+ def self.stop
121
+ DB.loggers.clear
122
+ end
123
+
124
+ def self.queries
125
+ @count_stringio.string.split("\n").map { |n| n.scan(/-- : (.*?)$/).flatten.first }
126
+ end
127
+
128
+ def self.single_quoted_queries
129
+ queries.join("\n").tr('"', "'").split("\n")
130
+ end
131
+
132
+ def self.queries_only
133
+ single_quoted_queries.select { |n| n =~ /\(\d/ }
134
+ end
135
+
136
+ def self.query_count
137
+ queries_only.count
138
+ end
139
+ end
@@ -104,7 +104,7 @@ def parse_row(row, object_name)
104
104
  when :datetime
105
105
  Timecop.return { Chronic.parse(value) || DateTime.parse(value) }
106
106
  when :boolean
107
- value.to_s.downcase == 'true'
107
+ value.to_s.casecmp('true').zero?
108
108
  when :string_array, :varchar_array, :bigint_array
109
109
  Sequel.pg_array(eval(value))
110
110
  else
@@ -0,0 +1,11 @@
1
+ Before do |scenario|
2
+ @scenario_name = scenario.name
3
+ @scenario_hash = Digest::SHA1.hexdigest(@scenario_name)[5]
4
+ @scenario_tags = scenario.source_tag_names
5
+ end
6
+
7
+ After do
8
+ instance_variable_set(:@scenario_name, nil)
9
+ instance_variable_set(:@scenario_hash, nil)
10
+ instance_variable_set(:@scenario_tags, nil)
11
+ end
@@ -6,6 +6,6 @@ module Cucumber
6
6
  # This module defines default steps used by all of Blendle Ruby projects.
7
7
  #
8
8
  module BlendleSteps
9
- VERSION = '0.6.1'.freeze
9
+ VERSION = '0.7.0'.freeze
10
10
  end
11
11
  end
@@ -1,5 +1,6 @@
1
1
  require 'cucumber/blendle/helpers/liquid_filters'
2
2
 
3
+ require 'cucumber/blendle/support/cucumber'
3
4
  require 'cucumber/blendle/support/dump'
4
5
  require 'cucumber/blendle/support/hyper_resource'
5
6
  require 'cucumber/blendle/support/json_spec'
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.6.1
4
+ version: 0.7.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-03-18 00:00:00.000000000 Z
11
+ date: 2016-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -326,6 +326,7 @@ files:
326
326
  - lib/cucumber/blendle/steps/model_steps.rb
327
327
  - lib/cucumber/blendle/steps/resource_steps.rb
328
328
  - lib/cucumber/blendle/steps/rest_steps.rb
329
+ - lib/cucumber/blendle/support/cucumber.rb
329
330
  - lib/cucumber/blendle/support/dump.rb
330
331
  - lib/cucumber/blendle/support/hyper_resource.rb
331
332
  - lib/cucumber/blendle/support/json_spec.rb