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



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

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
35
36
# 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
    # RJS the line below is very confusing and looks like a dupe of the line below it -- is it dead code or does it serve a purpose?
    behaviours_to_run.size == 0 && Micronaut.configuration.run_all_when_everything_filtered?
    if @behaviours_to_run.size == 0 && Micronaut.configuration.run_all_when_everything_filtered?
      puts "No behaviours 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



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

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



50
51
52
53
54
# File 'lib/micronaut/world.rb', line 50

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



56
57
58
# File 'lib/micronaut/world.rb', line 56

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

#total_examples_to_runObject



38
39
40
# File 'lib/micronaut/world.rb', line 38

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