Module: CSpec::Loader
- Defined in:
- lib/cspec/loader.rb
Class Method Summary collapse
- .load(filename) ⇒ Object
- .process_arg(spec, regex, aggregate_key) ⇒ Object
- .process_args(spec) ⇒ Object
- .validate_structure(filename) ⇒ Object
Class Method Details
.load(filename) ⇒ Object
7 8 9 10 |
# File 'lib/cspec/loader.rb', line 7 def self.load(filename) specs = ::CSV.open(filename, headers: :first_row).map(&:to_h) specs.map { |spec| ::CSpec::Spec.new(process_args(spec)) } end |
.process_arg(spec, regex, aggregate_key) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/cspec/loader.rb', line 18 def self.process_arg(spec, regex, aggregate_key) spec.merge({ aggregate_key => spec.keys .select { |k| k.match?(regex) && !spec[k].nil? } .inject([]) { |values, key| values << spec[key] } }) end |
.process_args(spec) ⇒ Object
12 13 14 15 16 |
# File 'lib/cspec/loader.rb', line 12 def self.process_args(spec) process_arg(spec, /method_arg_\d+/, 'method_args').merge( process_arg(spec, /initialization_arg_\d+/, 'initialization_args') ) end |
.validate_structure(filename) ⇒ Object
26 27 28 29 |
# File 'lib/cspec/loader.rb', line 26 def self.validate_structure(filename) headers = CSV.open(filename, &:readline) ::CSpec::Validator.validate_structure(headers) end |