Class: Micronaut::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/micronaut/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) {|_self| ... } ⇒ RakeTask

Returns a new instance of RakeTask.

Yields:

  • (_self)

Yield Parameters:



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/micronaut/rake_task.rb', line 40

def initialize(*args)
  @name = args.shift || :examples
  @pattern, @rcov_opts = nil, nil
  @warning, @rcov = false, false
  @ruby_opts = []
  @fail_on_error = true

  yield self if block_given?
  @pattern ||= 'examples/**/*_example.rb'
  define
end

Instance Attribute Details

#fail_on_errorObject

Whether or not to fail Rake when an error occurs (typically when examples fail). Defaults to true.



25
26
27
# File 'lib/micronaut/rake_task.rb', line 25

def fail_on_error
  @fail_on_error
end

#failure_messageObject

A message to print to stderr when there are failures.



28
29
30
# File 'lib/micronaut/rake_task.rb', line 28

def failure_message
  @failure_message
end

#nameObject

Name of task. (default is :examples)



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

def name
  @name
end

#patternObject

Glob pattern to match example files. (default is ‘examples/*/_example.rb’)



18
19
20
# File 'lib/micronaut/rake_task.rb', line 18

def pattern
  @pattern
end

#rcovObject

Use rcov for code coverage? defaults to false



35
36
37
# File 'lib/micronaut/rake_task.rb', line 35

def rcov
  @rcov
end

#rcov_optsObject

The options to pass to rcov. Defaults to blank



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

def rcov_opts
  @rcov_opts
end

#ruby_optsObject

Array of commandline options to pass to ruby. Defaults to [].



21
22
23
# File 'lib/micronaut/rake_task.rb', line 21

def ruby_opts
  @ruby_opts
end

#verboseObject

Use verbose output. If this is set to true, the task will print the executed spec command to stdout. Defaults to false.



32
33
34
# File 'lib/micronaut/rake_task.rb', line 32

def verbose
  @verbose
end

#warningObject

If true, requests that the specs be run with the warning flag set. E.g. warning=true implies “ruby -w” used to run the specs. Defaults to false.



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

def warning
  @warning
end

Instance Method Details

#defineObject

:nodoc:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/micronaut/rake_task.rb', line 52

def define # :nodoc:
  actual_name = Hash === name ? name.keys.first : name
  desc("Run all examples") unless ::Rake.application.last_comment

  task name do
    RakeFileUtils.send(:verbose, verbose) do
      if examples_to_run.empty?
        puts "No examples matching #{pattern} could be found"
      else
        cmd_parts = [rcov ? 'rcov' : RUBY]
        cmd_parts += rcov ? [rcov_opts] : ruby_opts
        cmd_parts << "-w" if warning
        cmd_parts += examples_to_run.collect { |fn| %["#{fn}"] }
        cmd = cmd_parts.join(" ")
        puts cmd if verbose
        unless system(cmd)
          STDERR.puts failure_message if failure_message
          raise("Command #{cmd} failed") if fail_on_error
        end
      end
    end
  end

  self
end

#examples_to_runObject

:nodoc:



78
79
80
# File 'lib/micronaut/rake_task.rb', line 78

def examples_to_run # :nodoc:
  FileList[ pattern ].to_a
end