rast 0.3.0.pre → 0.4.0.pre

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
  SHA256:
3
- metadata.gz: 8391dc80e151d193090188d90cd08e7e596056275fad1d10fe24c47cc8a43cd9
4
- data.tar.gz: abbc0bfc9e056de88bab998f3c5ebb36234650a884d650c2d96c00efd113ef9a
3
+ metadata.gz: b7cc441726e5d5112063ef2cf2886627723522e56f15902e03b7a4338c7765dc
4
+ data.tar.gz: 64978ebd88c648899445d712b00a9095f1dcbdf5c00c5709f536af259fa1ddc2
5
5
  SHA512:
6
- metadata.gz: 37ab3933ed59e5d347faceeba789e59b6af71fcb7384a035db7b9a6d1c67371e507ad74c4f19ce5b04f77074ab5a887b2151da267b02e29a3e6519ee02ad1ec1
7
- data.tar.gz: be8bfaf8cebaceb398e74d2902a29b3ac78c131445ac1850fc3b1c39dfbabd986c017e353fd3728b95df395493ef35ac77e02193acf4889435d43770b59eff4f
6
+ metadata.gz: fdb9d8e763f2bbc47f97b2a90a16c6f79d9b8300de9ea4afe1c5cbed3e68282ea85d26f88e28d7d2889ab543a06bc423674cd79171b116fcbbcda21a3d9f032f
7
+ data.tar.gz: 4daa2de1cb969a6c5de8fcfeade4986249d91081ef2610e8f7014c47e78bd0ea78734650235cd9508fd0fa937d2a4ace3618b11e1bc85e7f4d11587343803977
data/CHANGELOG.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Change log
2
2
 
3
-
4
- - 0.3.0.pre - Support factory methods in execute block
5
- - 0.2.0.pre - Support module subjects
6
- - 0.1.2.pre - Fixed exclusions
3
+ - 0.4.0.pre - Allow yaml-less configuration.
4
+ - 0.3.1.pre - Fixed spec naming for modules.
5
+ - 0.3.0.pre - Support factory methods in execute block.
6
+ - 0.2.0.pre - Support module subjects.
7
+ - 0.1.2.pre - Fixed exclusions.
7
8
  - 0.1.1.pre - Pre release version compatible with Ruby 2.0.0-p247
@@ -11,12 +11,17 @@ require 'rast/converters/float_converter'
11
11
 
12
12
  # Generates the test parameters.
13
13
  class ParameterGenerator
14
+ # Allow access so yaml-less can build the config via dsl.
15
+ attr_accessor :specs_config
16
+
14
17
  def initialize(yaml_path: '')
15
- @specs_config = YAML.load_file(yaml_path)['specs']
18
+ @specs_config = YAML.load_file(yaml_path)['specs'] if File.exist? yaml_path
16
19
  end
17
20
 
18
21
  # addCase. Generate the combinations, then add the fixture to the final list
19
22
  def generate_fixtures(spec_id: '')
23
+ return nil if @specs_config.nil?
24
+
20
25
  spec_config = @specs_config[spec_id]
21
26
 
22
27
  spec_config[:description] = spec_id
@@ -90,10 +95,12 @@ class ParameterGenerator
90
95
  converters = if spec_config['converters'].nil?
91
96
  str_converter = StrConverter.new
92
97
  spec_config['variables'].map { |_var| str_converter }
93
- else
98
+ elsif spec_config['converters'].first.class == String
94
99
  spec_config['converters'].map do |converter|
95
100
  Object.const_get(converter).new
96
101
  end
102
+ else
103
+ spec_config['converters']
97
104
  end
98
105
 
99
106
  spec.init_converters(converters: converters)
@@ -19,8 +19,8 @@ class RastSpec
19
19
  def init_pair(pair_config: {})
20
20
  @pair[pair_config.keys.first.to_s] = pair_config.values.first.to_s
21
21
 
22
- array = [@pair.to_a.first.reverse]
23
- @pair_reversed = { array.first.to_s.to_sym => array.last }
22
+ array = [@pair.to_a.first.reverse].first
23
+ @pair_reversed = { array.first.to_s => array.last }
24
24
  self
25
25
  end
26
26
 
data/lib/rast/spec_dsl.rb CHANGED
@@ -10,8 +10,17 @@ class SpecDSL
10
10
  attr_accessor :subject, :rspec_methods, :execute_block,
11
11
  :prepare_block, :transients, :outcomes, :fixtures
12
12
 
13
- def initialize(subject: nil, fixtures: [], &block)
13
+ # # yaml-less
14
+ attr_writer :variables, :exclude, :converters, :rules, :pair
15
+
16
+ # @subject the sut instance
17
+ # @name the sut name to be displayed with -fd
18
+ def initialize(subject: nil, name: '', fixtures: [], spec_id: '', &block)
14
19
  @subject = subject
20
+ @spec_id = spec_id
21
+
22
+ # cannot derive name from subject when sut is a module.
23
+ @subject_name = name || subject.class
15
24
  @fixtures = fixtures
16
25
 
17
26
  @transients = []
@@ -30,6 +39,7 @@ class SpecDSL
30
39
  end
31
40
 
32
41
  def method_missing(method_name_symbol, *args, &block)
42
+ # p "method_missing: #{method_name_symbol}"
33
43
  return super if method_name_symbol == :to_ary
34
44
 
35
45
  @rspec_methods << {
@@ -41,6 +51,29 @@ class SpecDSL
41
51
  self
42
52
  end
43
53
 
54
+ # yaml-less start
55
+ def variables(vars)
56
+ @variables = vars
57
+ end
58
+
59
+ def exclude(clause)
60
+ @exclude = clause
61
+ end
62
+
63
+ def converters(&block)
64
+ @converters = instance_eval(&block)
65
+ end
66
+
67
+ def rules(rules)
68
+ @rules = rules
69
+ end
70
+
71
+ def pair(pair)
72
+ @pair = pair
73
+ end
74
+
75
+ # yaml-less end
76
+
44
77
  def prepare(&block)
45
78
  @prepare_block = block
46
79
  @transients
@@ -49,6 +82,19 @@ class SpecDSL
49
82
  def execute(&block)
50
83
  @execute_block = block
51
84
 
85
+ if @fixtures.nil?
86
+ parameter_generator = ParameterGenerator.new
87
+ parameter_generator.specs_config = { @spec_id => {
88
+ 'variables' => @variables,
89
+ 'pair' => @pair,
90
+ 'converters' => @converters,
91
+ 'rules' => @rules,
92
+ 'exclude' => @exclude
93
+ } }
94
+
95
+ @fixtures = parameter_generator.generate_fixtures(spec_id: @spec_id)
96
+ end
97
+
52
98
  @fixtures.sort_by! do |fixture|
53
99
  fixture[:expected_outcome] + fixture[:scenario].to_s
54
100
  end
@@ -62,7 +108,7 @@ class SpecDSL
62
108
  spec = @fixtures.first[:spec]
63
109
  main_scope = self
64
110
 
65
- RSpec.describe "#{@subject.class}: #{spec.description}" do
111
+ RSpec.describe "#{@subject_name}: #{spec.description}" do
66
112
  main_scope.fixtures.each do |fixture|
67
113
  generate_rspec(
68
114
  scope: main_scope,
@@ -104,6 +150,12 @@ def generate_rspec(scope: nil, scenario: {}, expected: '')
104
150
  end
105
151
 
106
152
  # DSL Entry Point
107
- def spec(subject: nil, fixtures: [], &block)
108
- SpecDSL.new(subject: subject, fixtures: fixtures, &block)
153
+ def spec(subject: nil, name: '', fixtures: [], spec_id: '', &block)
154
+ SpecDSL.new(
155
+ subject: subject,
156
+ name: name,
157
+ fixtures: fixtures,
158
+ spec_id: spec_id,
159
+ &block
160
+ )
109
161
  end
data/lib/rast.rb CHANGED
@@ -24,6 +24,8 @@ class Rast
24
24
  rasted_subject.new
25
25
  end
26
26
 
27
+ @subject_name = rasted_subject
28
+
27
29
  spec_path = caller[2][/spec.*?\.rb/]
28
30
  yaml_path = spec_path.gsub(/(\w+).rb/, 'rast/\\1.yml')
29
31
 
@@ -35,7 +37,9 @@ class Rast
35
37
  def spec(id, &block)
36
38
  global_spec(
37
39
  subject: @subject,
40
+ name: @subject_name,
38
41
  fixtures: @generator.generate_fixtures(spec_id: id),
42
+ spec_id: id,
39
43
  &block
40
44
  )
41
45
  end
data/rast.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rast'
5
- spec.version = '0.3.0.pre'
5
+ spec.version = '0.4.0.pre'
6
6
  spec.authors = ['Royce Remulla']
7
7
  spec.email = ['royce.com@gmail.com']
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.pre
4
+ version: 0.4.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Royce Remulla
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-25 00:00:00.000000000 Z
11
+ date: 2020-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Extends RSpec functionality by using the catch-all-scenario testing (CAST)
14
14
  principle.