rubeno 0.0.1

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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +8 -0
  3. data/bin/rubeno +4 -0
  4. data/lib/rubeno.rb +317 -0
  5. data/test/test_rubeno.rb +16 -0
  6. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9eb232b39625c3e7467530c20adb9a89f45c1ae07ac6708f33e37174a5462d8
4
+ data.tar.gz: 04fa396a8506495962ac24b64846e3aea60e4e623d70c7acd057306a57db5c05
5
+ SHA512:
6
+ metadata.gz: 3c5972c7a4caef6240ecf784080acf1f40bd4397448cca85c9091a4d446544045bf98266640760c668d93e651abe3e06808c17f2a4668c3b3f953d853ba02f67
7
+ data.tar.gz: 68a7c328e9ba490e83b8f098f52b1e6e2674ef9fff1f7bac3440f37ec7923a66bd60a4719c678385d85e6ae6c0833843723d9c7f510e82febd2d20f624ba338a
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
data/bin/rubeno ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hola'
4
+ puts Hola.hi(ARGV[0])
data/lib/rubeno.rb ADDED
@@ -0,0 +1,317 @@
1
+ require 'json'
2
+ require_relative 'base_suite'
3
+ require_relative 'base_given'
4
+ require_relative 'base_when'
5
+ require_relative 'base_then'
6
+ require_relative 'simple_adapter'
7
+ require_relative 'pm/ruby'
8
+ require_relative 'types'
9
+
10
+ module Rubeno
11
+ class Rubeno
12
+ attr_accessor :test_resource_requirement, :artifacts, :test_jobs, :test_specification,
13
+ :suites_overrides, :given_overrides, :when_overrides, :then_overrides,
14
+ :puppet_master, :specs, :total_tests, :assert_this, :test_adapter,
15
+ :test_subject
16
+
17
+ def initialize(input_val, test_specification, test_implementation, test_resource_requirement, test_adapter, uber_catcher = nil)
18
+ @test_resource_requirement = test_resource_requirement
19
+ @artifacts = []
20
+ @test_jobs = []
21
+ @test_specification = test_specification
22
+ @suites_overrides = {}
23
+ @given_overrides = {}
24
+ @when_overrides = {}
25
+ @then_overrides = {}
26
+ @test_subject = input_val
27
+ @test_adapter = test_adapter
28
+
29
+ # Initialize classy implementations
30
+ initialize_classy_implementations(test_implementation)
31
+
32
+ # Generate specs
33
+ @specs = test_specification.call(
34
+ suites_wrapper,
35
+ given_wrapper,
36
+ when_wrapper,
37
+ then_wrapper
38
+ )
39
+
40
+ # Initialize test jobs
41
+ initialize_test_jobs
42
+ end
43
+
44
+ def suites_wrapper
45
+ # Return an object that responds to method calls for suite types
46
+ wrapper = Object.new
47
+ @suites_overrides.each do |suite_name, suite_proc|
48
+ wrapper.define_singleton_method(suite_name) do |description, givens_dict|
49
+ {
50
+ 'name' => description,
51
+ 'givens' => givens_dict
52
+ }
53
+ end
54
+ end
55
+ wrapper
56
+ end
57
+
58
+ def given_wrapper
59
+ wrapper = Object.new
60
+ @given_overrides.each do |given_name, given_proc|
61
+ wrapper.define_singleton_method(given_name) do |features, whens, thens, initial_values = nil|
62
+ given_proc.call(features, whens, thens, initial_values)
63
+ end
64
+ end
65
+ wrapper
66
+ end
67
+
68
+ def when_wrapper
69
+ wrapper = Object.new
70
+ @when_overrides.each do |when_name, when_proc|
71
+ wrapper.define_singleton_method(when_name) do |*args|
72
+ when_proc.call(*args)
73
+ end
74
+ end
75
+ wrapper
76
+ end
77
+
78
+ def then_wrapper
79
+ wrapper = Object.new
80
+ @then_overrides.each do |then_name, then_proc|
81
+ wrapper.define_singleton_method(then_name) do |*args|
82
+ then_proc.call(*args)
83
+ end
84
+ end
85
+ wrapper
86
+ end
87
+
88
+ def initialize_classy_implementations(test_implementation)
89
+ # Create classy givens
90
+ test_implementation.givens.each do |key, given_cb|
91
+ @given_overrides[key] = ->(features, whens, thens, initial_values = nil) do
92
+ BaseGiven.new(features, whens, thens, given_cb, initial_values)
93
+ end
94
+ end
95
+
96
+ # Create classy whens
97
+ test_implementation.whens.each do |key, when_cb_proc|
98
+ @when_overrides[key] = ->(*args) do
99
+ when_cb = when_cb_proc.call(*args)
100
+ BaseWhen.new(key, when_cb)
101
+ end
102
+ end
103
+
104
+ # Create classy thens
105
+ test_implementation.thens.each do |key, then_cb_proc|
106
+ @then_overrides[key] = ->(*args) do
107
+ then_cb = then_cb_proc.call(*args)
108
+ BaseThen.new(key, then_cb)
109
+ end
110
+ end
111
+ end
112
+
113
+ def initialize_test_jobs
114
+ @test_jobs = []
115
+ @specs.each_with_index do |suite_spec, i|
116
+ # Create a BaseSuite instance
117
+ suite = BaseSuite.new(suite_spec['name'], suite_spec['givens'])
118
+ suite.index = i
119
+
120
+ # Create a test job
121
+ test_job = {
122
+ suite: suite,
123
+ receiveTestResourceConfig: ->(pm, test_resource_config) { run_test_job(suite, pm, test_resource_config) },
124
+ to_obj: -> { suite.to_obj }
125
+ }
126
+
127
+ @test_jobs << test_job
128
+ end
129
+ end
130
+
131
+ def run_test_job(suite, pm, test_resource_config)
132
+ t_log = ->(*args) { puts args.join(' ') }
133
+
134
+ # Run the suite
135
+ suite_done = suite.run(
136
+ @test_subject,
137
+ test_resource_config, # Use the actual test resource configuration
138
+ ->(f_path, value) { nil }, # Simple artifactory
139
+ t_log,
140
+ pm
141
+ )
142
+
143
+ # Create result object
144
+ result = Object.new
145
+ result.instance_variable_set(:@fails, suite_done.fails)
146
+ result.instance_variable_set(:@artifacts, suite_done.artifacts)
147
+ result.instance_variable_set(:@features, suite_done.features)
148
+
149
+ def result.fails; @fails; end
150
+ def result.artifacts; @artifacts; end
151
+ def result.features; @features; end
152
+
153
+ result
154
+ rescue => e
155
+ puts "Error in test job: #{e.message}"
156
+ puts e.backtrace
157
+
158
+ result = Object.new
159
+ result.instance_variable_set(:@fails, 1)
160
+ result.instance_variable_set(:@artifacts, [])
161
+ result.instance_variable_set(:@features, [])
162
+
163
+ def result.fails; @fails; end
164
+ def result.artifacts; @artifacts; end
165
+ def result.features; @features; end
166
+
167
+ result
168
+ end
169
+
170
+ def receiveTestResourceConfig(partialTestResource, websocket_port = 'ipcfile')
171
+ # Parse the test resource configuration
172
+ test_resource_config = parse_test_resource_config(partialTestResource)
173
+
174
+ pm = PM_Ruby.new(test_resource_config, websocket_port)
175
+
176
+ # Run all test jobs
177
+ total_fails = 0
178
+ all_features = []
179
+ all_artifacts = []
180
+ suite_results = []
181
+
182
+ @test_jobs.each do |job|
183
+ begin
184
+ # Update the job's receiveTestResourceConfig to pass test_resource_config
185
+ result = run_test_job(job[:suite], pm, test_resource_config)
186
+ total_fails += result.fails
187
+ all_features.concat(result.features)
188
+ all_artifacts.concat(result.artifacts)
189
+ suite_results << job[:to_obj].call
190
+ rescue => e
191
+ puts "Error running test job: #{e.message}"
192
+ total_fails += 1
193
+ end
194
+ end
195
+
196
+ # Write tests.json
197
+ write_tests_json(suite_results, total_fails, all_features.uniq, all_artifacts)
198
+
199
+ # Return result
200
+ IFinalResults.new(
201
+ failed: total_fails > 0,
202
+ fails: total_fails,
203
+ artifacts: all_artifacts,
204
+ features: all_features.uniq
205
+ )
206
+ end
207
+
208
+ private
209
+
210
+ def parse_test_resource_config(partialTestResource)
211
+ begin
212
+ config = JSON.parse(partialTestResource)
213
+ # Create a hash that can be used as test resource configuration
214
+ # The PM_Ruby expects certain methods to be available
215
+ config_hash = {
216
+ 'name' => config['name'] || 'default',
217
+ 'fs' => config['fs'] || '.',
218
+ 'ports' => config['ports'] || [],
219
+ 'timeout' => config['timeout'] || 30000,
220
+ 'retries' => config['retries'] || 0,
221
+ 'environment' => config['environment'] || {}
222
+ }
223
+ # Create an object that responds to the needed methods
224
+ test_resource = Object.new
225
+ test_resource.define_singleton_method(:name) { config_hash['name'] }
226
+ test_resource.define_singleton_method(:fs) { config_hash['fs'] }
227
+ test_resource.define_singleton_method(:ports) { config_hash['ports'] }
228
+ test_resource.define_singleton_method(:timeout) { config_hash['timeout'] }
229
+ test_resource.define_singleton_method(:retries) { config_hash['retries'] }
230
+ test_resource.define_singleton_method(:environment) { config_hash['environment'] }
231
+ test_resource
232
+ rescue JSON::ParserError
233
+ # If not valid JSON, create a default config
234
+ test_resource = Object.new
235
+ test_resource.define_singleton_method(:name) { 'default' }
236
+ test_resource.define_singleton_method(:fs) { '.' }
237
+ test_resource.define_singleton_method(:ports) { [] }
238
+ test_resource.define_singleton_method(:timeout) { 30000 }
239
+ test_resource.define_singleton_method(:retries) { 0 }
240
+ test_resource.define_singleton_method(:environment) { {} }
241
+ test_resource
242
+ end
243
+ end
244
+
245
+ def write_tests_json(suite_results, total_fails, features, artifacts)
246
+ # Flatten all givens from all suites
247
+ all_givens = []
248
+ suite_results.each do |suite|
249
+ if suite[:givens]
250
+ all_givens.concat(suite[:givens])
251
+ end
252
+ end
253
+
254
+ tests_data = {
255
+ 'name' => @specs.first ? @specs.first['name'] : 'Unnamed Test',
256
+ 'givens' => all_givens,
257
+ 'fails' => total_fails,
258
+ 'failed' => total_fails > 0,
259
+ 'features' => features,
260
+ 'artifacts' => artifacts
261
+ }
262
+
263
+ # Create directory if it doesn't exist
264
+ dir_path = 'testeranto/reports/allTests/example'
265
+ FileUtils.mkdir_p(dir_path) unless Dir.exist?(dir_path)
266
+
267
+ # Write to file
268
+ tests_json_path = "#{dir_path}/ruby.Calculator.test.ts.json"
269
+ File.write(tests_json_path, JSON.pretty_generate(tests_data))
270
+ puts "tests.json written to: #{tests_json_path}"
271
+ end
272
+ end
273
+
274
+ # Main function
275
+ def self.main
276
+ puts "Rubeno Ruby implementation"
277
+
278
+ # Check command line arguments
279
+ if ARGV.length < 1
280
+ puts "No test arguments provided - exiting"
281
+ exit 0
282
+ end
283
+
284
+ partialTestResource = ARGV[0]
285
+ websocket_port = ARGV[1] || 'ipcfile'
286
+
287
+ # We need a default instance to run
288
+ # In a real implementation, this would be set elsewhere
289
+ if $default_rubeno_instance.nil?
290
+ puts "ERROR: No default Rubeno instance has been configured"
291
+ exit -1
292
+ end
293
+
294
+ result = $default_rubeno_instance.receiveTestResourceConfig(partialTestResource, websocket_port)
295
+ exit result.fails
296
+ end
297
+
298
+ # Store the default instance
299
+ $default_rubeno_instance = nil
300
+
301
+ def self.set_default_instance(instance)
302
+ $default_rubeno_instance = instance
303
+ end
304
+
305
+ # Helper function to create a Rubeno instance
306
+ def self.Rubeno(input_val = nil, test_specification = nil, test_implementation = nil, test_adapter = nil, test_resource_requirement = nil, uber_catcher = nil)
307
+ instance = Rubeno.new(
308
+ input_val,
309
+ test_specification,
310
+ test_implementation,
311
+ test_resource_requirement || ITTestResourceRequest.new,
312
+ test_adapter || SimpleTestAdapter.new,
313
+ uber_catcher
314
+ )
315
+ instance
316
+ end
317
+ end
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'rubneo'
3
+
4
+ class RubenoTest < Test::Unit::TestCase
5
+ # def test_english_hello
6
+ # assert_equal "hello world", Hola.hi("english")
7
+ # end
8
+
9
+ # def test_any_hello
10
+ # assert_equal "hello world", Hola.hi("ruby")
11
+ # end
12
+
13
+ # def test_spanish_hello
14
+ # assert_equal "hola mundo", Hola.hi("spanish")
15
+ # end
16
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubeno
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Wong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-04-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: The Ruby implementation of Testeranto
14
+ email: adamwong246@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - Rakefile
20
+ - bin/rubeno
21
+ - lib/rubeno.rb
22
+ - test/test_rubeno.rb
23
+ homepage: http://rubygems.org/gems/rubeno
24
+ licenses: []
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.4.1
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: The Ruby implementation of Testeranto
45
+ test_files:
46
+ - test/test_rubeno.rb