race_condition-rspec 0.0.3 → 0.0.4

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: b6c2d9166f3c3096d8f478697511724506fa103d
4
- data.tar.gz: b47be25f3c6aa37705cac78ef75ea85504c84ac2
3
+ metadata.gz: 36cda9c2eb826865fb948b83584460adf4e9561c
4
+ data.tar.gz: 491391fb105aa01f7dde471737f8c56bb8414c43
5
5
  SHA512:
6
- metadata.gz: 94d10c6abbaa5585cd9b4419b0d2eb9ff9a5005848cb454f859405ecb6a96ed2bb4a3b027e0057d3d702a820fac4d503c35dbe382893195d26d4170ea648d1ac
7
- data.tar.gz: 41ad5821ad7db5df621a777ebd2559e7cc6b0475372ea3b9e4ea69f391e0845b26a2bac4469f6ba3d34bf09c93fcd313ce025249189be959b0e3b780d5306a94
6
+ metadata.gz: 2cda2a25c932b37331fa81e12b628360c16b415784a29c5f95b01067bd136d16c20ef4e4a75b3293df38aeb487a5502bc6a6097cc2cbd094f3effa69fd4ac107
7
+ data.tar.gz: d8d42a7d8edf891e106bbfa8ef085acbfafc9afd74a316b92c48e21491be5439618977b3857b664ad72859dd266a7ad54afc959e14c62d91ee83dae3b81b20fc
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RaceCondition::Rspec [![Build Status](https://travis-ci.org/RaceCondition-io/race_condition-rspec.svg?branch=master)](https://travis-ci.org/RaceCondition-io/race_condition-rspec)
1
+ # RaceCondition::RSpec [![Build Status](https://travis-ci.org/RaceCondition-io/race_condition-rspec.svg?branch=master)](https://travis-ci.org/RaceCondition-io/race_condition-rspec)
2
2
 
3
3
  RSpec client for sending test suite results to RaceCondition.
4
4
 
@@ -29,7 +29,7 @@ RaceCondition::RSpec.configure do |c|
29
29
  end
30
30
  ```
31
31
 
32
- * `report_if` - This is a boolean or lambda that tells the reporter if it should test suite results to the server. Most popular CI servers set the `CI` environment variable.
32
+ * `report_if` - This is a boolean or lambda that tells the reporter if it should send test suite results to the server. Most popular CI servers set the `CI` environment variable.
33
33
  * `codebase_id` - This is the codebase ID from RaceCondition that you want to send the results to.
34
34
  * `branch_name` - The current branch name (optional, but recommended).
35
35
  * `commit` - The commit under test (optional).
@@ -1,29 +1,48 @@
1
+ require "net/http"
2
+ require 'json'
3
+
1
4
  module RaceCondition
2
5
  class Client
3
- include APISmith::Client
4
-
5
- base_uri "https://racecondition.io/"
6
- endpoint "api/1"
6
+ ENDPOINT = "api/v1"
7
7
 
8
8
  def report!(project_id, report_output)
9
9
  return unless report?
10
10
 
11
11
  puts "Sending test run data to RaceCondition..."
12
- params = { build: report_output }
13
- post("projects/#{project_id}/builds", extra_body: params)
14
- rescue Errno::ECONNREFUSED, SocketError, Net::ReadTimeout
15
- puts "Unable to reach RaceCondition."
16
- end
12
+ response = post("projects/#{project_id}/builds", report_output)
17
13
 
18
- def check_response_errors(response)
14
+ unless response.code.to_i == 200
15
+ puts "Unable to log test results to RaceCondition."
16
+ end
17
+ rescue Errno::ECONNREFUSED, SocketError, Net::ReadTimeout => e
18
+ puts "Unable to reach RaceCondition."
19
19
  end
20
20
 
21
21
  private
22
22
 
23
+ def post(path, params)
24
+ url = URI.parse("#{base_url}/#{ENDPOINT}/#{path}")
25
+
26
+ http = Net::HTTP.new(url.host, url.port)
27
+ http.read_timeout = 5
28
+ http.open_timeout = 5
29
+
30
+ json_headers = {
31
+ "Content-Type" => "application/json",
32
+ "Accept" => "application/json"
33
+ }
34
+
35
+ http.post(url.path, params.to_json, json_headers)
36
+ end
37
+
23
38
  def report?
24
39
  config.report?
25
40
  end
26
41
 
42
+ def base_url
43
+ config.report_to_domain
44
+ end
45
+
27
46
  def config
28
47
  RaceCondition::RSpec.configuration
29
48
  end
@@ -6,7 +6,12 @@ module RaceCondition
6
6
  :commit,
7
7
  :build_number,
8
8
  :codebase_id,
9
- :report_if
9
+ :report_if,
10
+ :report_to_domain # for testing purposes
11
+
12
+ def initialize
13
+ self.report_to_domain = "https://racecondition.io"
14
+ end
10
15
 
11
16
  def report?
12
17
  if report_if.respond_to? :call
@@ -13,10 +13,13 @@ module RaceCondition
13
13
 
14
14
  def broadcast!
15
15
  data = {
16
- seed: seed,
17
- duration: duration,
18
16
  examples: examples_output,
19
- metadata: metadata
17
+ seed: seed.seed,
18
+ client: "race_condition-rspec",
19
+ duration: duration,
20
+ branch_name: config.branch_name,
21
+ commit: config.commit,
22
+ build_number: config.build_number
20
23
  }
21
24
 
22
25
  allow_webmock!
@@ -29,14 +32,6 @@ module RaceCondition
29
32
  WebMock.allow_net_connect! if Object.const_defined?("WebMock")
30
33
  end
31
34
 
32
- def metadata
33
- {
34
- branch_name: config.branch_name,
35
- commit: config.commit,
36
- build_number: config.build_number
37
- }
38
- end
39
-
40
35
  def config
41
36
  RaceCondition::RSpec.configuration
42
37
  end
@@ -56,18 +51,20 @@ module RaceCondition
56
51
  example = example.example
57
52
  end
58
53
 
59
- data = example.execution_result.merge({
60
- description: example.description,
54
+ data = {
55
+ started_at: example.execution_result[:started_at].iso8601,
56
+ finished_at: example.execution_result[:finished_at].iso8601,
57
+ run_time: example.execution_result[:run_time],
58
+ result: example.execution_result[:status],
61
59
  full_description: example.full_description,
62
60
  file_path: example.file_path,
63
61
  location: example.location,
64
62
  type: example.metadata[:type]
65
- })
66
-
67
- if data[:exception]
68
- exception = data[:exception]
63
+ }
69
64
 
65
+ if exception = example.exception
70
66
  data[:exception] = {
67
+ rerun: "rspec #{rerun_argument_for(example)}",
71
68
  class: exception.class.name,
72
69
  message: exception.message,
73
70
  backtrace: exception.backtrace
@@ -76,6 +73,26 @@ module RaceCondition
76
73
 
77
74
  data
78
75
  end
76
+
77
+ # rerun logic from https://github.com/rspec/rspec-core/blob/4b0a10466cd19271bc5387bf5179bdb3b47a744d/lib/rspec/core/notifications.rb
78
+
79
+ def rerun_argument_for(example)
80
+ location = example.location_rerun_argument
81
+ return location unless duplicate_rerun_locations.include?(location)
82
+ example.id
83
+ end
84
+
85
+ def duplicate_rerun_locations
86
+ @duplicate_rerun_locations ||= begin
87
+ locations = ::RSpec.world.all_examples.map(&:location_rerun_argument)
88
+
89
+ Set.new.tap do |s|
90
+ locations.group_by { |l| l }.each do |l, ls|
91
+ s << l if ls.count > 1
92
+ end
93
+ end
94
+ end
95
+ end
79
96
  end
80
97
  end
81
98
  end
@@ -1,5 +1,5 @@
1
1
  module RaceCondition
2
2
  module Rspec
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -1,4 +1,3 @@
1
- require "api_smith"
2
1
  require "race_condition/rspec/version"
3
2
  require "race_condition/rspec/configuration"
4
3
  require "race_condition/client"
@@ -18,10 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "api_smith"
22
-
23
21
  spec.add_development_dependency "bundler", "~> 1.6"
24
22
  spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec", "~> 2.99.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0.0"
26
24
  spec.add_development_dependency "pry"
27
25
  end
@@ -1,8 +1,10 @@
1
1
  require "race_condition/rspec.rb"
2
2
 
3
- class RaceCondition::Client
4
- def report!(project, data)
5
- puts data.to_json
3
+ module RaceCondition
4
+ class Client
5
+ def report!(project_id, data)
6
+ puts data.to_json
7
+ end
6
8
  end
7
9
  end
8
10
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: race_condition-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Boland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-27 00:00:00.000000000 Z
11
+ date: 2016-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: api_smith
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +44,14 @@ dependencies:
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 2.99.0
47
+ version: 3.0.0
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 2.99.0
54
+ version: 3.0.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: pry
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
110
  version: '0'
125
111
  requirements: []
126
112
  rubyforge_project:
127
- rubygems_version: 2.4.5
113
+ rubygems_version: 2.6.8
128
114
  signing_key:
129
115
  specification_version: 4
130
116
  summary: RSpec client for sending test suite results to RaceCondition.