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



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

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

#behaviours_to_runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/micronaut/world.rb', line 15

def behaviours_to_run
  return @behaviours_to_run if @behaviours_to_run
  
  if 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

#filterObject



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

def filter
  Micronaut.configuration.filter
end

#filter_behavioursObject



40
41
42
43
44
45
46
# File 'lib/micronaut/world.rb', line 40

def filter_behaviours
  behaviours.inject([]) do |list, b|
    b.examples_to_run.replace(find(b.examples, filter).uniq)
    # Do not add behaviours with 0 examples to run
    list << (b.examples_to_run.size == 0 ? nil : b)
  end.compact
end

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



48
49
50
51
52
# File 'lib/micronaut/world.rb', line 48

def find(collection, conditions={})
  collection.select do |item|
    conditions.all? { |filter_on, filter| apply_condition(filter_on, filter, item.) }
  end
end

#find_behaviours(conditions = {}) ⇒ Object



54
55
56
# File 'lib/micronaut/world.rb', line 54

def find_behaviours(conditions={})
  find(behaviours, conditions)
end

#total_examples_to_runObject



36
37
38
# File 'lib/micronaut/world.rb', line 36

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