features/step_definitions/remi_step.rb in remi-0.2.14 vs features/step_definitions/remi_step.rb in remi-0.2.15
- old
+ new
@@ -13,30 +13,35 @@
Given /^the job target '([[:alnum:]\s\-_]+)'$/ do |arg|
@brt.add_job_target arg
end
-Given /^the following example(?: record| records|) called '([[:alnum:]\s\-_]+)':$/ do |arg, example_table|
- @brt.add_example arg, example_table
-end
-
Given /^the job parameter '([[:alnum:]\s\-_]+)' is "([^"]*)"$/ do |param, value|
@brt.set_job_parameter(param, value)
end
### Setting up example data
+Given /^the following example(?: record| records|) called '([[:alnum:]\s\-_]+)':$/ do |arg, example_table|
+ @brt.add_example arg, example_table
+end
+
Given /^the following example(?: record| records|) for '([[:alnum:]\s\-_]+)':$/ do |source_name, example_table|
example_name = source_name
@brt.add_example example_name, example_table
@brt.job_sources[source_name].stub_data_with(@brt.examples[example_name])
end
Given /^the example '([[:alnum:]\s\-_]+)' for '([[:alnum:]\s\-_]+)'$/ do |example_name, source_name|
@brt.job_sources[source_name].stub_data_with(@brt.examples[example_name])
end
+Given /^the following (?:record is|records are) appended to '([[:alnum:]\s\-_]+)':$/ do |source_name, example_table|
+ example_name = SecureRandom.uuid
+ @brt.add_example example_name, example_table
+ @brt.job_sources[source_name].append_data_with(@brt.examples[example_name])
+end
### Source file processing
Given /^files with names matching the pattern \/(.*)\/$/ do |pattern|
@brt.filestore.pattern(Regexp.new(pattern))
@@ -104,12 +109,12 @@
Given /^the source '([[:alnum:]\s\-_]+)'$/ do |arg|
@brt.add_source(arg)
end
-Given /^the source field '(.+)'$/ do |arg|
- @brt.sources.add_field(arg)
+Given /^the source field '([^']+)'$/ do |source_field_name|
+ @brt.sources.add_field(source_field_name)
end
Given /^the source field has the value "([^"]*)"$/ do |arg|
@brt.source.field.value = Remi::BusinessRules::ParseFormula.parse(arg)
end
@@ -118,34 +123,48 @@
@brt.source.field.value = ''
end
When /^the source field '(.+)' (?:has an empty value|is blank)$/ do |source_field|
step "the source field '#{source_field}'"
- @brt.source.fields[source_field].value = ''
+ source_name, source_field_name = @brt.sources.parse_full_field(source_field)
+ @brt.sources[source_name].fields[source_field_name].value = ''
end
Given /^the source field '([^:]+)' (?:has|is set to) the value "([^"]*)"$/ do |source_field, value|
step "the source field '#{source_field}'"
@brt.source.fields[source_field].value = Remi::BusinessRules::ParseFormula.parse(value)
end
Given /^the source field '(.+:.+)' (?:has|is set to) the value "([^"]*)"$/ do |source_field, value|
step "the source field '#{source_field}'"
- source_name, field_name = *Remi::BusinessRules.parse_full_field(source_field)
+ source_name, field_name = @brt.sources.parse_full_field(source_field)
@brt.sources[source_name].fields[field_name].value = Remi::BusinessRules::ParseFormula.parse(value)
end
+Given /^the source field '(.+:.+)' (?:has|is set to) the value in the source field '(.+:.+)'$/ do |source_field, other_source_field|
+ step "the source field '#{source_field}'"
+ step "the source field '#{other_source_field}'"
+ source_name, field_name = @brt.sources.parse_full_field(source_field)
+ other_source_name, other_field_name = @brt.sources.parse_full_field(other_source_field)
+
+ @brt.sources[source_name].fields[field_name].value = @brt.sources[other_source_name].fields[other_field_name].value
+end
+
Given /^the source field '(.+:.+)' (?:has|is set to) the value in the source field '(.+:.+)', prefixed with "([^"]*)"$/ do |source_field, other_source_field, prefix|
step "the source field '#{source_field}'"
step "the source field '#{other_source_field}'"
- source_name, field_name = *Remi::BusinessRules.parse_full_field(source_field)
- other_source_name, other_field_name = *Remi::BusinessRules.parse_full_field(other_source_field)
+ source_name, field_name = @brt.sources.parse_full_field(source_field)
+ other_source_name, other_field_name = @brt.sources.parse_full_field(other_source_field)
prefixed = "#{prefix}#{@brt.sources[other_source_name].fields[other_field_name].value}"
@brt.sources[source_name].fields[field_name].value = prefixed
end
+Given /^the source data are tied through the fields '(.+:.+)' and '(.+:.+)'$/ do |source_field, other_source_field|
+ step "the source field '#{other_source_field}' is set to the value in the source field '#{source_field}'"
+end
+
Given /^the source field is parsed with the date format "([^"]*)"$/ do |date_format|
expect(@brt.source.field.metadata[:format]).to eq date_format
end
Given /^the source field is a valid email address$/ do
@@ -178,14 +197,14 @@
Then /^the target field '(.+)' is copied from the source field '(.+:.+)'$/ do |target_field, source_field|
step "the target field '#{target_field}'"
step "the source field '#{source_field}'"
- source_name, source_field_name = *Remi::BusinessRules.parse_full_field(source_field)
+ source_name, source_field_name = @brt.sources.parse_full_field(source_field)
@brt.run_transforms
- expect(@brt.target.field.value).to eq (@brt.sources[source_name].fields[source_field_name].value)
+ expect(@brt.target.fields[target_field].value).to eq (@brt.sources[source_name].fields[source_field_name].value)
end
Then /^the target field '(.+)' is copied from the source field '([^:]+)'$/ do |target_field, source_field|
step "the target field '#{target_field}'"
step "the source field '#{source_field}'"
@@ -198,13 +217,17 @@
@brt.run_transforms
expect(@brt.target.field.value).to eq Remi::BusinessRules::ParseFormula.parse(value)
end
Then /^the target field '(.+)' is (?:set to the value|populated with) "([^"]*)"$/ do |target_field, value|
+ expect_cucumber {
+ expect {
@brt.targets.add_field(target_field)
@brt.run_transforms
+ }.not_to raise_error
expect(@brt.targets.fields[target_field].values.uniq).to eq [Remi::BusinessRules::ParseFormula.parse(value)]
+ }
end
Then /^the target field '(.+)' is in the list "([^"]*)"$/ do |target_field, list|
step "the target field '#{target_field}'"
@@ -232,11 +255,20 @@
Then /^the target should match the example '([[:alnum:]\s]+)'$/ do |example_name|
target_name = @brt.targets.keys.first
step "the target '#{target_name}' should match the example '#{example_name}'"
end
+Then /^the target field '(.+)' is populated from the source field '(.+)' after translating it according to:$/ do |target_field, source_field, translation_table|
+ step "the target field '#{target_field}'"
+ translation_table.rows.each do |translation_row|
+ step "the source field '#{source_field}' is set to the value \"#{translation_row[0]}\""
+ @brt.run_transforms
+ expect(@brt.target.fields[target_field].value).to eq translation_row[1]
+ end
+end
+
### Transforms
Then /^the target field is a concatenation of the source fields, delimited by "([^"]*)"$/ do |delimiter|
concatenated_source = @brt.sources.fields.values.uniq.map do |row|
Array(row.join(delimiter))
@@ -290,27 +322,30 @@
@brt.run_transforms
expect(@brt.target.field.value).to eq target_reformatted
end
Then /^the target field '(.+)' is the first non-blank value from source fields '(.+)'$/ do |target_field_name, source_field_list|
- source_field_names = "'#{source_field_list}'".split(',').map do |field_with_quotes|
- field_with_quotes.match(/'(.+)'/)[1]
+ source_fields = "'#{source_field_list}'".split(',').map do |field_with_quotes|
+ full_field_name = field_with_quotes.match(/'(.+)'/)[1]
+
+ source_name, field_name = @brt.sources.parse_full_field(full_field_name)
+ { full_field_name: full_field_name, source: source_name, field: field_name }
end
- source_field_names.each do |name|
- step "the source field '#{name}'"
+ source_fields.each do |source_field|
+ step "the source field '#{source_field[:full_field_name]}'"
end
step "the target field '#{target_field_name}'"
- source_field_names.each do |source_field_name|
+ source_fields.each do |source_field|
@brt.run_transforms
- source_values = source_field_names.map { |name| @brt.source.fields[name].value }
+ source_values = source_fields.map { |v_source_field| @brt.sources[v_source_field[:source]].fields[v_source_field[:field]].value }
source_values_nvl = source_values.find { |arg| !arg.blank? }
expect_cucumber { expect(@brt.target.fields[target_field_name].value).to eq source_values_nvl }
- @brt.source.fields[source_field_name].value = ''
+ @brt.sources[source_field[:source]].fields[source_field[:field]].value = ''
end
end
When /^in the source field, periods have been used in place of commas$/ do
@@ -382,10 +417,10 @@
step "the target '#{target_name}' has #{nrecords} records"
end
Then /^the target '([[:alnum:]\s\-_]+)' has (\d+) record(?:s|)$/ do |target_name, nrecords|
@brt.run_transforms
- expect(@brt.targets[target_name].size).to be nrecords.to_i
+ expect(@brt.targets[target_name].size).to eq nrecords.to_i
end
Then /^the target has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is "([^"]*)"$/ do |nrecords, field_name, value|
target_name = @brt.targets.keys.first
step "the target '#{target_name}' has #{nrecords} records where '#{field_name}' is \"#{value}\""