lib/remi/cucumber/business_rules.rb in remi-0.2.35 vs lib/remi/cucumber/business_rules.rb in remi-0.2.36
- old
+ new
@@ -111,30 +111,35 @@
class Tester
def initialize(job_name)
job_class_name = "#{job_name.gsub(/\s/,'')}Job"
+ require_job_file(job_class_name)
@job = Object.const_get(job_class_name).new
@job_sources = DataSubjectCollection.new
@job_targets = DataSubjectCollection.new
@sources = DataSubjectCollection.new
@targets = DataSubjectCollection.new
@examples = DataExampleCollection.new
-
- @filestore = Filestore.new
end
attr_reader :job
attr_reader :job_sources
attr_reader :job_targets
attr_reader :sources
attr_reader :targets
attr_reader :examples
- attr_reader :filestore
+ def require_job_file(job_class_name)
+ job_file = Dir["#{Remi::Settings.jobs_dir}/**/*_job.rb"].map do |fname|
+ fname if File.basename(fname) == "#{job_class_name.underscore}.rb"
+ end.compact.pop
+ require job_file
+ end
+
def add_job_source(name)
raise "Unknown source #{name} for job" unless @job.methods.include? name.symbolize
@job_sources.add_subject(name, @job.send(name.symbolize))
@job.send(name.symbolize).empty_stub_df
end
@@ -394,21 +399,10 @@
vector_name = fields[field_name].field_name
i = 0
@data_subject.df[vector_name].recode! { |v| i += 1 }
end
- def mock_extractor(filestore)
- extractor = class << @data_subject.extractor; self; end
-
- extractor.send(:define_method, :all_entries, ->() { filestore.sftp_entries })
- extractor.send(:define_method, :download, ->(to_download) { to_download.map { |e| e.name } })
- end
-
- def extract
- @data_subject.extractor.extract
- end
-
def csv_options
@data_subject.csv_options
end
end
@@ -553,80 +547,9 @@
@table.hashes.reduce({}) do |h, row|
row.each do |k,v|
(h[k.symbolize] ||= []) << v
end
h
- end
- end
- end
-
-
- class Filestore
- def initialize
- @files = []
- @delivered = {}
- end
-
- attr_reader :sftp_entries
-
- def pattern(pattern)
- @pattern = pattern
- end
-
- def anti_pattern(pattern)
- @pattern = /^ThisBetterNeverMatchAnythingOrIWillShootYou\d{8}Times$/
- end
-
- def delivered_since(date_time)
- @delivered = { :since => date_time }
- end
-
- def delivered_before(date_time)
- @delivered = { :before => date_time }
- end
-
- def latest
- @files.max_by { |f| f[:attributes][:createdtime] }[:name]
- end
-
- def generate
- psuedorand = Random.new(4985674985672348954987589429)
-
- generate_files_with_pattern
- @files.map! do |file|
- date_method = @delivered.keys.first
- if date_method == :since
- file[:attributes][:createdtime] = @delivered[:since] + 10 + psuedorand.rand * 100
- elsif date_method == :before
- file[:attributes][:createdtime] = @delivered[:since] - 10 - psuedorand.rand * 100
- else
- file[:attributes][:createdtime] = Time.now - 10 - psuedorand.rand * 100
- end
- file
- end
- end
-
- def sftp_entries
- @files.map do |file|
- Net::SFTP::Protocol::V04::Name.new(
- file[:name],
- Net::SFTP::Protocol::V04::Attributes.new(createtime: file[:attributes][:createdtime])
- )
- end
- end
-
- private
-
- def generate_files_with_pattern
- filenames = 1.upto(5).map { |f| @pattern.random_example }.uniq
-
- @files = filenames.map do |fname|
- {
- name: fname,
- attributes: {
- createdtime: nil
- }
- }
end
end
end
end