kapnismology 1.0.0 → 1.1.0

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: d27de09be6c9595f860e7054e7a87d8424c616e7
4
- data.tar.gz: 0ddb6a39122a5ff180f1aae24f9d407eef5d02eb
3
+ metadata.gz: 8828ed5a2b362b08e49a35a5b5f5f1ecf583d0c3
4
+ data.tar.gz: 524fb01922fd668ea33d89e421732bac4c324118
5
5
  SHA512:
6
- metadata.gz: d7014adec5ead6a8002bc58a34bc021e6f81da4c8fbb3aecb3a9e1ec2ff3280fd44114ed856d69bf0a322d701cde632368f87191211957a8dbcc69c8db64c822
7
- data.tar.gz: 8c873c5b0387c083269a05b4a7c0e472daaeb881af725ab5aea8bfdb73650393ada8f698b375a6e5be33989805dac4854bca689adba890657b091271f156c735
6
+ metadata.gz: f3e9a12ffb0fce5deffe02ee606d9c8379ce5cb36d8a956a70881c6cb1549e505a958d6e4d5b4c17e0ecb2f0b680dba5a257d5adfd512fb731079195a851f37a
7
+ data.tar.gz: ca3c6fd0ead670fe51c1dafb80fd98787d515c5419f103ca1b6672e7dfddd30d79f4d4b74db799b46e7e4d564cf8723a18e05639f80838cb2ec166239925cc4d
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.2'
10
+ gem 'kapnismology', '~> 1.1'
11
11
  ```
12
12
 
13
13
  In your config/routes write:
@@ -43,9 +43,51 @@ In this case the result of this class would be added to the result as:
43
43
  {'MySmokeTest': { passed: true, data: { connection: 'good' }, message: 'Connected!' }}
44
44
  ```
45
45
 
46
- If you want to change the name of the test, define self.name in your
46
+ ## Naming
47
+
48
+ If you want to change the name of the test, define `self.name` in your
47
49
  smoke test class.
48
50
 
51
+
52
+ ## Tagging and running tags
53
+
54
+ All smoke tests are tagged by default with 'deployment' and 'runtime'.
55
+ If you want to tag your test with any one of the above or any other tag, just overwrite the `self.categories` method in your smoke test class.
56
+ The following example creates a smoke test tagged with the tags 'slow' and 'integration'.
57
+
58
+ ```Ruby
59
+ class ExpensiveTest < Kapnismology::SmokeTest
60
+ def result
61
+ end
62
+ def self.categories
63
+ ['slow', 'integration']
64
+ end
65
+ end
66
+ ```
67
+
68
+ When you call the URL, all smoke tests marked with 'runtime' will be run. As by default all smoke test have the tags 'deployment' and 'runtime' they will all be run.
69
+
70
+ The above smoke test as it has not the 'runtime' category, it will not be run. To run it you should call your service like this:
71
+ ```
72
+ wget http://myservice.com/smoke_test?tags=integration_
73
+ ```
74
+
75
+ It will run all your integration tests. You can run it together with your runtime tests also:
76
+ ```
77
+ wget http://myservice.com/smoke_test?tags=integration,runtime
78
+ ```
79
+
80
+
81
+ ## Skipping tests
82
+
83
+ If you want to skip some smoke test when you call the URL then you can add the 'skip' query parameter to the URL indicating the tests you want to skip.
84
+ For instance:
85
+ ```
86
+ wget http://myservice.com/smoke_test?skip=ToNotBeCalled,NeitherCallThis_
87
+ ```
88
+
89
+
90
+
49
91
  ## TODO
50
92
 
51
93
  - Automount routes
data/Rakefile CHANGED
@@ -14,11 +14,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
17
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
18
18
  load 'rails/tasks/engine.rake'
19
19
 
20
-
21
-
22
20
  Bundler::GemHelper.install_tasks
23
21
 
24
22
  require 'rake/testtask'
@@ -30,5 +28,4 @@ Rake::TestTask.new(:test) do |t|
30
28
  t.verbose = false
31
29
  end
32
30
 
33
-
34
31
  task default: :test
@@ -1,11 +1,22 @@
1
1
  module Kapnismology
2
+ # This is called when the user goes to the /smoke_test URL. This calls all the
3
+ # smoke tests registered in the application and gather the results
2
4
  class SmokeTestsController < ApplicationController
3
5
  def index
4
- evaluations = SmokeTest.evaluations
6
+ evaluations = SmokeTest.evaluations(allowed_tags, blacklist)
5
7
  render text: evaluations.to_json, status: status(evaluations)
6
8
  end
7
9
 
8
10
  private
11
+
12
+ def allowed_tags
13
+ params[:tags] ? params[:tags].split(',') : [SmokeTest::RUNTIME_TAG]
14
+ end
15
+
16
+ def blacklist
17
+ params[:skip].to_s.split(',')
18
+ end
19
+
9
20
  def status(evaluations)
10
21
  if evaluations.passed?
11
22
  :ok
@@ -1,24 +1,28 @@
1
+ # Rails support, this may need changes if Rails change internals
1
2
  module Kapnismology
2
- begin
3
- class Engine < ::Rails::Engine
4
- initializer "kapnismology.add_autoload_paths", before: :set_autoload_paths do |app|
5
- app.config.eager_load_paths += Dir["#{app.config.root}/lib/**/*"]
6
- end
3
+ begin
4
+ # Rails engine to automatically load our code and smoke tests libraries
5
+ class Engine < ::Rails::Engine
6
+ initializer 'kapnismology.add_autoload_paths', before: :set_autoload_paths do |app|
7
+ app.config.eager_load_paths += Dir["#{app.config.root}/lib/**/*"]
8
+ end
7
9
 
8
- isolate_namespace Kapnismology
9
- end
10
+ isolate_namespace Kapnismology
11
+ end
10
12
 
11
- class Routes
12
- def self.insert!(path)
13
- if defined?(Kapnismology) == false
14
- raise 'require kapnismology before trying to insert routes'
15
- end
16
- Rails.application.routes.draw do
17
- mount Kapnismology::Engine, at: path
13
+ # Inserts the engine (the smoketest_controller) into a given path.
14
+ # TODO: how to automatically do this without the user needing to insert?
15
+ class Routes
16
+ def self.insert!(path)
17
+ if defined?(Kapnismology) == false
18
+ raise 'require kapnismology before trying to insert routes'
19
+ end
20
+ Rails.application.routes.draw do
21
+ mount Kapnismology::Engine, at: path
22
+ end
18
23
  end
19
24
  end
25
+ rescue NameError => e
26
+ puts "Incompatible Rails version #{e}"
20
27
  end
21
- rescue NameError => e
22
- puts "Incompatible Rails version #{e}"
23
28
  end
24
- end
@@ -1,11 +1,10 @@
1
1
  require 'json'
2
2
 
3
3
  module Kapnismology
4
-
5
4
  # Mapping of test_name => result for each smoke test
6
5
  class Evaluation
7
6
  def initialize(test_class)
8
- @name = test_class.name.split("::").last
7
+ @name = test_class.name.split('::').last
9
8
  @result = test_class.new.result || unavailable_result
10
9
  end
11
10
 
@@ -24,11 +23,11 @@ module Kapnismology
24
23
  private
25
24
 
26
25
  def unavailable_result
27
- Result.new(false, {}, "This test has not returned any result.")
26
+ Result.new(false, {}, 'This test has not returned any result.')
28
27
  end
29
28
 
30
29
  def passed_or_failed_text
31
- passed? ? "passed" : "failed"
30
+ passed? ? 'passed' : 'failed'
32
31
  end
33
32
  end
34
- end
33
+ end
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
 
3
3
  module Kapnismology
4
+ # A collection of the results of the smoke tests
4
5
  class EvaluationCollection
5
6
  include Enumerable
6
7
 
@@ -8,14 +9,14 @@ module Kapnismology
8
9
  @smoke_tests_classes = test_classes
9
10
  end
10
11
 
11
- def each(&block)
12
+ def each(&_block)
12
13
  evaluations.each do |member|
13
- block.call(member)
14
+ yield(member)
14
15
  end
15
16
  end
16
17
 
17
18
  def passed?
18
- evaluations.all?{|evaluation| evaluation.passed?}
19
+ evaluations.all?(&:passed?)
19
20
  end
20
21
 
21
22
  def to_json
@@ -30,5 +31,4 @@ module Kapnismology
30
31
  end
31
32
  end
32
33
  end
33
-
34
34
  end
@@ -6,7 +6,7 @@ module Kapnismology
6
6
  puts evaluation.to_s
7
7
  puts
8
8
  end
9
- fail 'We have some failures in our smoke tests' unless evaluations.passed?
9
+ raise 'We have some failures in our smoke tests' unless evaluations.passed?
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -1,17 +1,18 @@
1
1
  module Kapnismology
2
-
3
2
  # This is the result of each smoke test.
4
3
  # This class makes sense to enforce smoke test to return something known
5
4
  # Params of the constructor:
6
5
  # * passed : Boolean: true -> test passed, false -> test failed
7
6
  # * 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
7
+ # * message: String with an extra message to provide human readable information
9
8
  class Result
10
9
  attr_reader :data, :message
11
10
 
12
11
  def initialize(passed, data, message)
13
- raise ArgumentError, "passed must be true or false" unless !!passed == passed
14
- @passed, @data, @message = passed, data, message
12
+ raise ArgumentError, 'passed must be true or false' unless !!passed == passed
13
+ @passed = passed
14
+ @data = data
15
+ @message = message
15
16
  end
16
17
 
17
18
  def passed?
@@ -19,7 +20,7 @@ module Kapnismology
19
20
  end
20
21
 
21
22
  def to_hash
22
- {passed: passed?, data: @data, message: @message}
23
+ { passed: passed?, data: @data, message: @message }
23
24
  end
24
25
  end
25
26
  end
@@ -1,18 +1,19 @@
1
1
 
2
2
  module Kapnismology
3
-
4
3
  #
5
4
  # This is the base class for all the smoke tests.
6
5
  # Inherit from this class and implement the result and self.name method
7
6
  #
8
7
  class SmokeTest
8
+ DEPLOYMENT_TAG = 'deployment'.freeze
9
+ RUNTIME_TAG = 'runtime'.freeze
10
+ DEFAULT_TAGS = [DEPLOYMENT_TAG, RUNTIME_TAG].freeze
9
11
 
10
12
  def result
11
13
  raise 'this method has to be implemented in inherited classes'
12
14
  end
13
15
 
14
16
  class << self
15
-
16
17
  def inherited(klass)
17
18
  smoke_tests << klass
18
19
  end
@@ -21,10 +22,20 @@ module Kapnismology
21
22
  @smoke_tests ||= []
22
23
  end
23
24
 
24
- def evaluations
25
- EvaluationCollection.new(smoke_tests)
25
+ def evaluations(allowed_tags, blacklist)
26
+ # We will run any class which categories are in the allowed list
27
+ # and not blacklisted
28
+ runable_tests = smoke_tests.select do |test|
29
+ klass_name = test.name.split('::').last
30
+ !blacklist.include?(klass_name) &&
31
+ !(allowed_tags & test.tags).empty?
32
+ end
33
+ EvaluationCollection.new(runable_tests)
26
34
  end
27
- end
28
35
 
36
+ def tags
37
+ DEFAULT_TAGS
38
+ end
39
+ end
29
40
  end
30
- end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Kapnismology
2
- VERSION = "1.0.0"
2
+ VERSION = '1.1.0'.freeze
3
3
  end
data/lib/kapnismology.rb CHANGED
@@ -1,7 +1,5 @@
1
- #Engines blow up when being autoloaded by Rails and at the same time loaded by other gems
2
- unless defined?(Kapnismology::Engine)
3
- require "kapnismology/engine"
4
- end
1
+ # Engines blow up when being autoloaded by Rails and at the same time loaded by other gems
2
+ require 'kapnismology/engine' unless defined?(Kapnismology::Engine)
5
3
  require 'kapnismology/result'
6
4
  require 'kapnismology/evaluation'
7
5
  require 'kapnismology/evaluation_collection'
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.0.0
4
+ version: 1.1.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-02-11 00:00:00.000000000 Z
11
+ date: 2016-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -182,9 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.2.2
185
+ rubygems_version: 2.5.1
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Engine for smoke tests.
189
189
  test_files: []
190
- has_rdoc: