Class: Rake::RubyBreakerTestTask

Inherits:
TestTask
  • Object
show all
Defined in:
lib/rubybreaker/task.rb

Overview

This class can be used as a replacement for Rake::TestTask. It is a subclass of Rake::TestTask and maintains additional information for running RubyBreaker as a Rake test task.

For example, the following shows how to run RubyBreaker in a test task:

desc “Run testtask test” Rake::RubyBreakerTestTask.new(:“testtask_test”) do |t|

t.libs << "lib"
t.test_files = ["test/testtask/tc_testtask.rb"]
t.break = ["SampleClassA"]

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(taskname = "", *args, &blk) ⇒ RubyBreakerTestTask

This overrides the testtask’s constructor. In addition to the original behavior, it keeps track of RubyBreaker options and store them in a yaml file.



42
43
44
45
46
47
48
49
50
51
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rubybreaker/task.rb', line 42

def initialize(taskname="", *args, &blk)

  # Initialize extra instance variables
  @rubybreaker_opts = []
  @break = nil
  @check = nil

  # Call the original constructor first
  super(taskname, *args, &blk)

  # Parse the RubyBreaker options
  case @rubybreaker_opts
  when Array
    opts = @rubybreaker_opts
  when String
    opts = @rubybreaker_opts.split(" ").select {|v| v != ""}
  else
    opts = []
  end

  # Construct the task configuration hash
  config = {
    :name => taskname,
    :rubybreaker_opts => opts,
    :break => [], # Set doesn't work well with YAML; just use an array
    :check => [],
    :test_files => @test_files,
  }

  # This allows a bulk declaration of Breakable modules/classes
  @break.each { |b| config[:break] << b } if @break
  @check.each { |c| config[:check] << c } if @check

  # This code segment is a clever way to store yaml data in a ruby file
  # that reads its own yaml data after __END__ when loaded.
  code_data = <<-EOS
require "yaml"
f = File.new(__FILE__, "r")
while !(f.readline.match("^__END__.*$"))
  # do nothing
end
data = f.read
$__rubybreaker_task = YAML.load(data)
__END__
#{YAML.dump(config)}
  EOS

  tmp_path = ""
  # Tests are run different processes, so we must export this
  # information to an external yaml file.
  f = Tempfile.new(["#{taskname}",".rb"]) 
  tmp_path = f.path
  f.write(code_data)
  f.close()

  # Inject the -r option to load this yaml file
  if @ruby_opts && @ruby_opts.empty?
    @ruby_opts << "-r" << tmp_path
  else
    @ruby_opts = ["-r", tmp_path]
  end

  return self
end

Instance Attribute Details

#breakObject

List of modules/classes to break



25
26
27
# File 'lib/rubybreaker/task.rb', line 25

def break
  @break
end

#checkObject

List of modules/classes to check



28
29
30
# File 'lib/rubybreaker/task.rb', line 28

def check
  @check
end

#rubybreaker_optsObject

RubyBreaker options



31
32
33
# File 'lib/rubybreaker/task.rb', line 31

def rubybreaker_opts
  @rubybreaker_opts
end

Instance Method Details

#breakableObject

DEPRECATED accessor override



34
# File 'lib/rubybreaker/task.rb', line 34

def breakable(); @break end

#breakable=(*args) ⇒ Object

DEPRECATED accessor override



37
# File 'lib/rubybreaker/task.rb', line 37

def breakable=(*args); self.break(*args) end