lib/remi/project/features/step_definitions/remi_step.rb in remi-0.2.6 vs lib/remi/project/features/step_definitions/remi_step.rb in remi-0.2.7

- old
+ new

@@ -13,21 +13,21 @@ Given /^the job target '([[:alnum:]\s\-_]+)'$/ do |arg| @brt.add_job_target arg end -Given /^the following example record called '([[:alnum:]\s\-_]+)':$/ do |arg, example_table| +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 for '([[:alnum:]\s\-_]+)':$/ do |source_name, example_table| +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 @@ -195,10 +195,19 @@ @brt.targets.add_field(target_field) @brt.run_transforms 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}'" + + list_array = list.split(',').map(&:strip) + @brt.run_transforms + expect(@brt.targets.fields[target_field].values.uniq & list_array).to include(*@brt.targets.fields[target_field].values.uniq) +end + + Then /^the target field '(.+)' is the date (.+)$/ do |target_field, date_reference| step "the target field '#{target_field}' is set to the value \"*#{date_reference}*\"" end Then /^the target '(.+)' should match the example '([[:alnum:]\s]+)'$/ do |target_name, example_name| @@ -227,10 +236,16 @@ @brt.run_transforms expect(@brt.targets.fields.values.uniq).to eq concatenated_source end +Then /^the target field is a concatenation of '(.+)' and '(.+)', delimited by "([^"]*)"$/ do |source_field_1, source_field_2, delimiter| + expected_value = [@brt.sources.fields[source_field_1].value, @brt.sources.fields[source_field_2].value].join(delimiter) + @brt.run_transforms + expect(@brt.targets.fields.values.uniq).to eq [[expected_value]] +end + Then /^the target field is a concatenation of "([^"]*)" and '(.+)', delimited by "([^"]*)"$/ do |constant, source_field, delimiter| expected_value = [constant, @brt.sources.fields[source_field].value].join(delimiter) @brt.run_transforms expect(@brt.targets.fields.values.uniq).to eq [[expected_value]] end @@ -293,12 +308,12 @@ expect(@brt.target.data_obj.fields.keys).to match_array @brt.target.fields.names end ### Record-level expectations -Then /^the record should be (?i)(Retained|Rejected)(?-i)(?: without error|)$/ do |action| - source_size = @brt.source.size +Then /^the record from source '(.+)' should be (?i)(Retained|Rejected)(?-i)(?: without error|)$/ do |source_name, action| + source_size = @brt.sources[source_name].size @brt.run_transforms targets_size = @brt.targets.total_size case when action.downcase == 'retained' @@ -308,11 +323,16 @@ else raise "Unknown action #{action}" end end -Then /^the record should (not be|be) present on the target$/ do |action| +Then /^the record(?:s|) should be (?i)(Retained|Rejected)(?-i)(?: without error|)$/ do |action| + source_name = @brt.sources.keys.first + step "the record from source '#{source_name}' should be #{action}" +end + +Then /^the record(?:s|) should (not be|be) present on the target$/ do |action| map_action = { 'not be' => 'rejected', 'be' => 'retained' } step "the record should be #{map_action[action]}" end Then /^a target record is created$/ do @@ -321,6 +341,71 @@ end Then /^a target record is not created$/ do @brt.run_transforms expect(@brt.targets.total_size).to be 0 +end + + +### Record counting + +Then /^the target has (\d+) record(?:s|)$/ do |nrecords| + target_name = @brt.targets.keys.first + 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 +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}\"" +end + +Then /^the target '([[:alnum:]\s\-_]+)' has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is "([^"]*)"$/ do |target_name, nrecords, field_name, value| + @brt.run_transforms + expect(@brt.targets[target_name].where_is(field_name, value).size).to eq nrecords.to_i +end + +Then /^the target has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is in "([^"]*)"$/ do |nrecords, field_name, value| + target_name = @brt.targets.keys.first + step "the target '#{target_name}' has #{nrecords} records where '#{field_name}' is in \"#{value}\"" +end + +Then /^the target '([[:alnum:]\s\-_]+)' has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is in "([^"]*)"$/ do |target_name, nrecords, field_name, value| + @brt.run_transforms + expect(@brt.targets[target_name].where_in(field_name, value).size).to eq nrecords.to_i +end + +Then /^the target has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is (\d*\.?\d+)$/ do |nrecords, field_name, value| + target_name = @brt.targets.keys.first + step "the target '#{target_name}' has #{nrecords} records where '#{field_name}' is #{value}" +end + +Then /^the target '([[:alnum:]\s\-_]+)' has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is (\d*\.?\d+)$/ do |target_name, nrecords, field_name, value| + @brt.run_transforms + expect(@brt.targets[target_name].where_is(field_name, value).size).to eq nrecords.to_i +end + +Then /^the target has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is (less|greater) than (\d*\.?\d+)$/ do |nrecords, field_name, direction, value| + target_name = @brt.targets.keys.first + step "the target '#{target_name}' has #{nrecords} records where '#{field_name}' is #{direction} than #{value}" +end + +Then /^the target '([[:alnum:]\s\-_]+)' has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is (less|greater) than (\d*\.?\d+)$/ do |target_name, nrecords, field_name, direction, value| + @brt.run_transforms + query_method = { 'less' => :where_lt, 'greater' => :where_gt }[direction] + + expect(@brt.targets[target_name].send(query_method, field_name, value).size).to eq nrecords.to_i +end + +Then /^the target has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is between (\d*\.?\d+) and (\d*\.?\d+)$/ do |nrecords, field_name, low_value, high_value| + target_name = @brt.targets.keys.first + step "the target '#{target_name}' has #{nrecords} records where '#{field_name}' is between #{low_value} and #{high_value}" +end + +Then /^the target '([[:alnum:]\s\-_]+)' has (\d+) record(?:s|) where '([[:alnum:]\s\-_]+)' is between (\d*\.?\d+) and (\d*\.?\d+)$/ do |target_name, nrecords, field_name, low_value, high_value| + @brt.run_transforms + expect(@brt.targets[target_name].where_between(field_name, low_value, high_value).size).to eq nrecords.to_i end