Class: SpecGuard
Direct Known Subclasses
BackgroundGuard, BigEndianGuard, CompliantOnGuard, ConflictsGuard, ExtensionsGuard, LittleEndianGuard, NonComplianceGuard, NotCompliantOnGuard, PlatformGuard, QuarantineGuard, RunnerGuard, SuperUserGuard, SupportedGuard, TTYGuard, VersionGuard
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ SpecGuard
Returns a new instance of SpecGuard.
53
54
55
|
# File 'lib/mspec/guards/guard.rb', line 53
def initialize(*args)
@args = args
end
|
Class Method Details
18
19
20
|
# File 'lib/mspec/guards/guard.rb', line 18
def self.finish
print "\n#{self.class}\n#{@tally.format}\n"
end
|
5
6
7
8
9
10
11
12
|
# File 'lib/mspec/guards/guard.rb', line 5
def self.register
unless @registered
@tally = TallyAction.new
@tally.register
MSpec.register :finish, self
@registered = true
end
end
|
.ruby_version(which = :minor) ⇒ Object
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"
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/mspec/guards/guard.rb', line 30
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}.#{patch}"
version.split('.')[0,n].join('.')
end
|
.unregister ⇒ Object
14
15
16
|
# File 'lib/mspec/guards/guard.rb', line 14
def self.unregister
@tally.unregister if @tally
end
|
.windows?(key = RUBY_PLATFORM) ⇒ Boolean
48
49
50
|
# File 'lib/mspec/guards/guard.rb', line 48
def self.windows?(key = RUBY_PLATFORM)
!!key.match(/(mswin|mingw)/)
end
|
Instance Method Details
#===(other) ⇒ Object
72
73
74
|
# File 'lib/mspec/guards/guard.rb', line 72
def ===(other)
true
end
|
#after(state) ⇒ Object
79
80
|
# File 'lib/mspec/guards/guard.rb', line 79
def after(state)
end
|
#before(state) ⇒ Object
76
77
|
# File 'lib/mspec/guards/guard.rb', line 76
def before(state)
end
|
#implementation?(*args) ⇒ Boolean
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/mspec/guards/guard.rb', line 89
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/
else
false
end
end
end
|
#match? ⇒ Boolean
139
140
141
|
# File 'lib/mspec/guards/guard.rb', line 139
def match?
implementation?(*@args) or platform?(*@args)
end
|
#os?(*oses) ⇒ Boolean
130
131
132
133
134
135
136
137
|
# File 'lib/mspec/guards/guard.rb', line 130
def os?(*oses)
require 'rbconfig'
oses.any? do |os|
host_os = Config::CONFIG['host_os'] || RUBY_PLATFORM
host_os.downcase!
host_os.match(os.to_s) || windows?(os, host_os)
end
end
|
116
117
118
119
120
121
122
123
124
|
# File 'lib/mspec/guards/guard.rb', line 116
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
|
#standard? ⇒ Boolean
108
109
110
|
# File 'lib/mspec/guards/guard.rb', line 108
def standard?
implementation? :ruby
end
|
#windows?(sym, key) ⇒ Boolean
112
113
114
|
# File 'lib/mspec/guards/guard.rb', line 112
def windows?(sym, key)
sym == :windows && SpecGuard.windows?(key)
end
|
#wordsize?(size) ⇒ Boolean
126
127
128
|
# File 'lib/mspec/guards/guard.rb', line 126
def wordsize?(size)
size == 8 * 1.size
end
|
#yield?(invert = false) ⇒ Boolean
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/mspec/guards/guard.rb', line 57
def yield?(invert=false)
if MSpec.mode? :unguarded
return true
elsif MSpec.mode? :report
self.class.register
MSpec.register :before, self
return true
elsif MSpec.mode? :verify
self.class.register
MSpec.register :after, self
return true
end
return match? ^ invert
end
|