Module: KnowsAboutDataDependencies

Defined in:
lib/cucumber/blinkbox/data_dependencies.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object


4
5
6
7
8
9
10
# File 'lib/cucumber/blinkbox/data_dependencies.rb', line 4

def self.extended(base)
  base.instance_eval do
    path = TEST_CONFIG["data.yml"] || "config/data.yml"
    raise "The data dependencies file does not exist at #{path}" unless File.exist?(path)
    @data_dependencies = YAML.load_file(path)
  end
end

Instance Method Details

#data_for_a(object, which: nil, but_isnt: nil, instances: nil) ⇒ Object

Raises:

  • (ArgumentError)

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cucumber/blinkbox/data_dependencies.rb', line 12

def data_for_a(object, which: nil, but_isnt: nil, instances: nil)
  raise ArgumentError, "Please specify a condition using `which:`" if which.nil?
  data = @data_dependencies[object.to_s][which] rescue nil

  if data.respond_to? :sample
    data.delete_if { |item| item == but_isnt } if but_isnt
    if instances
      pending "Test error: There are not enough examples defined for a #{object} which #{which}" unless data.size >= instances
      data = data.sample(instances)
    else
      data = data.sample
    end
  end

  pending "Test error: There is no data dependency defined for a #{object} which #{which}" unless data
  data
end