probedock-ruby 0.1.0 → 0.1.1

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: d941395e464c62eab491d4939d4a8a64096cbac6
4
- data.tar.gz: 4e35bc79a67d9f0cf1460ea0f167f5b7061a34a7
3
+ metadata.gz: 23bf815842f4bd1f2c40d19802e6bde6d2343aee
4
+ data.tar.gz: f66d5ae1474538712d06fe75de4e096a462c60d4
5
5
  SHA512:
6
- metadata.gz: e7b22566142e31593d73930d26ef56eefc3f1e491a0deb1f22c5a1960806d07d3e82d2510706fc92f5086dd1fa1eddccb94e89db091525211d2dfb1c05a38998
7
- data.tar.gz: b05d2128a07ae016a8a7616a7651b0fa4d9b1d21d08a8a6ba4cf8c6a057d7da0d486540bd9990090910dbfd4fe7208598ef10480cdb1fc769360f3728a28b8b9
6
+ metadata.gz: 2f95da27dbb3b7bff866d392719e97f5bc07685b3fa5617759a28ca4375551f9c5aef2a929458144eecfb12c384a5c98b31677f45065af866a691e406b0a394a
7
+ data.tar.gz: 5089ff9bfda8ff1755eee59deb59fec0e3d82005d0f37d396544ec2b63a788ea52baf6527e2abe1a5811b534a1373fe6257603aeae590beb1da5888efbc4ab64
data/README.md CHANGED
@@ -17,7 +17,7 @@
17
17
  Add it to your Gemfile:
18
18
 
19
19
  ```rb
20
- gem 'probedock-ruby', '~> 0.1.0'
20
+ gem 'probedock-ruby', '~> 0.1.1'
21
21
  ```
22
22
 
23
23
  Run `bundle install`.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1,3 +1,5 @@
1
+ require 'paint'
2
+
1
3
  module ProbeDockProbe
2
4
 
3
5
  class Client
@@ -41,7 +43,7 @@ module ProbeDockProbe
41
43
 
42
44
  def build_payload test_run, options = {}
43
45
  begin
44
- TestPayload.new(test_run).to_h options
46
+ test_run.to_h options
45
47
  rescue PayloadError => e
46
48
  fail e.message
47
49
  end
@@ -1,20 +1,13 @@
1
1
  require 'yaml'
2
2
 
3
- # Utilities to send test results to Probe Dock.
4
3
  module ProbeDockProbe
5
4
 
6
5
  def self.config
7
- @config ||= Config.new.tap(&:load!)
6
+ @config ||= Config.new
8
7
  end
9
8
 
10
- def self.configure options = {}
11
-
12
- yield config if block_given?
13
-
14
- config.check!
15
- config.load_warnings.each{ |w| warn Paint["Probe Dock - #{w}", :yellow] }
16
-
17
- config
9
+ def self.config= config
10
+ @config = config
18
11
  end
19
12
 
20
13
  class Config
@@ -59,9 +52,9 @@ module ProbeDockProbe
59
52
  @servers.clear
60
53
 
61
54
  @load_warnings = []
62
- return unless config = load_config_files
55
+ config = load_config_files
63
56
 
64
- @publish = parse_env_flag :publish, !!config[:publish]
57
+ @publish = parse_env_flag :publish, config.fetch(:publish, true)
65
58
  @server_name = parse_env_option(:server) || config[:server]
66
59
  @local_mode = parse_env_flag(:local) || !!config[:local]
67
60
 
@@ -87,9 +80,16 @@ module ProbeDockProbe
87
80
  project_options.merge! api_id: @server.project_api_id if @server and @server.project_api_id
88
81
  @project.update project_options
89
82
 
83
+ yield self if block_given?
84
+
85
+ check!
86
+ @load_warnings.each{ |w| warn Paint["Probe Dock - #{w}", :yellow] }
87
+
90
88
  self
91
89
  end
92
90
 
91
+ private
92
+
93
93
  def check!
94
94
 
95
95
  configs = [ home_config_file, working_config_file ]
@@ -106,8 +106,6 @@ module ProbeDockProbe
106
106
  end
107
107
  end
108
108
 
109
- private
110
-
111
109
  def build_servers config
112
110
 
113
111
  default_server_options = { project_api_id: config[:project][:api_id] }
@@ -123,7 +121,7 @@ module ProbeDockProbe
123
121
 
124
122
  configs = [ home_config_file, working_config_file ]
125
123
  actual_configs = configs.select{ |f| File.exists? f }
126
- return false if actual_configs.empty?
124
+ return { servers: [], payload: {}, project: {} } if actual_configs.empty?
127
125
 
128
126
  actual_configs.collect!{ |f| YAML.load_file f }
129
127
 
@@ -1,40 +1,42 @@
1
1
  module ProbeDockProbe
2
2
  class TestResult
3
- attr_reader :key, :name, :category, :tags, :tickets, :data, :duration, :message
4
-
5
- def initialize project, example, groups = [], options = {}
3
+ attr_reader :key, :fingerprint, :name, :category, :tags, :tickets, :data, :duration, :message
4
+
5
+ def initialize project, options = {}
6
+
7
+ if !options[:fingerprint]
8
+ raise Error, "The :fingerprint option is required (unique identifier for the test)"
9
+ elsif !options[:name]
10
+ raise Error, "The :name option is required (human-friendly identifier for the test, not necessarily unique)"
11
+ elsif !options.key?(:passed)
12
+ raise Error, "The :passed option is required (indicates whether the test passed or not)"
13
+ elsif !options[:duration]
14
+ raise Error, "The :duration options is required (indicates how long it took to run the test)"
15
+ end
6
16
 
7
- @category = project.category
8
- @tags = project.tags
9
- @tickets = project.tickets
17
+ @key = options[:key]
18
+ @fingerprint = options[:fingerprint]
19
+ @name = options[:name]
10
20
 
11
- @grouped = extract_grouped example, groups
12
-
13
- [ :key, :name, :category, :tags, :tickets, :data ].each do |attr|
14
- instance_variable_set "@#{attr}".to_sym, send("extract_#{attr}".to_sym, example, groups)
15
- end
21
+ @category = options[:category] || project.category
22
+ @tags = (wrap(options[:tags]) + wrap(project.tags)).compact.collect(&:to_s).uniq
23
+ @tickets = (wrap(options[:tickets]) + wrap(project.tickets)).compact.collect(&:to_s).uniq
16
24
 
17
25
  @passed = !!options[:passed]
18
26
  @duration = options[:duration]
19
27
  @message = options[:message]
28
+
29
+ @data = options[:data] || {}
30
+ @data = @data.deep_stringify_keys if @data.respond_to? :deep_stringify_keys
20
31
  end
21
32
 
22
33
  def passed?
23
34
  @passed
24
35
  end
25
36
 
26
- def grouped?
27
- @grouped
28
- end
29
-
30
- def update options = {}
31
- @passed &&= options[:passed]
32
- @duration += options[:duration]
33
- @message = [ @message, options[:message] ].select{ |m| m }.join("\n\n") if options[:message]
34
- end
35
-
36
37
  def to_h options = {}
37
38
  {
39
+ 'f' => @fingerprint,
38
40
  'p' => @passed,
39
41
  'd' => @duration
40
42
  }.tap do |h|
@@ -48,63 +50,6 @@ module ProbeDockProbe
48
50
  end
49
51
  end
50
52
 
51
- def self.extract_grouped example, groups = []
52
- !!groups.collect{ |g| meta(g)[:grouped] }.compact.last
53
- end
54
-
55
- def self.extract_key example, groups = []
56
- (groups.collect{ |g| meta(g)[:key] } << meta(example)[:key]).compact.reject{ |k| k.strip.empty? }.last
57
- end
58
-
59
- def self.meta holder
60
- meta = holder.metadata[:probe_dock] || {}
61
- if meta.kind_of? String
62
- { key: meta }
63
- elsif meta.kind_of? Hash
64
- meta
65
- else
66
- {}
67
- end
68
- end
69
-
70
- private
71
-
72
- def meta *args
73
- self.class.meta *args
74
- end
75
-
76
- def extract_grouped *args
77
- self.class.extract_grouped *args
78
- end
79
-
80
- def extract_key *args
81
- self.class.extract_key *args
82
- end
83
-
84
- def extract_name example, groups = []
85
- parts = groups.dup
86
- parts = parts[0, parts.index{ |p| meta(p)[:grouped] } + 1] if @grouped
87
- parts << example unless @grouped
88
- parts.collect{ |p| p.description.strip }.join ' '
89
- end
90
-
91
- def extract_category example, groups = []
92
- cat = (groups.collect{ |g| meta(g)[:category] }.unshift(@category) << meta(example)[:category]).compact.last
93
- cat ? cat.to_s : nil
94
- end
95
-
96
- def extract_tags example, groups = []
97
- (wrap(@tags) + groups.collect{ |g| wrap meta(g)[:tags] } + (wrap meta(example)[:tags])).flatten.compact.uniq.collect(&:to_s)
98
- end
99
-
100
- def extract_tickets example, groups = []
101
- (wrap(@tickets) + groups.collect{ |g| wrap meta(g)[:tickets] } + (wrap meta(example)[:tickets])).flatten.compact.uniq.collect(&:to_s)
102
- end
103
-
104
- def extract_data example, groups = []
105
- meta(example)[:data] || {}
106
- end
107
-
108
53
  def wrap a
109
54
  a.kind_of?(Array) ? a : [ a ]
110
55
  end
@@ -9,23 +9,8 @@ module ProbeDockProbe
9
9
  @project = project
10
10
  end
11
11
 
12
- def add_result example, groups = [], options = {}
13
- if TestResult.extract_grouped(example, groups) and (existing_result = @results.find{ |r| r.grouped? && r.key == TestResult.extract_key(example, groups) })
14
- existing_result.update options
15
- else
16
- @results << TestResult.new(@project, example, groups, options)
17
- end
18
- end
19
-
20
- def results_without_key
21
- @results.select{ |r| !r.key or r.key.to_s.strip.empty? }
22
- end
23
-
24
- def results_by_key
25
- @results.inject({}) do |memo,r|
26
- (memo[r.key] ||= []) << r unless !r.key or r.key.to_s.strip.empty?
27
- memo
28
- end
12
+ def add_result options = {}
13
+ @results << TestResult.new(@project, options)
29
14
  end
30
15
 
31
16
  def to_h options = {}
@@ -45,40 +30,9 @@ module ProbeDockProbe
45
30
 
46
31
  def validate!
47
32
  # TODO: validate duration
48
-
33
+ # TODO: log information about duplicate keys (if any)
49
34
  raise PayloadError.new("Missing project") if !@project
50
35
  @project.validate!
51
-
52
- # FIXME: log info/warnings
53
- #validate_no_results_without_key
54
- #validate_no_duplicate_keys
55
- end
56
-
57
- def validate_no_duplicate_keys
58
-
59
- results_with_duplicate_key = results_by_key.select{ |k,r| r.length >= 2 }
60
- return if results_with_duplicate_key.none?
61
-
62
- msg = "the following keys are used by multiple test results".tap do |s|
63
- results_with_duplicate_key.each_pair do |key,results|
64
- s << "\n - #{key}"
65
- results.each{ |r| s << "\n - #{r.name}" }
66
- end
67
- end
68
-
69
- raise PayloadError.new(msg)
70
- end
71
-
72
- def validate_no_results_without_key
73
-
74
- keyless = results_without_key
75
- return if keyless.empty?
76
-
77
- msg = "the following test results are missing a key".tap do |s|
78
- keyless.each{ |r| s << "\n - #{r.name}" }
79
- end
80
-
81
- raise PayloadError.new(msg)
82
36
  end
83
37
  end
84
38
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  module ProbeDockProbe
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
 
5
5
  class Error < StandardError; end
6
6
  class PayloadError < Error; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: probedock-ruby
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-27 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -198,7 +198,6 @@ files:
198
198
  - lib/probe_dock_ruby/project.rb
199
199
  - lib/probe_dock_ruby/server.rb
200
200
  - lib/probe_dock_ruby/tasks.rb
201
- - lib/probe_dock_ruby/test_payload.rb
202
201
  - lib/probe_dock_ruby/test_result.rb
203
202
  - lib/probe_dock_ruby/test_run.rb
204
203
  - lib/probe_dock_ruby/uid.rb
@@ -1,18 +0,0 @@
1
- require 'fileutils'
2
- require 'digest/sha2'
3
-
4
- module ProbeDockProbe
5
-
6
- class TestPayload
7
-
8
- class Error < ProbeDockProbe::Error; end
9
-
10
- def initialize run
11
- @run = run
12
- end
13
-
14
- def to_h options = {}
15
- @run.to_h options
16
- end
17
- end
18
- end