kapnismology 0.1.2 → 1.0.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: 9f774766ca0fb68f1ce0dbb2f81581654a002a8d
4
- data.tar.gz: 883937951485cfd3fbb1d3b20da6e29ccb879d5d
3
+ metadata.gz: d27de09be6c9595f860e7054e7a87d8424c616e7
4
+ data.tar.gz: 0ddb6a39122a5ff180f1aae24f9d407eef5d02eb
5
5
  SHA512:
6
- metadata.gz: 28f921c8f93814503aa67f119bb9880acc09afc41a74a2397f4dca40b7235815a3a63888edea896aa48d7db7f7dcd262e7bc4fcbcb4d2d336c9267217cb11e17
7
- data.tar.gz: 147495374e5821784b739413893f1dc569635669c8acb27f9a10e822f0fcc7ffd86a477e734c27bbd92a4b70ae5a293c9046b54a23de8c4a81f425a3dcc957d2
6
+ metadata.gz: d7014adec5ead6a8002bc58a34bc021e6f81da4c8fbb3aecb3a9e1ec2ff3280fd44114ed856d69bf0a322d701cde632368f87191211957a8dbcc69c8db64c822
7
+ data.tar.gz: 8c873c5b0387c083269a05b4a7c0e472daaeb881af725ab5aea8bfdb73650393ada8f698b375a6e5be33989805dac4854bca689adba890657b091271f156c735
data/README.md CHANGED
@@ -7,7 +7,7 @@ Kapnismology 'the study of smoke', is a gem which contains an engine to easily c
7
7
  Kapnismology only supports Rails.
8
8
  In the Gemfile write:
9
9
  ```
10
- gem 'kapnismology', '~> 0.1'
10
+ gem 'kapnismology', '~> 0.2'
11
11
  ```
12
12
 
13
13
  In your config/routes write:
@@ -27,29 +27,26 @@ Create a class like this:
27
27
  ```
28
28
  class MySmokeTest < Kapnismology::SmokeTest
29
29
 
30
- def self.name
31
- 'my_test'
32
- end
33
-
34
30
  def result
35
- "BOOO"
31
+ Kapnismology::Result.new(true, {connection: 'good'}, "Connected!")
36
32
  end
37
33
  end
38
34
  ```
39
35
 
40
36
  The class must:
41
37
  - Inherit from `Kapnismology::SmokeTest`
42
- - Have a method `self.name` returning a string
43
38
  - Have an instance method `result` returning a Kapnismology::Result object
44
39
 
45
40
  Any class created this way will be called and its result will be added to a resulting hash.
46
41
  In this case the result of this class would be added to the result as:
47
42
  ```
48
- {'my_test' => 'BOOO'}
43
+ {'MySmokeTest': { passed: true, data: { connection: 'good' }, message: 'Connected!' }}
49
44
  ```
50
45
 
46
+ If you want to change the name of the test, define self.name in your
47
+ smoke test class.
48
+
51
49
  ## TODO
52
50
 
53
- - rspecs
54
51
  - Automount routes
55
52
  - Hypermedia output
@@ -4,16 +4,31 @@ module Kapnismology
4
4
 
5
5
  # Mapping of test_name => result for each smoke test
6
6
  class Evaluation
7
- extend Forwardable
8
- attr_reader :test_name
9
- def_delegators :@result, :data, :passed, :message
7
+ def initialize(test_class)
8
+ @name = test_class.name.split("::").last
9
+ @result = test_class.new.result || unavailable_result
10
+ end
11
+
12
+ def passed?
13
+ @result.passed?
14
+ end
15
+
16
+ def as_json(_options = nil)
17
+ { @name => @result.to_hash }
18
+ end
19
+
20
+ def to_s
21
+ "The smoke test #{@name} #{passed_or_failed_text}\n #{@result.message}"
22
+ end
23
+
24
+ private
10
25
 
11
- def initialize(test_name, result)
12
- @test_name, @result = test_name, result
26
+ def unavailable_result
27
+ Result.new(false, {}, "This test has not returned any result.")
13
28
  end
14
29
 
15
- def to_json(_options = nil)
16
- {test_name => @result.to_hash}.to_json
30
+ def passed_or_failed_text
31
+ passed? ? "passed" : "failed"
17
32
  end
18
33
  end
19
34
  end
@@ -4,8 +4,8 @@ module Kapnismology
4
4
  class EvaluationCollection
5
5
  include Enumerable
6
6
 
7
- def initialize(smoke_tests)
8
- @smoke_tests = smoke_tests
7
+ def initialize(test_classes)
8
+ @smoke_tests_classes = test_classes
9
9
  end
10
10
 
11
11
  def each(&block)
@@ -15,7 +15,7 @@ module Kapnismology
15
15
  end
16
16
 
17
17
  def passed?
18
- evaluations.all?{|evaluation| evaluation.passed}
18
+ evaluations.all?{|evaluation| evaluation.passed?}
19
19
  end
20
20
 
21
21
  def to_json
@@ -25,10 +25,9 @@ module Kapnismology
25
25
  private
26
26
 
27
27
  def evaluations
28
- @evaluations ||= @smoke_tests.map do |smoke_test|
29
- result = smoke_test.new.result
30
- Evaluation.new(smoke_test.name, result) if result
31
- end.compact
28
+ @evaluations ||= @smoke_tests_classes.map do |klass|
29
+ Evaluation.new(klass)
30
+ end
32
31
  end
33
32
  end
34
33
 
@@ -3,15 +3,10 @@ module Kapnismology
3
3
  def output
4
4
  evaluations = SmokeTest.evaluations
5
5
  evaluations.each do |evaluation|
6
- puts "The smoke test #{evaluation.test_name} #{passed_or_failed(evaluation.passed)}"
7
- puts evaluation.message
6
+ puts evaluation.to_s
8
7
  puts
9
8
  end
10
9
  fail 'We have some failures in our smoke tests' unless evaluations.passed?
11
10
  end
12
-
13
- def passed_or_failed(passed)
14
- passed ? "passed" : "failed"
15
- end
16
11
  end
17
12
  end
@@ -3,18 +3,23 @@ module Kapnismology
3
3
  # This is the result of each smoke test.
4
4
  # This class makes sense to enforce smoke test to return something known
5
5
  # Params of the constructor:
6
- # * data : Typically Array or Hash representing the result of the test
7
6
  # * passed : Boolean: true -> test passed, false -> test failed
8
- # * message: String: extra message set by the test if it wants to provide more information
7
+ # * data : Typically Array or Hash representing the result of the test
8
+ # * message: String with an extra message set by the test to provide human readable information
9
9
  class Result
10
- attr_reader :data, :passed, :message
10
+ attr_reader :data, :message
11
+
12
+ def initialize(passed, data, message)
13
+ raise ArgumentError, "passed must be true or false" unless !!passed == passed
14
+ @passed, @data, @message = passed, data, message
15
+ end
11
16
 
12
- def initialize(data, passed, message)
13
- @data, @passed, @message = data, passed, message
17
+ def passed?
18
+ !!@passed
14
19
  end
15
20
 
16
21
  def to_hash
17
- {result: @data, passed: @passed, message: @message}
22
+ {passed: passed?, data: @data, message: @message}
18
23
  end
19
24
  end
20
- end
25
+ end
@@ -11,10 +11,6 @@ module Kapnismology
11
11
  raise 'this method has to be implemented in inherited classes'
12
12
  end
13
13
 
14
- def self.name
15
- raise 'this method has to be implemented in inherited classes'
16
- end
17
-
18
14
  class << self
19
15
 
20
16
  def inherited(klass)
@@ -1,3 +1,3 @@
1
1
  module Kapnismology
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
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: 0.1.2
4
+ version: 1.0.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: 2015-09-27 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '6.0'
53
+ version: '8.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '6.0'
60
+ version: '8.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: mutant
63
63
  requirement: !ruby/object:Gem::Requirement