Class: SpecGuard
Direct Known Subclasses
BigEndianGuard, ComplianceGuard, ConflictsGuard, ExtensionsGuard, LittleEndianGuard, NonComplianceGuard, PlatformGuard, QuarantineGuard, RunnerGuard, SuperUserGuard, SupportedGuard, VersionGuard
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ SpecGuard
Returns a new instance of SpecGuard.
22
23
24
|
# File 'lib/mspec/guards/guard.rb', line 22
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
|
.unregister ⇒ Object
14
15
16
|
# File 'lib/mspec/guards/guard.rb', line 14
def self.unregister
@tally.unregister if @tally
end
|
Instance Method Details
#===(other) ⇒ Object
39
40
41
|
# File 'lib/mspec/guards/guard.rb', line 39
def ===(other)
true
end
|
#after(state) ⇒ Object
46
47
|
# File 'lib/mspec/guards/guard.rb', line 46
def after(state)
end
|
#before(state) ⇒ Object
43
44
|
# File 'lib/mspec/guards/guard.rb', line 43
def before(state)
end
|
#implementation?(*args) ⇒ Boolean
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/mspec/guards/guard.rb', line 56
def implementation?(*args)
args.any? do |name|
!!case name
when :rbx, :rubinius
RUBY_NAME =~ /^rbx/
when :ruby
RUBY_NAME =~ /^ruby/
when :ruby18
RUBY_NAME =~ /^ruby(1.8)?/ and RUBY_VERSION =~ /^1.8/
when :ruby19
RUBY_NAME =~ /^ruby(1.9)?/ and RUBY_VERSION =~ /^1.9/
when :jruby
RUBY_NAME =~ /^jruby/
when :ironruby, :ir
RUBY_NAME =~ /^ironruby/
else
false
end
end
end
|
#match? ⇒ Boolean
104
105
106
|
# File 'lib/mspec/guards/guard.rb', line 104
def match?
implementation?(*@args) or platform?(*@args)
end
|
#os?(*oses) ⇒ Boolean
95
96
97
98
99
100
101
102
|
# File 'lib/mspec/guards/guard.rb', line 95
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
|
81
82
83
84
85
86
87
88
89
|
# File 'lib/mspec/guards/guard.rb', line 81
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
|
#windows?(sym, key) ⇒ Boolean
77
78
79
|
# File 'lib/mspec/guards/guard.rb', line 77
def windows?(sym, key)
sym == :windows && !!key.match(/(mswin|mingw)/)
end
|
#wordsize?(size) ⇒ Boolean
91
92
93
|
# File 'lib/mspec/guards/guard.rb', line 91
def wordsize?(size)
size == 8 * 1.size
end
|
#yield?(invert = false) ⇒ Boolean
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/mspec/guards/guard.rb', line 26
def yield?(invert=false)
if MSpec.report_mode?
self.class.register
MSpec.register :before, self
return true
elsif MSpec.verify_mode?
self.class.register
MSpec.register :after, self
return true
end
return match? ^ invert
end
|