probedock-cucumber 0.1.0 → 0.1.1

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: 2286ed5e21fbf47725e16a0c43c6e9f977f6b8f6
4
- data.tar.gz: 6a32e6aa3309aef8cda90a6b35c7131424827ce1
3
+ metadata.gz: 51a99b927ad1d4edd9c1c4a90c407b8a4743d262
4
+ data.tar.gz: 3e264ed7f2ec4beb507fe2b472c0fafa06d4bf0e
5
5
  SHA512:
6
- metadata.gz: 58cac119d835d2c90c3c12c71405662be7bfee895c01a0d24bb3589406872ce812b3c123c4d6b09ff933e3a345a93313052155c4dbe9103f8f77ad8229c6c7cb
7
- data.tar.gz: c4b678b65c203690cd0cded6c85b507813225e83ab72887a556b6a85b0a4af9874076552ff623f08b1ef904bc7eb04ce26f0e5f217eb692fc8fea7fcf1de66fb
6
+ metadata.gz: cdc350bb64b6b7a8630d76c36bd8df034d5c41512ae51480fb8ee3abf7905bd7279a6b0db44fc35aa2f7eebfa72dc3c1ace97b4d8e77da81d5bb5a044c78608d
7
+ data.tar.gz: 21b1f8676d432f3276a92c26fafb7dbb363cfc1a612cb2e50337625d55a29ef3913c16e88c5e2ad641fb47f31e0d515a8c3914f8dccbc045f89da5b28ae0a1eb
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Probe Dock Cucumber
2
2
 
3
- **Cucumber (Ruby) probe for [Probe Dock](https://github.com/probedock/probedock).**
3
+ **[Cucumber](https://cucumber.io) (Ruby) probe for [Probe Dock](https://github.com/probedock/probedock).**
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/probedock-cucumber.svg)](http://badge.fury.io/rb/probedock-cucumber)
6
6
  [![Dependency Status](https://gemnasium.com/probedock/probedock-cucumber-ruby.svg)](https://gemnasium.com/probedock/probedock-cucumber-ruby)
@@ -13,7 +13,7 @@
13
13
  In your Gemfile:
14
14
 
15
15
  ```rb
16
- gem 'probedock-cucumber', '~> 0.1.0'
16
+ gem 'probedock-cucumber', '~> 0.1.1'
17
17
  ```
18
18
 
19
19
  Then run `bundle install`.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -2,7 +2,7 @@
2
2
  require 'probedock-ruby'
3
3
 
4
4
  module ProbeDockCucumber
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
 
7
7
  class Error < StandardError; end
8
8
  end
@@ -1,75 +1,151 @@
1
1
  require 'paint'
2
2
  require 'digest/sha1'
3
3
 
4
+ # Cucumber formatter to send test results to Probe Dock.
5
+ #
6
+ # The following events can be received by a formatter:
7
+ #
8
+ # before_features
9
+ # before_feature
10
+ # before_comment
11
+ # comment_line
12
+ # after_comment
13
+ # before_tags
14
+ # tag_name
15
+ # after_tags
16
+ # feature_name
17
+ # before_feature_element
18
+ # before_tags
19
+ # tag_name
20
+ # after_tags
21
+ # scenario_name
22
+ # before_steps
23
+ # before_step
24
+ # before_step_result
25
+ # step_name
26
+ # after_step_result
27
+ # after_step
28
+ # after_steps
29
+ # after_feature_element
30
+ # after_feature
31
+ # after_features
4
32
  module ProbeDockCucumber
5
33
  class Formatter
6
34
 
7
35
  def initialize step_mother, io, options
8
36
 
37
+ # Initialize the Probe Dock client and an empty test run.
9
38
  config = ProbeDockProbe.config
10
39
  @client = ProbeDockProbe::Client.new config.server, config.client_options
11
40
  @test_run = ProbeDockProbe::TestRun.new config.project
12
41
 
42
+ # Current feature data.
13
43
  @current_feature = nil
14
44
  @current_feature_tags = []
15
45
 
46
+ # Current scenario data.
16
47
  @current_scenario = nil
17
48
  @current_scenario_tags = []
18
49
  @current_scenario_error = nil
19
50
  end
20
51
 
52
+ # Called when the test suite starts.
21
53
  def before_features *args
22
- @start_time = Time.now
54
+ @suite_start_time = Time.now
23
55
  end
24
56
 
57
+ # Called before each feature is tested.
25
58
  def before_feature feature, *args
59
+
60
+ # Store the first line of the feature's description.
61
+ # It will be used in #add_result to build the complete name of the test.
26
62
  @current_feature = feature.name.sub(/\n.*$/m, '').strip
63
+
64
+ # Reset feature and scenario data.
27
65
  @current_feature_tags = []
28
66
  @current_scenario = nil
67
+ @current_scenario_tags = []
68
+ @current_scenario_error = nil
29
69
  end
30
70
 
31
- def after_tags tags, *args
71
+ # Called every time a tag is encountered, either at the feature or the scenario level.
72
+ def tag_name name, *args
32
73
  if @current_scenario
33
- @current_scenario_tags = tags.tags.collect{ |tag| tag.name.sub(/^@/, '').strip }.uniq
74
+ @current_scenario_tags << name.sub(/^@/, '').strip
34
75
  else
35
- @current_feature_tags = tags.tags.collect{ |tag| tag.name.sub(/^@/, '').strip }.uniq
76
+ @current_feature_tags << name.sub(/^@/, '').strip
36
77
  end
37
78
  end
38
79
 
80
+ # Called before each scenario is tested.
39
81
  def before_feature_element feature_element, *args
82
+
83
+ # Store the first line of the scenario's description.
84
+ # It will be used in #add_result to build the complete name of the test.
40
85
  @current_scenario = feature_element.name.sub(/\n.*$/m, '').strip
86
+
87
+ # Reset scenario data.
41
88
  @current_scenario_tags = []
42
89
  @current_scenario_error = nil
43
90
  @current_scenario_start_time = Time.now
44
91
  end
45
92
 
93
+ # Called after each scenario step (Given, When, Then) is executed.
46
94
  def after_step_result keyword, step_match, multiline_arg, status, exception, *args
47
- if exception
48
- @current_scenario_error = exception
49
- end
95
+ # If a step fails, the exception is provided here.
96
+ # It will be used in #add_result to build the error message of the test.
97
+ @current_scenario_error = exception if exception
50
98
  end
51
99
 
100
+ # Called after each completed scenario.
52
101
  def after_feature_element *args
53
- add_result !@current_scenario_error, @current_scenario_error
102
+ add_result
54
103
  end
55
104
 
105
+ # Called when the test suite ends.
56
106
  def after_features *args
57
- #puts "after_features: #{args.inspect}"
58
107
  end_time = Time.now
59
- @test_run.duration = ((end_time - @start_time) * 1000).round
60
- puts @test_run.inspect
61
- #@client.process @test_run
108
+ @test_run.duration = ((end_time - @suite_start_time) * 1000).round
109
+ @client.process @test_run
62
110
  end
63
111
 
64
112
  private
65
113
 
66
- def add_result successful, error = nil
114
+ # Adds a result to the test run.
115
+ # The test and result data was stored while the features and scenarios
116
+ # were being executed (see #before_feature, #tag_name, etc).
117
+ def add_result
67
118
 
68
- options = {
69
- tags: (@current_feature_tags + @current_scenario_tags).uniq,
119
+ result_options = {
120
+ name: complete_name,
121
+ passed: !@current_scenario_error,
70
122
  data: {}
71
123
  }
72
124
 
125
+ result_options[:duration] = ((Time.now - @current_scenario_start_time) * 1000).round
126
+
127
+ # Combine the tags of the feature and of the scenario.
128
+ result_options[:tags] = (@current_feature_tags + @current_scenario_tags).uniq.sort
129
+
130
+ # The fingerprint identifying the test contains the first line of the
131
+ # feature's and the scenario's descriptions joined with a separator.
132
+ fingerprint_data = [ @current_feature, @current_scenario ]
133
+ result_options[:fingerprint] = Digest::SHA1.hexdigest fingerprint_data.join('|||')
134
+ result_options[:data][:fingerprint] = result_options[:fingerprint]
135
+
136
+ # Build the message from the error's message and backtrace if an error occurred.
137
+ result_options[:message] = failure_message @current_scenario_error if @current_scenario_error
138
+
139
+ @test_run.add_result result_options
140
+ end
141
+
142
+ # Builds the complete test name.
143
+ # The name is obtained by joining the first line of the feature's
144
+ # and the scenario's descriptions. Additionally, if the feature's
145
+ # description doesn't end with a dot, a semicolon is added
146
+ # (e.g. "Feature: Scenario").
147
+ def complete_name
148
+
73
149
  name = @current_feature.dup
74
150
  if name.match /\.$/
75
151
  name << ' '
@@ -78,17 +154,6 @@ module ProbeDockCucumber
78
154
  end
79
155
 
80
156
  name << @current_scenario
81
-
82
- options[:name] = name
83
-
84
- fingerprint_data = [ @current_feature, @current_scenario ]
85
- options[:fingerprint] = Digest::SHA1.hexdigest fingerprint_data.join('|||')
86
- options[:data][:fingerprint] = options[:fingerprint]
87
-
88
- options.merge! passed: successful, duration: ((Time.now - @current_scenario_start_time) * 1000).round
89
- options[:message] = failure_message error if error
90
-
91
- @test_run.add_result options
92
157
  end
93
158
 
94
159
  def failure_message error
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: probedock-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Oulevay (Alpha Hydrae)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-30 00:00:00.000000000 Z
11
+ date: 2015-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: probedock-ruby