kapnismology 1.8.2 → 1.9.0

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: 55ff0fd8235f398c2d5228907fcc22cd4ed67329
4
- data.tar.gz: 97c555355873882b3b089c2371548c70d2a9530b
3
+ metadata.gz: dbd621f0387cf288bfa32a43784b7ba92b020f6e
4
+ data.tar.gz: 6a1c5b6146fe86811c77a9aad9fb3adc9b88b5b9
5
5
  SHA512:
6
- metadata.gz: ef567cd772e4660eedab61a8c23d7cf15ea4e6a86bf1966faee6cdbff5d180e5d6740371a212cb733198b9342e2305798b71f6008c88ea38567848dcd86be313
7
- data.tar.gz: 69c992fbc2e8403e7aa86bc341e1b18fe743cbc3646efc6478ee73141c07ae1d50f829d8904d5ccbece9e472d6be594c17ea9fef2fc7ccf21b53e520c87b8db0
6
+ metadata.gz: 13d340c969350eba069680e6b8bcb8a9327ce05c63b31fc366f52c31de57aaf588ba95c038672a358c8d0748dc6dbc3680522332efa9218a4bd1c81091c6c294
7
+ data.tar.gz: c7c5f8096788f20db177cb30b7f4902f87c8d8879534a7553b57d36e1376c2442d973d439f434b3d1bc6c47f23b26ecb9a2b634eb6f7183efecdcaf243a003d3
data/README.md CHANGED
@@ -151,12 +151,13 @@ end
151
151
  def user_from_remote
152
152
  get_user
153
153
  rescue => e
154
- raise SmokeTestFailed.new({class: e.class, message: e.message}, "Error raised when accessing user")
154
+ raise SmokeTestFailed.new(e, "Error raised when accessing user")
155
155
  end
156
156
  ...
157
157
  ```
158
158
 
159
159
  Using small methods that raise SmokeTestFailed when failed will help you write an easy to read `result` method.
160
+ You can pass your own data to SmokeTestFailed or you can pass an exception which will be properly formatted.
160
161
 
161
162
 
162
163
  ## Testing
@@ -4,7 +4,7 @@ module Kapnismology
4
4
  class SmokeTestsController < ApplicationController
5
5
  def index
6
6
  evaluations = SmokeTestCollection.evaluations(allowed_tags, blacklist)
7
- render text: evaluations.to_json, status: status(evaluations)
7
+ render json: evaluations.to_json, status: status(evaluations)
8
8
  end
9
9
 
10
10
  private
@@ -13,10 +13,6 @@ module Kapnismology
13
13
  @result.passed?
14
14
  end
15
15
 
16
- def null_result?
17
- @result.is_a?(NullResult)
18
- end
19
-
20
16
  def as_json(_options = nil)
21
17
  { @name => @result.to_hash }
22
18
  end
@@ -1,7 +1,7 @@
1
1
  require 'json'
2
2
 
3
3
  module Kapnismology
4
- # A collection of the results of the smoke tests
4
+ # A collection of the evaluations of the smoke tests
5
5
  class EvaluationCollection
6
6
  include Enumerable
7
7
 
@@ -20,7 +20,7 @@ module Kapnismology
20
20
  end
21
21
 
22
22
  def to_json
23
- evaluations.delete_if(&:null_result?).to_json
23
+ evaluations.to_json
24
24
  end
25
25
 
26
26
  private
@@ -48,7 +48,7 @@ eos
48
48
  # * message: String with an extra message to provide human readable information
49
49
  class Result < BaseResult
50
50
  def initialize(passed, data, message)
51
- raise ArgumentError, 'passed must be true or false' unless !!passed == passed
51
+ raise ArgumentError, 'passed argument must be true or false' unless !!passed == passed
52
52
  @passed = passed
53
53
  @data = data
54
54
  @message = message
@@ -56,6 +56,8 @@ eos
56
56
  end
57
57
  end
58
58
 
59
+ # This class can be returned when a check do not want to return an assertion on if
60
+ # it passed or not.
59
61
  class NullResult < BaseResult
60
62
  def initialize(data, message = 'The result could not be determined')
61
63
  @passed = true
@@ -63,6 +65,20 @@ eos
63
65
  @message = message
64
66
  @extra_messages = []
65
67
  end
68
+
69
+ # Redefining to have our own unique output
70
+ def to_hash
71
+ { data: @data, message: @message, extra_messages: @extra_messages }
72
+ end
73
+
74
+ # Redefining for unique output
75
+ def to_s(name)
76
+ <<-eos
77
+ #{Terminal.yellow('Skipped')}: #{name}
78
+ #{format_extra_messages(@extra_messages)}#{Terminal.bold(@message)}
79
+ #{@data}
80
+ eos
81
+ end
66
82
  end
67
83
 
68
84
  # Use this class when your test is not valid in the current situation
@@ -1,19 +1,8 @@
1
1
  require 'kapnismology/result'
2
2
  require 'kapnismology/smoke_test_collection'
3
+ require 'kapnismology/smoke_test_failed'
3
4
 
4
5
  module Kapnismology
5
-
6
- # This class can be raised to make Kapnismology create a failed result from your smoke test
7
- class SmokeTestFailed < StandardError
8
- def initialize(data, message)
9
- @data = data
10
- @message = message
11
- end
12
-
13
- def result
14
- Kapnismology::Result.new(false, @data, @message)
15
- end
16
- end
17
6
  #
18
7
  # This is the base class for all the smoke tests.
19
8
  # Inherit from this class and implement the result and self.name method
@@ -31,9 +20,10 @@ module Kapnismology
31
20
  def result
32
21
  end
33
22
 
23
+ # Internally Kapnismology is calling this method. We are handling exceptions under the hood herer
34
24
  def __result__
35
25
  result_object = result
36
- unless result_object.is_a?(Kapnismology::BaseResult)
26
+ unless result_object.class.ancestors.include?(Kapnismology::BaseResult)
37
27
  message = "Smoke test #{self.class}, returned #{result_object.class} instead of a Result"
38
28
  result_object = Result.new(false, { returned_class: result_object.class }, message)
39
29
  end
@@ -0,0 +1,18 @@
1
+ module Kapnismology
2
+
3
+ # This class can be raised to make Kapnismology create a failed result from your smoke test
4
+ class SmokeTestFailed < StandardError
5
+ def initialize(data, message)
6
+ @data = if data.class.ancestors.include?(Exception)
7
+ { exception: data.class, message: data.message }
8
+ else
9
+ data
10
+ end
11
+ @message = message
12
+ end
13
+
14
+ def result
15
+ Kapnismology::Result.new(false, @data, @message)
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,6 @@
1
1
  module Kapnismology
2
2
  class Terminal
3
+
3
4
  def self.green(msg)
4
5
  "\e[32m\e[1m#{msg}\e[0m"
5
6
  end
@@ -8,6 +9,10 @@ module Kapnismology
8
9
  "\e[31m\e[1m#{msg}\e[0m"
9
10
  end
10
11
 
12
+ def self.yellow(msg)
13
+ "\e[33m\e[1m#{msg}\e[0m"
14
+ end
15
+
11
16
  def self.bold(msg)
12
17
  "\e[1m#{msg}\e[0m"
13
18
  end
@@ -1,3 +1,3 @@
1
1
  module Kapnismology
2
- VERSION = '1.8.2'.freeze
2
+ VERSION = '1.9.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kapnismology
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordi Polo Carres
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-07 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -155,6 +155,7 @@ files:
155
155
  - lib/kapnismology/result.rb
156
156
  - lib/kapnismology/smoke_test.rb
157
157
  - lib/kapnismology/smoke_test_collection.rb
158
+ - lib/kapnismology/smoke_test_failed.rb
158
159
  - lib/kapnismology/spec_helper.rb
159
160
  - lib/kapnismology/terminal.rb
160
161
  - lib/kapnismology/version.rb