Class: SpecGuard
- Inherits:
-
Object
show all
- Defined in:
- lib/extensions/mspec/mspec/guards/guard.rb
Direct Known Subclasses
BackgroundGuard, CompliantOnGuard, ConflictsGuard, EndianGuard, ExtensionsGuard, FeatureGuard, NonComplianceGuard, NotCompliantOnGuard, PlatformGuard, QuarantineGuard, RunnerGuard, SpecifiedOnGuard, SuperUserGuard, SupportedGuard, TTYGuard, UnspecifiedGuard, UserGuard, VersionGuard
Constant Summary
collapse
- @@ruby_version_override =
nil
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ SpecGuard
Returns a new instance of SpecGuard.
72
73
74
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 72
def initialize(*args)
self.parameters = @args = args
end
|
Instance Attribute Details
Returns the value of attribute name.
70
71
72
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 70
def name
@name
end
|
#parameters ⇒ Object
Returns the value of attribute parameters.
70
71
72
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 70
def parameters
@parameters
end
|
Class Method Details
10
11
12
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 10
def self.clear
@report = nil
end
|
.clear_guards ⇒ Object
30
31
32
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 30
def self.clear_guards
@guards = []
end
|
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 14
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
|
26
27
28
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 26
def self.guards
@guards ||= []
end
|
6
7
8
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 6
def self.report
@report ||= Hash.new { |h,k| h[k] = [] }
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"
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 52
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 ⇒ Object
40
41
42
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 40
def self.ruby_version_override
@@ruby_version_override
end
|
.ruby_version_override=(version) ⇒ Object
36
37
38
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 36
def self.ruby_version_override=(version)
@@ruby_version_override = version
end
|
Instance Method Details
#===(other) ⇒ Object
93
94
95
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 93
def ===(other)
true
end
|
#add(example) ⇒ Object
110
111
112
113
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 110
def add(example)
record example.description
MSpec.retrieve(:formatter).tally.counter.guards!
end
|
#implementation?(*args) ⇒ Boolean
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 120
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/
else
false
end
end
end
|
#match? ⇒ Boolean
171
172
173
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 171
def match?
implementation?(*@args) or platform?(*@args)
end
|
#os?(*oses) ⇒ Boolean
163
164
165
166
167
168
169
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 163
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
|
149
150
151
152
153
154
155
156
157
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 149
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) ⇒ Object
106
107
108
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 106
def record(description)
SpecGuard.report[report_key] << description
end
|
#report_key ⇒ Object
102
103
104
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 102
def report_key
"#{name} #{parameters.join(", ")}"
end
|
#reporting? ⇒ Boolean
97
98
99
100
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 97
def reporting?
MSpec.mode?(:report) or
(MSpec.mode?(:report_on) and SpecGuard.guards.include?(name))
end
|
#standard? ⇒ Boolean
141
142
143
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 141
def standard?
implementation? :ruby
end
|
#windows?(sym, key) ⇒ Boolean
145
146
147
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 145
def windows?(sym, key)
sym == :windows && !key.match(/(mswin|mingw)/).nil?
end
|
#wordsize?(size) ⇒ Boolean
159
160
161
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 159
def wordsize?(size)
size == 8 * 1.size
end
|
#yield?(invert = false) ⇒ Boolean
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/extensions/mspec/mspec/guards/guard.rb', line 76
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
|