blob: 4f1df1cabe798d9d9ed6b4c5986830477d0c530a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
require 'mspec/guards/guard'
class FeatureGuard < SpecGuard
def self.enabled?(*features)
new(*features).match?
end
def match?
@parameters.all? { |f| MSpec.feature_enabled? f }
end
end
# Provides better documentation in the specs by
# naming sets of features that work together as
# a whole. Examples include :encoding, :fiber,
# :continuation, :fork.
#
# Usage example:
#
# with_feature :encoding do
# # specs for a method that provides aspects
# # of the encoding feature
# end
#
# Multiple features must all be enabled for the
# guard to run:
#
# with_feature :one, :two do
# # these specs will run if features :one AND
# # :two are enabled.
# end
#
# The implementation must explicitly enable a feature
# by adding code like the following to the .mspec
# configuration file:
#
# MSpec.enable_feature :encoding
#
def with_feature(*features, &block)
FeatureGuard.new(*features).run_if(:with_feature, &block)
end
MSpecEnv.class_eval do
def without_feature(*features, &block)
FeatureGuard.new(*features).run_unless(:without_feature, &block)
end
end
|