mspec 1.5.9 → 1.5.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/mspec/commands/mspec-ci.rb +5 -1
- data/lib/mspec/commands/mspec-run.rb +8 -5
- data/lib/mspec/guards/background.rb +2 -0
- data/lib/mspec/guards/bug.rb +5 -1
- data/lib/mspec/guards/compliance.rb +10 -0
- data/lib/mspec/guards/conflict.rb +2 -0
- data/lib/mspec/guards/endian.rb +4 -0
- data/lib/mspec/guards/extensions.rb +2 -0
- data/lib/mspec/guards/guard.rb +49 -25
- data/lib/mspec/guards/noncompliance.rb +2 -0
- data/lib/mspec/guards/platform.rb +5 -0
- data/lib/mspec/guards/quarantine.rb +2 -0
- data/lib/mspec/guards/runner.rb +4 -0
- data/lib/mspec/guards/superuser.rb +2 -0
- data/lib/mspec/guards/support.rb +2 -0
- data/lib/mspec/guards/tty.rb +2 -0
- data/lib/mspec/guards/version.rb +3 -0
- data/lib/mspec/matchers.rb +1 -0
- data/lib/mspec/matchers/have_constant.rb +30 -0
- data/lib/mspec/matchers/method.rb +4 -3
- data/lib/mspec/matchers/stringsymboladapter.rb +8 -0
- data/lib/mspec/runner/actions/tally.rb +13 -3
- data/lib/mspec/runner/context.rb +8 -1
- data/lib/mspec/runner/mspec.rb +16 -0
- data/lib/mspec/utils/options.rb +10 -3
- data/lib/mspec/version.rb +1 -1
- data/spec/guards/background_spec.rb +15 -0
- data/spec/guards/bug_spec.rb +28 -10
- data/spec/guards/compliance_spec.rb +54 -0
- data/spec/guards/conflict_spec.rb +19 -0
- data/spec/guards/endian_spec.rb +26 -0
- data/spec/guards/extensions_spec.rb +20 -0
- data/spec/guards/guard_spec.rb +69 -52
- data/spec/guards/noncompliance_spec.rb +20 -0
- data/spec/guards/platform_spec.rb +26 -0
- data/spec/guards/quarantine_spec.rb +16 -0
- data/spec/guards/runner_spec.rb +26 -0
- data/spec/guards/superuser_spec.rb +13 -0
- data/spec/guards/support_spec.rb +20 -0
- data/spec/guards/tty_spec.rb +16 -0
- data/spec/guards/version_spec.rb +13 -0
- data/spec/matchers/have_constant_spec.rb +37 -0
- data/spec/matchers/stringsymboladapter_spec.rb +40 -0
- data/spec/runner/actions/tagpurge_spec.rb +1 -0
- data/spec/runner/actions/tally_spec.rb +64 -0
- data/spec/runner/context_spec.rb +24 -11
- data/spec/runner/formatters/html_spec.rb +1 -0
- data/spec/runner/mspec_spec.rb +31 -0
- data/spec/utils/options_spec.rb +59 -0
- metadata +6 -3
- data/spec/matchers/method_spec.rb +0 -36
@@ -1,10 +1,11 @@
|
|
1
|
-
require 'mspec/
|
1
|
+
require 'mspec/matchers/stringsymboladapter'
|
2
2
|
|
3
3
|
class MethodMatcher
|
4
|
+
include StringSymbolAdapter
|
5
|
+
|
4
6
|
def initialize(method, include_super=true)
|
5
7
|
@include_super = include_super
|
6
|
-
|
7
|
-
@method = version < 0 ? method.to_s : method
|
8
|
+
@method = convert_name method
|
8
9
|
end
|
9
10
|
|
10
11
|
def matches?(mod)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class Tally
|
2
|
-
attr_accessor :files, :examples, :expectations, :failures, :errors
|
2
|
+
attr_accessor :files, :examples, :expectations, :failures, :errors, :guards
|
3
3
|
|
4
4
|
def initialize
|
5
|
-
@files = @examples = @expectations = @failures = @errors = 0
|
5
|
+
@files = @examples = @expectations = @failures = @errors = @guards = 0
|
6
6
|
end
|
7
7
|
|
8
8
|
def files!(add=1)
|
@@ -25,6 +25,10 @@ class Tally
|
|
25
25
|
@errors += add
|
26
26
|
end
|
27
27
|
|
28
|
+
def guards!(add=1)
|
29
|
+
@guards += add
|
30
|
+
end
|
31
|
+
|
28
32
|
def file
|
29
33
|
pluralize files, "file"
|
30
34
|
end
|
@@ -45,8 +49,14 @@ class Tally
|
|
45
49
|
pluralize errors, "error"
|
46
50
|
end
|
47
51
|
|
52
|
+
def guard
|
53
|
+
pluralize guards, "guard"
|
54
|
+
end
|
55
|
+
|
48
56
|
def format
|
49
|
-
[ file, example, expectation, failure, error ]
|
57
|
+
results = [ file, example, expectation, failure, error ]
|
58
|
+
results << guard if [:report, :report_on, :verify].any? { |m| MSpec.mode? m }
|
59
|
+
results.join(", ")
|
50
60
|
end
|
51
61
|
|
52
62
|
alias_method :to_s, :format
|
data/lib/mspec/runner/context.rb
CHANGED
@@ -79,18 +79,23 @@ class ContextState
|
|
79
79
|
|
80
80
|
# Records before(:each) and before(:all) blocks.
|
81
81
|
def before(what, &block)
|
82
|
+
return if MSpec.guarded?
|
82
83
|
block ? @before[what].push(block) : @before[what]
|
83
84
|
end
|
84
85
|
|
85
86
|
# Records after(:each) and after(:all) blocks.
|
86
87
|
def after(what, &block)
|
88
|
+
return if MSpec.guarded?
|
87
89
|
block ? @after[what].unshift(block) : @after[what]
|
88
90
|
end
|
89
91
|
|
90
92
|
# Creates an ExampleState instance for the block and stores it
|
91
93
|
# in a list of examples to evaluate unless the example is filtered.
|
92
94
|
def it(desc, &block)
|
93
|
-
|
95
|
+
example = ExampleState.new(self, desc, block)
|
96
|
+
MSpec.actions :add, example
|
97
|
+
return if MSpec.guarded?
|
98
|
+
@examples << example
|
94
99
|
end
|
95
100
|
|
96
101
|
# Evaluates the block and resets the toplevel +ContextState+ to #parent.
|
@@ -108,6 +113,8 @@ class ContextState
|
|
108
113
|
# Injects the before/after blocks and examples from the shared
|
109
114
|
# describe block into this +ContextState+ instance.
|
110
115
|
def it_should_behave_like(desc)
|
116
|
+
return if MSpec.guarded?
|
117
|
+
|
111
118
|
unless state = MSpec.retrieve_shared(desc)
|
112
119
|
raise Exception, "Unable to find shared 'describe' for #{desc}"
|
113
120
|
end
|
data/lib/mspec/runner/mspec.rb
CHANGED
@@ -20,6 +20,7 @@ module MSpec
|
|
20
20
|
@current = nil
|
21
21
|
@modes = []
|
22
22
|
@shared = {}
|
23
|
+
@guarded = []
|
23
24
|
@exception = nil
|
24
25
|
@randomize = nil
|
25
26
|
@expectation = nil
|
@@ -74,6 +75,20 @@ module MSpec
|
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
78
|
+
# Guards can be nested, so a stack is necessary to know when we have
|
79
|
+
# exited the toplevel guard.
|
80
|
+
def self.guard
|
81
|
+
@guarded << true
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.unguard
|
85
|
+
@guarded.pop
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.guarded?
|
89
|
+
not @guarded.empty?
|
90
|
+
end
|
91
|
+
|
77
92
|
# Sets the toplevel ContextState to +state+.
|
78
93
|
def self.register_current(state)
|
79
94
|
store :current, state
|
@@ -161,6 +176,7 @@ module MSpec
|
|
161
176
|
# :load before a spec file is loaded
|
162
177
|
# :enter before a describe block is run
|
163
178
|
# :before before a single spec is run
|
179
|
+
# :add while a describe block is adding examples to run later
|
164
180
|
# :expectation before a 'should', 'should_receive', etc.
|
165
181
|
# :example after an example block is run, passed the block
|
166
182
|
# :exception after an exception is rescued
|
data/lib/mspec/utils/options.rb
CHANGED
@@ -360,6 +360,9 @@ class MSpecOptions
|
|
360
360
|
on("--unguarded", "Turn off all guards") do
|
361
361
|
MSpec.register_mode :unguarded
|
362
362
|
end
|
363
|
+
on("--no-ruby_bug", "Turn off the ruby_bug guard") do
|
364
|
+
MSpec.register_mode :no_ruby_bug
|
365
|
+
end
|
363
366
|
end
|
364
367
|
|
365
368
|
def randomize
|
@@ -401,13 +404,17 @@ class MSpecOptions
|
|
401
404
|
end
|
402
405
|
|
403
406
|
def verify
|
404
|
-
on("-
|
405
|
-
|
406
|
-
|
407
|
+
on("--report-on", "GUARD", "Report specs guarded by GUARD") do |g|
|
408
|
+
MSpec.register_mode :report_on
|
409
|
+
SpecGuard.guards << g.to_sym
|
407
410
|
end
|
408
411
|
on("-O", "--report", "Report guarded specs") do
|
409
412
|
MSpec.register_mode :report
|
410
413
|
end
|
414
|
+
on("-Y", "--verify",
|
415
|
+
"Verify that guarded specs pass and fail as expected") do
|
416
|
+
MSpec.register_mode :verify
|
417
|
+
end
|
411
418
|
end
|
412
419
|
|
413
420
|
def action_filters
|
data/lib/mspec/version.rb
CHANGED
@@ -5,6 +5,9 @@ describe Object, "#process_is_foreground" do
|
|
5
5
|
before :each do
|
6
6
|
MSpec.clear_modes
|
7
7
|
ScratchPad.clear
|
8
|
+
|
9
|
+
@guard = BackgroundGuard.new
|
10
|
+
BackgroundGuard.stub!(:new).and_return(@guard)
|
8
11
|
end
|
9
12
|
|
10
13
|
it "yields if MSpec.mode?(:background) is false" do
|
@@ -18,4 +21,16 @@ describe Object, "#process_is_foreground" do
|
|
18
21
|
process_is_foreground { ScratchPad.record :yield }
|
19
22
|
ScratchPad.recorded.should_not == :yield
|
20
23
|
end
|
24
|
+
|
25
|
+
it "sets the name of the guard to :process_is_foreground" do
|
26
|
+
process_is_foreground { ScratchPad.record :yield }
|
27
|
+
@guard.name.should == :process_is_foreground
|
28
|
+
end
|
29
|
+
|
30
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
31
|
+
@guard.should_receive(:unregister)
|
32
|
+
lambda do
|
33
|
+
process_is_foreground { raise Exception }
|
34
|
+
end.should raise_error(Exception)
|
35
|
+
end
|
21
36
|
end
|
data/spec/guards/bug_spec.rb
CHANGED
@@ -46,6 +46,12 @@ describe BugGuard, "#match? when #implementation? is 'ruby'" do
|
|
46
46
|
BugGuard.new("#1", "1.8").match?.should == true
|
47
47
|
BugGuard.new("#1", "1.8.6").match?.should == true
|
48
48
|
end
|
49
|
+
|
50
|
+
it "returns false when MSpec.mode?(:no_ruby_bug) is true" do
|
51
|
+
MSpec.should_receive(:mode?).with(:no_ruby_bug).twice.and_return(:true)
|
52
|
+
BugGuard.new("#1", "1.8.5").match?.should == false
|
53
|
+
BugGuard.new("#1", "1.8").match?.should == false
|
54
|
+
end
|
49
55
|
end
|
50
56
|
|
51
57
|
describe BugGuard, "#match? when #implementation? is not 'ruby'" do
|
@@ -87,6 +93,13 @@ describe BugGuard, "#match? when #implementation? is not 'ruby'" do
|
|
87
93
|
BugGuard.new("#1", "1.8.7").match?.should == false
|
88
94
|
BugGuard.new("#1", "1.8.6.115").match?.should == false
|
89
95
|
end
|
96
|
+
|
97
|
+
it "returns false when MSpec.mode?(:no_ruby_bug) is true" do
|
98
|
+
MSpec.should_receive(:mode?).with(:no_ruby_bug).any_number_of_times.and_return(:true)
|
99
|
+
BugGuard.new("#1", "1.8.6").match?.should == false
|
100
|
+
BugGuard.new("#1", "1.8.6.114").match?.should == false
|
101
|
+
BugGuard.new("#1", "1.8.6.115").match?.should == false
|
102
|
+
end
|
90
103
|
end
|
91
104
|
|
92
105
|
describe Object, "#ruby_bug" do
|
@@ -98,25 +111,30 @@ describe Object, "#ruby_bug" do
|
|
98
111
|
|
99
112
|
it "yields when #match? returns false" do
|
100
113
|
@guard.stub!(:match?).and_return(false)
|
101
|
-
ruby_bug { ScratchPad.record :yield }
|
114
|
+
ruby_bug("#1234", "1.8.6") { ScratchPad.record :yield }
|
102
115
|
ScratchPad.recorded.should == :yield
|
103
116
|
end
|
104
117
|
|
105
118
|
it "does not yield when #match? returns true" do
|
106
119
|
@guard.stub!(:match?).and_return(true)
|
107
|
-
ruby_bug { ScratchPad.record :yield }
|
120
|
+
ruby_bug("#1234", "1.8.6") { ScratchPad.record :yield }
|
108
121
|
ScratchPad.recorded.should_not == :yield
|
109
122
|
end
|
110
123
|
|
111
|
-
it "
|
112
|
-
|
113
|
-
ruby_bug("#1234") {
|
114
|
-
ScratchPad.recorded.should == :yield
|
124
|
+
it "requires a bug tracker number and a version number" do
|
125
|
+
lambda { ruby_bug { } }.should raise_error(ArgumentError)
|
126
|
+
lambda { ruby_bug("#1234") { } }.should raise_error(ArgumentError)
|
115
127
|
end
|
116
128
|
|
117
|
-
it "
|
118
|
-
|
119
|
-
|
120
|
-
|
129
|
+
it "sets the name of the guard to :ruby_bug" do
|
130
|
+
ruby_bug("#1234", "1.8.6") { }
|
131
|
+
@guard.name.should == :ruby_bug
|
132
|
+
end
|
133
|
+
|
134
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
135
|
+
@guard.should_receive(:unregister)
|
136
|
+
lambda do
|
137
|
+
ruby_bug("", "") { raise Exception }
|
138
|
+
end.should raise_error(Exception)
|
121
139
|
end
|
122
140
|
end
|
@@ -21,6 +21,14 @@ describe Object, "#compliant_on" do
|
|
21
21
|
ScratchPad.clear
|
22
22
|
end
|
23
23
|
|
24
|
+
it "raises an Exception when passed :ruby" do
|
25
|
+
Object.const_set :RUBY_NAME, "jruby"
|
26
|
+
lambda {
|
27
|
+
compliant_on(:ruby) { ScratchPad.record :yield }
|
28
|
+
}.should raise_error(Exception)
|
29
|
+
ScratchPad.recorded.should_not == :yield
|
30
|
+
end
|
31
|
+
|
24
32
|
it "does not yield when #standard? and #implementation? return false" do
|
25
33
|
Object.const_set :RUBY_NAME, "jruby"
|
26
34
|
compliant_on(:rubinius, :ironruby) { ScratchPad.record :yield }
|
@@ -46,6 +54,25 @@ describe Object, "#compliant_on" do
|
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
57
|
+
describe Object, "#compliant_on" do
|
58
|
+
before :each do
|
59
|
+
@guard = CompliantOnGuard.new :any
|
60
|
+
CompliantOnGuard.stub!(:new).and_return(@guard)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "sets the name of the guard to :compliant_on" do
|
64
|
+
compliant_on(:rubinius) { }
|
65
|
+
@guard.name.should == :compliant_on
|
66
|
+
end
|
67
|
+
|
68
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
69
|
+
@guard.should_receive(:unregister)
|
70
|
+
lambda do
|
71
|
+
compliant_on(:rubinius) { raise Exception }
|
72
|
+
end.should raise_error(Exception)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
49
76
|
describe Object, "#not_compliant_on" do
|
50
77
|
before :all do
|
51
78
|
@verbose = $VERBOSE
|
@@ -66,6 +93,14 @@ describe Object, "#not_compliant_on" do
|
|
66
93
|
ScratchPad.clear
|
67
94
|
end
|
68
95
|
|
96
|
+
it "raises an Exception when passed :ruby" do
|
97
|
+
Object.const_set :RUBY_NAME, "jruby"
|
98
|
+
lambda {
|
99
|
+
not_compliant_on(:ruby) { ScratchPad.record :yield }
|
100
|
+
}.should raise_error(Exception)
|
101
|
+
ScratchPad.recorded.should_not == :yield
|
102
|
+
end
|
103
|
+
|
69
104
|
it "yields when #standard? returns true" do
|
70
105
|
Object.const_set :RUBY_NAME, "ruby"
|
71
106
|
not_compliant_on(:rubinius) { ScratchPad.record :yield }
|
@@ -84,3 +119,22 @@ describe Object, "#not_compliant_on" do
|
|
84
119
|
ScratchPad.recorded.should == :yield
|
85
120
|
end
|
86
121
|
end
|
122
|
+
|
123
|
+
describe Object, "#not_compliant_on" do
|
124
|
+
before :each do
|
125
|
+
@guard = NotCompliantOnGuard.new :any
|
126
|
+
NotCompliantOnGuard.stub!(:new).and_return(@guard)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "sets the name of the guard to :not_compliant_on" do
|
130
|
+
not_compliant_on(:rubinius) { }
|
131
|
+
@guard.name.should == :not_compliant_on
|
132
|
+
end
|
133
|
+
|
134
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
135
|
+
@guard.should_receive(:unregister)
|
136
|
+
lambda do
|
137
|
+
not_compliant_on(:rubinius) { raise Exception }
|
138
|
+
end.should raise_error(Exception)
|
139
|
+
end
|
140
|
+
end
|
@@ -18,3 +18,22 @@ describe Object, "#conflicts_with" do
|
|
18
18
|
ScratchPad.recorded.should == :yield
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe Object, "#conflicts_with" do
|
23
|
+
before :each do
|
24
|
+
@guard = ConflictsGuard.new
|
25
|
+
ConflictsGuard.stub!(:new).and_return(@guard)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets the name of the guard to :conflicts_with" do
|
29
|
+
conflicts_with(:AClass, :BClass) { }
|
30
|
+
@guard.name.should == :conflicts_with
|
31
|
+
end
|
32
|
+
|
33
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
34
|
+
@guard.should_receive(:unregister)
|
35
|
+
lambda do
|
36
|
+
conflicts_with(:AClass, :BClass) { raise Exception }
|
37
|
+
end.should raise_error(Exception)
|
38
|
+
end
|
39
|
+
end
|
data/spec/guards/endian_spec.rb
CHANGED
@@ -19,6 +19,19 @@ describe Object, "#big_endian" do
|
|
19
19
|
big_endian { ScratchPad.record :yield }
|
20
20
|
ScratchPad.recorded.should_not == :yield
|
21
21
|
end
|
22
|
+
|
23
|
+
it "sets the name of the guard to :big_endian" do
|
24
|
+
big_endian { }
|
25
|
+
@guard.name.should == :big_endian
|
26
|
+
end
|
27
|
+
|
28
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
29
|
+
@guard.stub!(:pattern).and_return([1])
|
30
|
+
@guard.should_receive(:unregister)
|
31
|
+
lambda do
|
32
|
+
big_endian { raise Exception }
|
33
|
+
end.should raise_error(Exception)
|
34
|
+
end
|
22
35
|
end
|
23
36
|
|
24
37
|
describe Object, "#little_endian" do
|
@@ -39,4 +52,17 @@ describe Object, "#little_endian" do
|
|
39
52
|
little_endian { ScratchPad.record :yield }
|
40
53
|
ScratchPad.recorded.should_not == :yield
|
41
54
|
end
|
55
|
+
|
56
|
+
it "sets the name of the guard to :little_endian" do
|
57
|
+
little_endian { }
|
58
|
+
@guard.name.should == :little_endian
|
59
|
+
end
|
60
|
+
|
61
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
62
|
+
@guard.stub!(:pattern).and_return([0])
|
63
|
+
@guard.should_receive(:unregister)
|
64
|
+
lambda do
|
65
|
+
little_endian { raise Exception }
|
66
|
+
end.should raise_error(Exception)
|
67
|
+
end
|
42
68
|
end
|
@@ -47,3 +47,23 @@ describe Object, "#extended_on" do
|
|
47
47
|
ScratchPad.recorded.should == :yield
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
describe Object, "#extended_on" do
|
52
|
+
before :each do
|
53
|
+
@guard = ExtensionsGuard.new
|
54
|
+
ExtensionsGuard.stub!(:new).and_return(@guard)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "sets the name of the guard to :extended_on" do
|
58
|
+
extended_on(:rubinius) { }
|
59
|
+
@guard.name.should == :extended_on
|
60
|
+
end
|
61
|
+
|
62
|
+
it "calls #unregister even when an exception is raised in the guard block" do
|
63
|
+
@guard.should_receive(:match?).and_return(true)
|
64
|
+
@guard.should_receive(:unregister)
|
65
|
+
lambda do
|
66
|
+
extended_on(:rubinius) { raise Exception }
|
67
|
+
end.should raise_error(Exception)
|
68
|
+
end
|
69
|
+
end
|
data/spec/guards/guard_spec.rb
CHANGED
@@ -3,42 +3,6 @@ require 'mspec/utils/ruby_name'
|
|
3
3
|
require 'mspec/guards/guard'
|
4
4
|
require 'rbconfig'
|
5
5
|
|
6
|
-
describe SpecGuard, ".register" do
|
7
|
-
before :each do
|
8
|
-
@tally = mock("tally")
|
9
|
-
@tally.stub!(:register)
|
10
|
-
TallyAction.stub!(:new).and_return(@tally)
|
11
|
-
SpecGuard.instance_variable_set(:@registered, nil)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "creates a new TallyAction if one does not exist" do
|
15
|
-
TallyAction.should_receive(:new).and_return(@tally)
|
16
|
-
@tally.should_receive(:register)
|
17
|
-
SpecGuard.register
|
18
|
-
SpecGuard.register
|
19
|
-
end
|
20
|
-
|
21
|
-
it "registers itself with MSpec :finish actions" do
|
22
|
-
MSpec.should_receive(:register).with(:finish, SpecGuard)
|
23
|
-
SpecGuard.register
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe SpecGuard, ".unregister" do
|
28
|
-
before :each do
|
29
|
-
@tally = mock("tally")
|
30
|
-
@tally.stub!(:register)
|
31
|
-
TallyAction.stub!(:new).and_return(@tally)
|
32
|
-
SpecGuard.instance_variable_set(:@registered, nil)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "unregisters its tally action" do
|
36
|
-
@tally.should_receive(:unregister)
|
37
|
-
SpecGuard.register
|
38
|
-
SpecGuard.unregister
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
6
|
describe SpecGuard, ".ruby_version" do
|
43
7
|
before :all do
|
44
8
|
@ruby_version = Object.const_get :RUBY_VERSION
|
@@ -116,6 +80,12 @@ describe SpecGuard, "#yield?" do
|
|
116
80
|
@guard = SpecGuard.new
|
117
81
|
end
|
118
82
|
|
83
|
+
after :each do
|
84
|
+
MSpec.unregister :add, @guard
|
85
|
+
MSpec.clear_modes
|
86
|
+
SpecGuard.clear_guards
|
87
|
+
end
|
88
|
+
|
119
89
|
it "returns true if MSpec.mode?(:unguarded) is true" do
|
120
90
|
MSpec.register_mode :unguarded
|
121
91
|
@guard.yield?.should == true
|
@@ -141,6 +111,14 @@ describe SpecGuard, "#yield?" do
|
|
141
111
|
@guard.yield?(true).should == true
|
142
112
|
end
|
143
113
|
|
114
|
+
it "returns true if MSpec.mode?(:report_on) is true and SpecGuards.guards contains the named guard" do
|
115
|
+
MSpec.register_mode :report_on
|
116
|
+
SpecGuard.guards << :guard_name
|
117
|
+
@guard.yield?.should == false
|
118
|
+
@guard.name = :guard_name
|
119
|
+
@guard.yield?.should == true
|
120
|
+
end
|
121
|
+
|
144
122
|
it "returns #match? if neither report nor verify mode are true" do
|
145
123
|
@guard.stub!(:match?).and_return(false)
|
146
124
|
@guard.yield?.should == false
|
@@ -430,30 +408,69 @@ end
|
|
430
408
|
|
431
409
|
describe SpecGuard, "#unregister" do
|
432
410
|
before :each do
|
433
|
-
@tally = mock("tally")
|
434
|
-
@tally.stub!(:register)
|
435
|
-
TallyAction.stub!(:new).and_return(@tally)
|
436
411
|
MSpec.stub!(:unregister)
|
437
412
|
@guard = SpecGuard.new
|
438
|
-
|
439
|
-
SpecGuard.instance_variable_set(:@registered, nil)
|
440
|
-
SpecGuard.register
|
441
413
|
end
|
442
414
|
|
443
|
-
it "unregisters from MSpec :
|
444
|
-
MSpec.should_receive(:unregister).with(:
|
445
|
-
@tally.should_receive(:unregister)
|
415
|
+
it "unregisters from MSpec :add actions" do
|
416
|
+
MSpec.should_receive(:unregister).with(:add, @guard)
|
446
417
|
@guard.unregister
|
447
418
|
end
|
419
|
+
end
|
448
420
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
@guard.unregister
|
421
|
+
describe SpecGuard, "#record" do
|
422
|
+
after :each do
|
423
|
+
SpecGuard.clear
|
453
424
|
end
|
454
425
|
|
455
|
-
it "
|
456
|
-
SpecGuard.
|
457
|
-
|
426
|
+
it "saves the name of the guarded spec under the name of the guard" do
|
427
|
+
guard = SpecGuard.new "a", "1.8"..."1.9"
|
428
|
+
guard.name = :named_guard
|
429
|
+
guard.record "SomeClass#action returns true"
|
430
|
+
SpecGuard.report.should == {
|
431
|
+
'named_guard a, 1.8...1.9' => ["SomeClass#action returns true"]
|
432
|
+
}
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
describe SpecGuard, ".guards" do
|
437
|
+
it "returns an Array" do
|
438
|
+
SpecGuard.guards.should be_kind_of(Array)
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
describe SpecGuard, ".clear_guards" do
|
443
|
+
it "resets the array to empty" do
|
444
|
+
SpecGuard.guards << :guard
|
445
|
+
SpecGuard.guards.should == [:guard]
|
446
|
+
SpecGuard.clear_guards
|
447
|
+
SpecGuard.guards.should == []
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
describe SpecGuard, ".finish" do
|
452
|
+
before :each do
|
453
|
+
$stdout = @out = IOStub.new
|
454
|
+
end
|
455
|
+
|
456
|
+
after :each do
|
457
|
+
$stdout = STDOUT
|
458
|
+
SpecGuard.clear
|
459
|
+
end
|
460
|
+
|
461
|
+
it "prints the descriptions of the guarded specs" do
|
462
|
+
guard = SpecGuard.new "a", "1.8"..."1.9"
|
463
|
+
guard.name = :named_guard
|
464
|
+
guard.record "SomeClass#action returns true"
|
465
|
+
guard.record "SomeClass#reverse returns false"
|
466
|
+
SpecGuard.finish
|
467
|
+
$stdout.should == %[
|
468
|
+
|
469
|
+
2 specs omitted by guard: named_guard a, 1.8...1.9:
|
470
|
+
|
471
|
+
SomeClass#action returns true
|
472
|
+
SomeClass#reverse returns false
|
473
|
+
|
474
|
+
]
|
458
475
|
end
|
459
476
|
end
|