cucumber-formatter 1.0.0 → 1.1.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cucumber_formatter.rb +72 -36
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e476c346672c51f036ddf89abf4632d9d27579a
4
- data.tar.gz: 58184c841540ac038ea79602b0a84e0aa27e97c4
3
+ metadata.gz: c210b68da615b9dee9bd2882a910aef3eda52fec
4
+ data.tar.gz: 074bc10c433f939741a61a83d5d0002945328e92
5
5
  SHA512:
6
- metadata.gz: 7af94bb19f29b63edc9cc7ea3a9dd17f217530d26e8bb6ce9518de3f2da52f896a85898db22eb344f30211fc759c4112d15c60632756ee69af72eea12e107bcf
7
- data.tar.gz: 5ea75aab1eb0be1d22cadd4f6a66b1ce4170a4cbe6b170ae367666e7ae46263f37a4fe6c1bc70e01a51b24c16e6b79f343c7087d3819a20e12e5f0eee316d04d
6
+ metadata.gz: 40203ddf676dd86c2c1aa0ced85868009a4102ad849b27fe012b82469dab51726967f5cf2b79e942cf2ad961e022e006f9862b1abea5e755748eba76268238c8
7
+ data.tar.gz: 2e1c34338c7a09258b3ecbdff2ca06058def7c70dc5d96c71dd28f8c65cfd94935c8bbd8f579517d80ac4b45c8d41bff32536d2fd6120047d53e3bb78687c0d9
@@ -34,49 +34,39 @@ class CucumberFormatter
34
34
  puts "Initializing CucumberMetrics ...\n\n\n"
35
35
  end
36
36
 
37
- def before_feature_element(scenario)
38
- @scenario = scenario
39
- @scenario_time_start = Time.now
40
-
41
- @start_time = Time.now
42
- @end_time = Time.now
43
- machine_name = Socket.gethostname
44
-
45
- @dbm ||= dbm
37
+ def before_feature(feature)
38
+ @background = true
39
+ @scenario_counter ||= 0
46
40
 
47
- if scenario == nil
48
- fail "The scenario did not run"
49
- end
50
-
51
- get_scenario_id(scenario)
52
- get_environment_id
53
- get_browser_id
54
-
55
- # save the test run
56
- sql = "INSERT INTO scenario_test_runs (scenario_id, test_run_at, test_environment_id,
57
- browser_id, machine_name, created_at, updated_at)
58
- VALUES (#{@scenario_id}, now(), #{@env_id}, #{@browser_id}, \'#{machine_name}\', now(), now())"
59
- @dbm.query(sql)
60
- @str_id = @dbm.last_id
41
+ @scenario = feature.feature_elements[@scenario_counter]
42
+ @scenario_counter += 1
43
+ save_str_start_time
44
+ end
61
45
 
62
- # extract and save the tags
63
- tags = extract_tags(scenario)
64
- tags.each do |t|
65
- sql = "INSERT INTO scenario_tags (scenario_test_run_id, tag_name, created_at, updated_at)
66
- VALUES (#{@str_id}, \'#{t}\', now(), now())"
67
- @dbm.query(sql)
46
+ # the first set of background steps don't call this method (cucumber 1.3.19) - instead
47
+ # before_feature is called.
48
+ def before_feature_element(scenario)
49
+ unless @background
50
+ @scenario = scenario
51
+ save_str_start_time
68
52
  end
69
53
  end
70
54
 
71
55
  #save the step
72
56
  def after_step(step)
73
- step_name = get_step_name(@scenario).strip[0..255].gsub('\'', '')
57
+ step_name = get_step_name(@scenario)
58
+ # background steps seem to be adding an extra after_step call. This is above and beyond
59
+ # the fact that they don't call before_feature_elements until after the background
60
+ # executes
61
+ unless step_name == nil
62
+ step_name = step_name.strip[0..255].gsub('\'', '')
63
+ end
74
64
  @start_time = @end_time
75
65
  @end_time = Time.now
76
66
 
77
67
  sql = "INSERT INTO scenario_steps (scenario_test_run_id, name, elapsed_time, created_at, updated_at)
78
68
  VALUES (#{@str_id}, \'#{step_name}\', #{(@end_time - @start_time).round}, now(), now())"
79
- @dbm.query sql
69
+ @dbm.query sql unless step_name == nil
80
70
  end
81
71
 
82
72
  #finish saving the test run
@@ -92,17 +82,63 @@ class CucumberFormatter
92
82
  end
93
83
  #reset step counter when scenario is finished
94
84
  @step_counter = 0
85
+ # clear the background flag - it seems to only happen once
86
+ @background = false
95
87
  end
96
88
 
97
89
  private
98
90
 
91
+ def save_str_start_time
92
+ ###############
93
+ @scenario_time_start = Time.now
94
+
95
+ @start_time = Time.now
96
+ @end_time = Time.now
97
+ machine_name = Socket.gethostname
98
+
99
+ @dbm ||= dbm
100
+
101
+ if @scenario == nil
102
+ fail "The scenario did not run"
103
+ end
104
+
105
+ get_scenario_id(@scenario)
106
+ get_environment_id
107
+ get_browser_id
108
+
109
+ save_test_run(machine_name)
110
+ save_tags
111
+ end
112
+
113
+ def save_tags
114
+ # extract and save the tags
115
+ tags = extract_tags
116
+ tags.each do |t|
117
+ sql = "INSERT INTO scenario_tags (scenario_test_run_id, tag_name, created_at, updated_at)
118
+ VALUES (#{@str_id}, \'#{t}\', now(), now())"
119
+ @dbm.query(sql)
120
+ end
121
+ end
122
+
123
+ def save_test_run(machine_name)
124
+ # save the test run
125
+ sql = "INSERT INTO scenario_test_runs (scenario_id, test_run_at, test_environment_id,
126
+ browser_id, machine_name, created_at, updated_at)
127
+ VALUES (#{@scenario_id}, now(), #{@env_id}, #{@browser_id}, \'#{machine_name}\', now(), now())"
128
+ @dbm.query(sql)
129
+ @str_id = @dbm.last_id
130
+ end
131
+
99
132
  # get the step name; keep track of the counter through the scenario
100
133
  def get_step_name(scenario)
101
134
  @step_counter ||= 0
102
- steps = scenario.instance_eval {@steps}
103
- step_name = (steps.instance_eval {@steps})[@step_counter]
135
+ step = scenario.steps.to_a[@step_counter]
104
136
  @step_counter += 1
105
- return step_name.name
137
+ if step == nil
138
+ step
139
+ else
140
+ step.name
141
+ end
106
142
  end
107
143
 
108
144
  def get_scenario_id(scenario)
@@ -185,8 +221,8 @@ class CucumberFormatter
185
221
  :database => database.metrics_db['database'])
186
222
  end
187
223
 
188
- def extract_tags(scenario)
189
- scenario.source_tag_names
224
+ def extract_tags
225
+ @scenario.source_tag_names
190
226
  end
191
227
 
192
228
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hartill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-05 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2