jackal 0.3.12 → 0.3.14

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: 02001e5b2ff6b59d1031f8121657bcb1e7ed5ee7
4
- data.tar.gz: 0392d96103ada117ed0d36efb82aa8bb4c1033c2
3
+ metadata.gz: 7253602def38f284c8ad696165795a312490d5dd
4
+ data.tar.gz: 596d502a71246dc3c4534899841e1e63dc4f982d
5
5
  SHA512:
6
- metadata.gz: 6eeb8f2de5be35b540209a3a366ffbf7c3668b5df73dd123509549ca7be26ee8b9a3577a80b65499cd23d81a25ea679b5ecd54cfd28e9e8b9757ff692be0afc7
7
- data.tar.gz: 23cf4aa6b4966daa6b4329e5d88c03aeaa2ec16b25da321da68a579bb4fb59905784b10316c8f7f908dd5431fef7ba47599d21f82b3b6723c430e19d3faf2bf4
6
+ metadata.gz: bac6c34c10109837b87bb9debc3490cb301cee1c5fb0bbab4434fb0a039ff93c021d82e6dcf79961aac09f0e8d2d9d83c648a6edcc76f094b7e8440f35e0ed6e
7
+ data.tar.gz: 2ff2bb0ff8927e174f008dd36ecd141191a94f7f7f73958e3fe3d5e0567d9b505a8882c817d14c5395951fe7c9d726bbe872d7679dd8c7bd322636c306034700
@@ -1,3 +1,7 @@
1
+ # v0.3.14
2
+ * Add test scaffold generator
3
+ * Update carnivore constraint
4
+
1
5
  # v0.3.12
2
6
  * Set default verbosity to :info
3
7
  * Support changing spec runner
@@ -2,4 +2,26 @@
2
2
  # -*- mode: ruby -*-
3
3
  # -*- encoding: utf-8 -*-
4
4
 
5
- require 'jackal/utils/spec/loader'
5
+ require 'bogo-cli'
6
+ require 'jackal'
7
+
8
+ # This conditional is necessary since the cli parsing has a no-arg
9
+ # default of printing the help menu (not able to override the default)
10
+ if ARGV.empty?
11
+ require 'jackal/utils/spec/loader'
12
+ else
13
+ Bogo::Cli::Setup.define do
14
+ global_opts = lambda do
15
+ on :s, 'service-name=', 'Service to test (Eg: Jackal::Mail::Smtp - mail)', :required => true
16
+ on :m, 'module-name=', 'Module to test (Eg: Jackal::Mail::Smtp - smtp)', :required => true
17
+ end
18
+
19
+ command 'generate' do
20
+ description 'Generate test boilerplate for jackal-test'
21
+ self.instance_exec(&global_opts)
22
+ run do |opts, args|
23
+ Jackal::Utils::Spec::Generator.new(opts.to_h, args).execute!
24
+ end
25
+ end
26
+ end
27
+ end
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.description = 'Message processing helper'
11
11
  s.require_path = 'lib'
12
12
  s.license = 'Apache 2.0'
13
- s.add_dependency 'carnivore', '>= 0.3.12', '< 1.0.0'
13
+ s.add_dependency 'carnivore', '>= 0.3.14', '< 1.0.0'
14
14
  s.add_dependency 'bogo', '>= 0.1.24', '< 1.0.0'
15
15
  s.add_dependency 'bogo-cli', '~> 0.1'
16
16
  s.add_dependency 'bogo-config', '>= 0.1.12', '< 1.0.0'
@@ -5,6 +5,7 @@ module Jackal
5
5
  # Testing helpers
6
6
  module Spec
7
7
  autoload :CallbackLocal, 'jackal/utils/spec/callback_local'
8
+ autoload :Generator, 'jackal/utils/spec/generator'
8
9
 
9
10
  class << self
10
11
 
@@ -0,0 +1,185 @@
1
+ require 'bogo-cli'
2
+ require 'fileutils'
3
+ require 'jackal'
4
+
5
+ module Jackal
6
+ module Utils
7
+ module Spec
8
+ # Test files generator
9
+ class Generator < Bogo::Cli::Command
10
+
11
+ # Test directory path
12
+ TEST_DIR = 'test/specs'
13
+ # Test configuration directory path
14
+ TEST_CONFIG_DIR = 'test/specs/config'
15
+ # Lines required within Gemfile
16
+ GEMFILE_LINES = [
17
+ "gem 'carnivore-actor'",
18
+ "gem 'minitest'",
19
+ "gem 'pry'"
20
+ ]
21
+
22
+ # Create new instance
23
+ #
24
+ # @return [self]
25
+ def initialize(*_)
26
+ super
27
+
28
+ @orig_service_name = options[:service_name].downcase
29
+ @service_name = Bogo::Utility.snake(@orig_service_name)
30
+ @service_class_name = Bogo::Utility.camel(@service_name)
31
+
32
+ @module_name = options[:module_name].downcase
33
+ @module_class_name = Bogo::Utility.camel(@module_name)
34
+
35
+ @callback_type = 'jackal'
36
+ @supervisor_name = "jackal_#{@service_name}_input"
37
+ end
38
+
39
+ # Generate test files
40
+ #
41
+ # @return [TrueClass]
42
+ def execute!
43
+ ui.info 'Generating jackal test files'
44
+
45
+ # ensure dependencies are present in Gemfile
46
+ run_action 'Update Gemfile contents' do
47
+ update_gemfile
48
+ nil
49
+ end
50
+
51
+ run_action 'Create testing directory structure' do
52
+ # Create test directory structure
53
+ [TEST_DIR, TEST_CONFIG_DIR].each do |dir|
54
+ FileUtils.mkdir_p(dir)
55
+ end
56
+ nil
57
+ end
58
+
59
+ run_action 'Write test configuration file' do
60
+ conf_path = File.join(Dir.pwd, TEST_CONFIG_DIR, "#{@module_name}.rb")
61
+ write_file(conf_path, config_file_content)
62
+ nil
63
+ end
64
+
65
+ run_action 'Write default test spec file' do
66
+ spec_path = File.join(Dir.pwd, TEST_DIR, "#{@service_name}_spec.rb")
67
+ write_file(spec_path, spec_file_content)
68
+ nil
69
+ end
70
+
71
+ ui.info 'Jackal test file generation complete!'
72
+ true
73
+ end
74
+
75
+ # Configuration file content
76
+ #
77
+ # @return [String]
78
+ def config_file_content
79
+ <<-TEXT
80
+ Configuration.new do
81
+ jackal do
82
+ require ["carnivore-actor", "jackal-#{@orig_service_name}"]
83
+
84
+ mail do
85
+ config do
86
+ end
87
+
88
+ sources do
89
+ input { type 'actor' }
90
+ output { type 'spec' }
91
+ end
92
+
93
+ callbacks ['Jackal::#{@service_class_name}::#{@module_class_name}']
94
+ end
95
+ end
96
+ end
97
+ TEXT
98
+ end
99
+
100
+ # Spec file content
101
+ #
102
+ # @return [String]
103
+ def spec_file_content
104
+ <<TEXT
105
+ require '#{@callback_type}-#{@orig_service_name}'
106
+ require 'pry'
107
+
108
+ # To stub out an api call for your callback
109
+ class #{callback_class}::#{@service_class_name}::#{@module_class_name}
110
+ attr_accessor :test_payload
111
+
112
+ #def api_call(args)
113
+ # test_payload.set(:args, args)
114
+ #end
115
+ end
116
+
117
+ describe #{callback_class}::#{@service_class_name}::#{@module_class_name} do
118
+
119
+ before do
120
+ @runner = run_setup(:#{@module_name})
121
+ track_execution(#{callback_class}::#{@service_class_name}::#{@module_class_name})
122
+ end
123
+
124
+ after do
125
+ @runner.terminate
126
+ end
127
+
128
+ let(:actor) { Carnivore::Supervisor.supervisor[:#{@supervisor_name}] }
129
+
130
+ it 'executes with empty payload' do
131
+ result = transmit_and_wait(actor, payload)
132
+ (!!result).must_equal true
133
+ callback_executed?(result).must_equal true
134
+ end
135
+
136
+ private
137
+
138
+ # payload to send for callback execution
139
+ def payload
140
+ Jackal::Utils.new_payload(:test, Smash.new)
141
+ end
142
+
143
+ end
144
+ TEXT
145
+ end
146
+
147
+ private
148
+
149
+ # @return [String] callback class name
150
+ def callback_class
151
+ @callback_class ||= Bogo::Utility.camel(@callback_type)
152
+ end
153
+
154
+ # Update the contents of the Gemfile with required items
155
+ #
156
+ # @return [TrueClass]
157
+ def update_gemfile
158
+ raise Errno::ENOENT.new('Gemfile (ensure file exists)') unless File.exists?('Gemfile')
159
+ gemfile = File.read('Gemfile')
160
+ lines = GEMFILE_LINES.select{ |l| !gemfile[l] } # only append items not already present
161
+
162
+ unless(lines.empty?)
163
+ File.open('Gemfile', 'a') do |f|
164
+ f << "\n"
165
+ lines.each { |l| f << (l + "\n") }
166
+ end
167
+ end
168
+ true
169
+ end
170
+
171
+ # Write file content to given path if file does not already
172
+ # exist
173
+ #
174
+ # @param path [String] path to write
175
+ # @param content [String] file content
176
+ # @return [Integer] number of bytes written
177
+ def write_file(path, content)
178
+ raise Errno::EEXIST.new(path) if File.exists?(path)
179
+ File.write(path, content)
180
+ end
181
+
182
+ end
183
+ end
184
+ end
185
+ end
@@ -1,4 +1,4 @@
1
1
  module Jackal
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.3.12')
3
+ VERSION = Gem::Version.new('0.3.14')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.3.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carnivore
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.12
19
+ version: 0.3.14
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.0.0
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.3.12
29
+ version: 0.3.14
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.0.0
@@ -127,6 +127,7 @@ files:
127
127
  - lib/jackal/utils/process.rb
128
128
  - lib/jackal/utils/spec.rb
129
129
  - lib/jackal/utils/spec/callback_local.rb
130
+ - lib/jackal/utils/spec/generator.rb
130
131
  - lib/jackal/utils/spec/helpers.rb
131
132
  - lib/jackal/utils/spec/loader.rb
132
133
  - lib/jackal/utils/spec/runner.rb
@@ -156,3 +157,4 @@ signing_key:
156
157
  specification_version: 4
157
158
  summary: Message processing helper
158
159
  test_files: []
160
+ has_rdoc: