lib/remi/cucumber/business_rules.rb in remi-0.2.14 vs lib/remi/cucumber/business_rules.rb in remi-0.2.15

- old
+ new

@@ -1,12 +1,8 @@ module Remi::BusinessRules using Remi::Refinements::Symbolizer - def self.parse_full_field(full_field_name) - full_field_name.split(':').map(&:strip) - end - def self.csv_opt_map { 'tab' => "\t", 'comma' => ',', 'pipe' => '|', @@ -171,22 +167,29 @@ def keys @subjects.keys end + def parse_full_field(full_field_name, multi: false) + if full_field_name.include? ':' + full_field_name.split(':').map(&:strip) + elsif multi + [@subjects.keys, full_field_name] + else + raise "Multiple subjects defined: #{keys}" unless @subjects.size == 1 + [@subjects.keys.first, full_field_name] + end + end + def add_subject(subject_name, subject) @subjects[subject_name] ||= DataSubject.new(subject) end def add_field(full_field_name) - if full_field_name.include? ':' - subject_name, field_name = *Remi::BusinessRules.parse_full_field(full_field_name) + subject_names, field_name = parse_full_field(full_field_name, multi: true) + Array(subject_names).each do |subject_name| @subjects[subject_name].add_field(field_name) - else - @subjects.each do |subject_name, subject| - subject.add_field(full_field_name) - end end end def only raise "Multiple subjects defined: #{keys}" unless @subjects.size == 1 @@ -283,12 +286,20 @@ def stub_data @data_obj.stub_df if @data_obj.respond_to? :stub_df end + def example_to_df(example) + example.to_df(@data_obj.df.row[0].to_hash, field_symbolizer: @data_obj.field_symbolizer) + end + def stub_data_with(example) stub_data - @data_obj.df = example.to_df(@data_obj.df.row[0].to_hash, field_symbolizer: @data_obj.field_symbolizer) + @data_obj.df = example_to_df(example) + end + + def append_data_with(example) + @data_obj.df = @data_obj.df.concat example_to_df(example) end def replicate_rows(n_rows) replicated_df = Daru::DataFrame.new([], order: @data_obj.df.vectors.to_a)