Parent

Files

Class/Module Index [+]

Quicksearch

SpecGuard

Attributes

name[RW]
parameters[RW]

Public Class Methods

clear() click to toggle source
# File lib/mspec/guards/guard.rb, line 11
def self.clear
  @report = nil
end
clear_guards() click to toggle source
# File lib/mspec/guards/guard.rb, line 31
def self.clear_guards
  @guards = []
end
finish() click to toggle source
# File lib/mspec/guards/guard.rb, line 15
def self.finish
  report.keys.sort.each do |key|
    desc = report[key]
    size = desc.size
    spec = size == 1 ? "spec" : "specs"
    print "\n\n#{size} #{spec} omitted by guard: #{key}:\n"
    desc.each { |description| print "\n", description; }
  end

  print "\n\n"
end
guards() click to toggle source
# File lib/mspec/guards/guard.rb, line 27
def self.guards
  @guards ||= []
end
new(*args) click to toggle source
# File lib/mspec/guards/guard.rb, line 73
def initialize(*args)
  self.parameters = @args = args
end
report() click to toggle source
# File lib/mspec/guards/guard.rb, line 7
def self.report
  @report ||= Hash.new { |h,k| h[k] = [] }
end
ruby_version(which = :minor) click to toggle source

Returns a partial Ruby version string based on which. For example, if RUBY_VERSION = 8.2.3 and RUBY_PATCHLEVEL = 71:

:major  => "8"
:minor  => "8.2"
:tiny   => "8.2.3"
:teeny  => "8.2.3"
:full   => "8.2.3.71"
# File lib/mspec/guards/guard.rb, line 53
def self.ruby_version(which = :minor)
  case which
  when :major
    n = 1
  when :minor
    n = 2
  when :tiny, :teeny
    n = 3
  else
    n = 4
  end

  patch = RUBY_PATCHLEVEL.to_i
  patch = 0 if patch < 0
  version = "#{ruby_version_override || RUBY_VERSION}.#{patch}"
  version.split('.')[0,n].join('.')
end
ruby_version_override() click to toggle source
# File lib/mspec/guards/guard.rb, line 41
def self.ruby_version_override
  @@ruby_version_override
end
ruby_version_override=(version) click to toggle source
# File lib/mspec/guards/guard.rb, line 37
def self.ruby_version_override=(version)
  @@ruby_version_override = version
end

Public Instance Methods

===(other) click to toggle source
# File lib/mspec/guards/guard.rb, line 94
def ===(other)
  true
end
add(example) click to toggle source
# File lib/mspec/guards/guard.rb, line 111
def add(example)
  record example.description
  MSpec.retrieve(:formatter).tally.counter.guards!
end
implementation?(*args) click to toggle source
# File lib/mspec/guards/guard.rb, line 121
def implementation?(*args)
  args.any? do |name|
    !!case name
    when :rubinius
      RUBY_NAME =~ /^rbx/
    when :ruby
      RUBY_NAME =~ /^ruby/
    when :jruby
      RUBY_NAME =~ /^jruby/
    when :ironruby
      RUBY_NAME =~ /^ironruby/
    when :macruby
      RUBY_NAME =~ /^macruby/
    when :maglev
      RUBY_NAME =~ /^maglev/
    when :topaz
      RUBY_NAME =~ /^topaz/
    else
      false
    end
  end
end
match?() click to toggle source
# File lib/mspec/guards/guard.rb, line 174
def match?
  implementation?(*@args) or platform?(*@args)
end
os?(*oses) click to toggle source
# File lib/mspec/guards/guard.rb, line 166
def os?(*oses)
  oses.any? do |os|
    host_os = RbConfig::CONFIG['host_os'] || RUBY_PLATFORM
    host_os.downcase!
    host_os.match(os.to_s) || windows?(os, host_os)
  end
end
platform?(*args) click to toggle source
# File lib/mspec/guards/guard.rb, line 152
def platform?(*args)
  args.any? do |platform|
    if platform != :java && RUBY_PLATFORM.match('java') && os?(platform)
      true
    else
      RUBY_PLATFORM.match(platform.to_s) || windows?(platform, RUBY_PLATFORM)
    end
  end
end
record(description) click to toggle source
# File lib/mspec/guards/guard.rb, line 107
def record(description)
  SpecGuard.report[report_key] << description
end
report_key() click to toggle source
# File lib/mspec/guards/guard.rb, line 103
def report_key
  "#{name} #{parameters.join(", ")}"
end
reporting?() click to toggle source
# File lib/mspec/guards/guard.rb, line 98
def reporting?
  MSpec.mode?(:report) or
    (MSpec.mode?(:report_on) and SpecGuard.guards.include?(name))
end
standard?() click to toggle source
# File lib/mspec/guards/guard.rb, line 144
def standard?
  implementation? :ruby
end
unregister() click to toggle source
# File lib/mspec/guards/guard.rb, line 116
def unregister
  MSpec.unguard
  MSpec.unregister :add, self
end
windows?(sym, key) click to toggle source
# File lib/mspec/guards/guard.rb, line 148
def windows?(sym, key)
  sym == :windows && !key.match(/(mswin|mingw)/).nil?
end
wordsize?(size) click to toggle source
# File lib/mspec/guards/guard.rb, line 162
def wordsize?(size)
  size == 8 * 1.size
end
yield?(invert=false) click to toggle source
# File lib/mspec/guards/guard.rb, line 77
def yield?(invert=false)
  return true if MSpec.mode? :unguarded

  allow = match? ^ invert

  if not allow and reporting?
    MSpec.guard
    MSpec.register :finish, SpecGuard
    MSpec.register :add,    self
    return true
  elsif MSpec.mode? :verify
    return true
  end

  allow
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.