class Fudge::Tasks::Rspec

Allow use of RSpec as a task

Private Instance Methods

check_for() click to toggle source
Calls superclass method
# File lib/fudge/tasks/rspec.rb, line 33
def check_for
  if coverage
    [check_regex, method(:coverage_checker)]
  else
    super
  end
end
check_regex() click to toggle source
# File lib/fudge/tasks/rspec.rb, line 20
def check_regex
  Regexp.union(coverage_regex, pre_conditions_regex)
end
cmd(options={}) click to toggle source
# File lib/fudge/tasks/rspec.rb, line 24
def cmd(options={})
  self.arguments = 'spec/' if (arguments.nil? || arguments.empty?)
  bundle_cmd("rspec#{tty_options} #{arguments}", options)
end
color() click to toggle source
# File lib/fudge/tasks/rspec.rb, line 67
def color
  options[:color]
end
coverage() click to toggle source
# File lib/fudge/tasks/rspec.rb, line 63
def coverage
  options[:coverage]
end
coverage_checker(matches) click to toggle source

will check if the expected coverage is met, but first will test for pre conditions to pass

# File lib/fudge/tasks/rspec.rb, line 43
def coverage_checker(matches)
  matches = matches.to_s
  if matches.match(pre_conditions_regex)
    true
  else
    test_coverage_threshold(matches)
  end
end
coverage_regex() click to toggle source

Expression to check for coverage

# File lib/fudge/tasks/rspec.rb, line 16
def coverage_regex
  /((\d+\.\d+)%\) covered)/
end
pre_conditions_regex() click to toggle source

Preconditions to check for coverage, that if not met make the test pass for example, if no tests exist, no need to fail

# File lib/fudge/tasks/rspec.rb, line 11
def pre_conditions_regex
   /[^\d](0 examples, 0 failures)/ # no tests exist
end
test_coverage_threshold(matches) click to toggle source

checks the matched string from the console output, to see if the number for the coverage is greater or equal than the expected coverage

# File lib/fudge/tasks/rspec.rb, line 55
def test_coverage_threshold(matches)
  if matches.to_f >= coverage
    true
  else
    'Insufficient Coverage.'
  end
end
tty_options() click to toggle source
# File lib/fudge/tasks/rspec.rb, line 29
def tty_options
  ' --tty' unless color == false
end