Class: Spark::Rake::SpeckTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/spark/rake/speck_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :specks, batteries = Array.new) {|_self| ... } ⇒ SpeckTask

Returns a new instance of SpeckTask.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spark/rake/speck_task.rb', line 14

def initialize name = :specks, batteries = Array.new
  @name = name
  @batteries = batteries.is_a?(Array) ? batteries : [batteries]
  @files = []
  @description = "Recursively runs all unbound Specks"
  
  yield self if block_given?
  @files << 'specifications/**/*_specs.rb' if @files.empty?
  
  self.files += ENV['SPECK_FILES'].split(/[ ,]/) if ENV['SPECK_FILES']
  
  define
end

Instance Attribute Details

#batteriesObject

Returns the value of attribute batteries.



12
13
14
# File 'lib/spark/rake/speck_task.rb', line 12

def batteries
  @batteries
end

#descriptionObject

Returns the value of attribute description.



10
11
12
# File 'lib/spark/rake/speck_task.rb', line 10

def description
  @description
end

#filesObject

Returns the value of attribute files.



11
12
13
# File 'lib/spark/rake/speck_task.rb', line 11

def files
  @files
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/spark/rake/speck_task.rb', line 9

def name
  @name
end

Instance Method Details

#defineObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/spark/rake/speck_task.rb', line 28

def define
  desc @description
  task @name do
    # TODO: AND SUDDENLY, UGLY CODES! KILOBYTES OF THEM!
    [@files].flatten.map {|p| p.include?("*") ? Dir[p] : p }.flatten
      .each {|f| require File.expand_path(f) }
    
    targets = @batteries.empty? ? Speck::unbound : @batteries
    checks = targets.inject(Array.new) do |acc, target|
      puts '-~- ' * 10 + '*' + ' -~-' * 10 if targets.size > 1
      target = target.call if target.respond_to? :call
      acc << Spark.playback(target)
    end
    puts '-~- ' * 10 + '*' + ' -~-' * 10 if targets.size > 1
    
    if targets.size == 0
      puts 'No specifications found.'
      exit 1
    end
    
    exit(1) if checks.map {|c| c[:failed] ? c[:failed].size : 0 }
      .inject {|acc,e| acc + e } > 0
  end
end