Class: SpecDSL
- Inherits:
-
Object
- Object
- SpecDSL
- Includes:
- FactoryBot::Syntax::Methods
- Defined in:
- lib/rast/spec_dsl.rb
Overview
Main DSL. This is the entry point of the test when running a spec.
Instance Attribute Summary collapse
-
#converters ⇒ Object
writeonly
# yaml-less.
-
#default_outcome ⇒ Object
writeonly
# yaml-less.
-
#exclude ⇒ Object
writeonly
# yaml-less.
-
#execute_block ⇒ Object
Returns the value of attribute execute_block.
-
#fixtures ⇒ Object
Returns the value of attribute fixtures.
-
#include ⇒ Object
writeonly
# yaml-less.
-
#outcomes(outcomes) ⇒ Object
Returns the value of attribute outcomes.
-
#pair ⇒ Object
writeonly
# yaml-less.
-
#prepare_block ⇒ Object
Returns the value of attribute prepare_block.
- #rules(rules) ⇒ Object
-
#spec_id ⇒ Object
Returns the value of attribute spec_id.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#variables(vars) ⇒ Object
yaml-less start.
Instance Method Summary collapse
- #default(default) ⇒ Object
- #exclusion(clause) ⇒ Object
- #execute(&block) ⇒ Object
- #inclusion(clause) ⇒ Object
-
#initialize(subject: nil, name: '', fixtures: [], spec_id: '', &block) ⇒ SpecDSL
constructor
A new instance of SpecDSL.
-
#prepare(&block) ⇒ Object
yaml-less end.
Constructor Details
#initialize(subject: nil, name: '', fixtures: [], spec_id: '', &block) ⇒ SpecDSL
Returns a new instance of SpecDSL.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rast/spec_dsl.rb', line 19 def initialize(subject: nil, name: '', fixtures: [], spec_id: '', &block) @subject = subject @spec_id = spec_id # cannot derive name from subject when sut is a module. @subject_name = name || subject.class @fixtures = fixtures instance_eval(&block) end |
Instance Attribute Details
#converters=(value) ⇒ Object (writeonly)
# yaml-less
14 15 16 |
# File 'lib/rast/spec_dsl.rb', line 14 def converters=(value) @converters = value end |
#default_outcome=(value) ⇒ Object (writeonly)
# yaml-less
14 15 16 |
# File 'lib/rast/spec_dsl.rb', line 14 def default_outcome=(value) @default_outcome = value end |
#exclude=(value) ⇒ Object (writeonly)
# yaml-less
14 15 16 |
# File 'lib/rast/spec_dsl.rb', line 14 def exclude=(value) @exclude = value end |
#execute_block ⇒ Object
Returns the value of attribute execute_block.
10 11 12 |
# File 'lib/rast/spec_dsl.rb', line 10 def execute_block @execute_block end |
#fixtures ⇒ Object
Returns the value of attribute fixtures.
10 11 12 |
# File 'lib/rast/spec_dsl.rb', line 10 def fixtures @fixtures end |
#include=(value) ⇒ Object (writeonly)
# yaml-less
14 15 16 |
# File 'lib/rast/spec_dsl.rb', line 14 def include=(value) @include = value end |
#outcomes(outcomes) ⇒ Object
Returns the value of attribute outcomes.
10 11 12 |
# File 'lib/rast/spec_dsl.rb', line 10 def outcomes @outcomes end |
#pair=(value) ⇒ Object (writeonly)
# yaml-less
14 15 16 |
# File 'lib/rast/spec_dsl.rb', line 14 def pair=(value) @pair = value end |
#prepare_block ⇒ Object
Returns the value of attribute prepare_block.
10 11 12 |
# File 'lib/rast/spec_dsl.rb', line 10 def prepare_block @prepare_block end |
#rules(rules) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/rast/spec_dsl.rb', line 43 def rules(rules) @rules = {} rules.each do |key, value| calc_key = key calc_key = key == :true if key == :true || key == :false @rules[calc_key] = value end end |
#spec_id ⇒ Object
Returns the value of attribute spec_id.
10 11 12 |
# File 'lib/rast/spec_dsl.rb', line 10 def spec_id @spec_id end |
#subject ⇒ Object
Returns the value of attribute subject.
10 11 12 |
# File 'lib/rast/spec_dsl.rb', line 10 def subject @subject end |
#variables(vars) ⇒ Object
yaml-less start
31 32 33 |
# File 'lib/rast/spec_dsl.rb', line 31 def variables(vars) @variables = vars end |
Instance Method Details
#default(default) ⇒ Object
57 58 59 |
# File 'lib/rast/spec_dsl.rb', line 57 def default(default) @default_outcome = default end |
#exclusion(clause) ⇒ Object
35 36 37 |
# File 'lib/rast/spec_dsl.rb', line 35 def exclusion(clause) @exclude = clause end |
#execute(&block) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rast/spec_dsl.rb', line 67 def execute(&block) @execute_block = block if @fixtures.nil? parameter_generator = ParameterGenerator.new parameter_generator.specs_config = { @spec_id => { 'variables' => @variables, 'pair' => @pair, 'converters' => @converters, 'rules' => @rules, 'exclude' => @exclude, 'include' => @include, 'default' => @default_outcome } } @fixtures = parameter_generator.generate_fixtures(spec_id: @spec_id) end @fixtures.sort_by! do |fixture| if fixture[:expected].nil? raise "Expected outcome not found for #{fixture[:scenario]}, check" \ ' your single rule/else/default configuration' end fixture[:expected] + fixture[:scenario].to_s end generate_rspecs end |
#inclusion(clause) ⇒ Object
39 40 41 |
# File 'lib/rast/spec_dsl.rb', line 39 def inclusion(clause) @include = clause end |
#prepare(&block) ⇒ Object
yaml-less end
63 64 65 |
# File 'lib/rast/spec_dsl.rb', line 63 def prepare(&block) @prepare_block = block end |