Class: Micronaut::World

Inherits:
Object show all
Defined in:
lib/micronaut/world.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorld

Returns a new instance of World.



7
8
9
# File 'lib/micronaut/world.rb', line 7

def initialize
  @behaviours = []
end

Instance Attribute Details

#behavioursObject (readonly)

Returns the value of attribute behaviours.



5
6
7
# File 'lib/micronaut/world.rb', line 5

def behaviours
  @behaviours
end

Instance Method Details

#apply_condition(filter_on, filter, metadata) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/micronaut/world.rb', line 79

def apply_condition(filter_on, filter, )
  return false if .nil?

  case filter
  when Hash
    filter.all? { |k, v| apply_condition(k, v, [filter_on]) }
  when Regexp
    [filter_on] =~ filter
  when Proc
    filter.call([filter_on]) rescue false
  else
    [filter_on] == filter
  end
end

#apply_exclusion_filters(collection, conditions = {}) ⇒ Object



75
76
77
# File 'lib/micronaut/world.rb', line 75

def apply_exclusion_filters(collection, conditions={})
  find(collection, :negative, conditions)
end

#apply_inclusion_filters(collection, conditions = {}) ⇒ Object



71
72
73
# File 'lib/micronaut/world.rb', line 71

def apply_inclusion_filters(collection, conditions={})
  find(collection, :positive, conditions)
end

#behaviours_to_runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/micronaut/world.rb', line 19

def behaviours_to_run
  return @behaviours_to_run if @behaviours_to_run
  
  if filter || exclusion_filter
    @behaviours_to_run = filter_behaviours
    if @behaviours_to_run.size == 0 && Micronaut.configuration.run_all_when_everything_filtered?
      puts "No examples were matched by #{filter.inspect}, running all"
      # reset the behaviour list to all behaviours, and add back all examples
      @behaviours_to_run = @behaviours
      @behaviours.each { |b| b.examples_to_run.replace(b.examples) }
    else
      Micronaut.configuration.output.puts "Run filtered using #{filter.inspect}"          
    end
  else
    @behaviours_to_run = @behaviours
    @behaviours.each { |b| b.examples_to_run.replace(b.examples) }
  end      

  @behaviours_to_run
end

#exclusion_filterObject



15
16
17
# File 'lib/micronaut/world.rb', line 15

def exclusion_filter
  Micronaut.configuration.exclusion_filter
end

#filterObject



11
12
13
# File 'lib/micronaut/world.rb', line 11

def filter
  Micronaut.configuration.filter
end

#filter_behavioursObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/micronaut/world.rb', line 44

def filter_behaviours
  behaviours.inject([]) do |list_of_behaviors, _behavior|
    examples = _behavior.examples
    examples = apply_exclusion_filters(examples, exclusion_filter) if exclusion_filter
    examples = apply_inclusion_filters(examples, filter) if filter
    examples.uniq!
    _behavior.examples_to_run.replace(examples)
    if examples.empty?
      list_of_behaviors << nil
    else
      list_of_behaviors << _behavior
    end
  end.compact
end

#find(collection, type_of_filter = :positive, conditions = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/micronaut/world.rb', line 59

def find(collection, type_of_filter=:positive, conditions={})
  negative = type_of_filter != :positive
  
  collection.select do |item|
    # negative conditions.any?, positive conditions.all? ?????
    result = conditions.all? do |filter_on, filter| 
               apply_condition(filter_on, filter, item.)
             end
    negative ? !result : result
  end
end

#total_examples_to_runObject



40
41
42
# File 'lib/micronaut/world.rb', line 40

def total_examples_to_run
  @total_examples_to_run ||= behaviours_to_run.inject(0) { |sum, b| sum += b.examples_to_run.size }
end