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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
require 'spec_helper'
require 'mspec/guards'
describe BugGuard, "#match? when #implementation? is 'ruby'" do
before :all do
@verbose = $VERBOSE
$VERBOSE = nil
end
after :all do
$VERBOSE = @verbose
end
before :each do
hide_deprecation_warnings
stub_const "VersionGuard::FULL_RUBY_VERSION", SpecVersion.new('1.8.6')
@ruby_engine = Object.const_get :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, 'ruby'
end
after :each do
Object.const_set :RUBY_ENGINE, @ruby_engine
end
it "returns false when version argument is less than RUBY_VERSION" do
BugGuard.new("#1", "1.8.5").match?.should == false
end
it "returns true when version argument is equal to RUBY_VERSION" do
BugGuard.new("#1", "1.8.6").match?.should == true
end
it "returns true when version argument is greater than RUBY_VERSION" do
BugGuard.new("#1", "1.8.7").match?.should == true
end
it "returns true when version argument implicitly includes RUBY_VERSION" do
BugGuard.new("#1", "1.8").match?.should == true
BugGuard.new("#1", "1.8.6").match?.should == true
end
it "returns true when the argument range includes RUBY_VERSION" do
BugGuard.new("#1", '1.8.5'..'1.8.7').match?.should == true
BugGuard.new("#1", '1.8'..'1.9').match?.should == true
BugGuard.new("#1", '1.8'...'1.9').match?.should == true
BugGuard.new("#1", '1.8'..'1.8.6').match?.should == true
BugGuard.new("#1", '1.8.5'..'1.8.6').match?.should == true
BugGuard.new("#1", ''...'1.8.7').match?.should == true
end
it "returns false when the argument range does not include RUBY_VERSION" do
BugGuard.new("#1", '1.8.7'..'1.8.9').match?.should == false
BugGuard.new("#1", '1.8.4'..'1.8.5').match?.should == false
BugGuard.new("#1", '1.8.4'...'1.8.6').match?.should == false
BugGuard.new("#1", '1.8.5'...'1.8.6').match?.should == false
BugGuard.new("#1", ''...'1.8.6').match?.should == false
end
it "returns false when MSpec.mode?(:no_ruby_bug) is true" do
MSpec.should_receive(:mode?).with(:no_ruby_bug).twice.and_return(:true)
BugGuard.new("#1", "1.8.5").match?.should == false
BugGuard.new("#1", "1.8").match?.should == false
end
end
describe BugGuard, "#match? when #implementation? is not 'ruby'" do
before :all do
@verbose = $VERBOSE
$VERBOSE = nil
end
after :all do
$VERBOSE = @verbose
end
before :each do
hide_deprecation_warnings
@ruby_version = Object.const_get :RUBY_VERSION
@ruby_engine = Object.const_get :RUBY_ENGINE
Object.const_set :RUBY_VERSION, '1.8.6'
Object.const_set :RUBY_ENGINE, 'jruby'
end
after :each do
Object.const_set :RUBY_VERSION, @ruby_version
Object.const_set :RUBY_ENGINE, @ruby_engine
end
it "returns false when version argument is less than RUBY_VERSION" do
BugGuard.new("#1", "1.8").match?.should == false
BugGuard.new("#1", "1.8.6").match?.should == false
end
it "returns false when version argument is equal to RUBY_VERSION" do
BugGuard.new("#1", "1.8.6").match?.should == false
end
it "returns false when version argument is greater than RUBY_VERSION" do
BugGuard.new("#1", "1.8.7").match?.should == false
end
it "returns false no matter if the argument range includes RUBY_VERSION" do
BugGuard.new("#1", '1.8'...'1.9').match?.should == false
BugGuard.new("#1", '1.8.5'...'1.8.7').match?.should == false
BugGuard.new("#1", '1.8.4'...'1.8.6').match?.should == false
end
it "returns false when MSpec.mode?(:no_ruby_bug) is true" do
MSpec.stub(:mode?).and_return(:true)
BugGuard.new("#1", "1.8.6").match?.should == false
end
end
describe Object, "#ruby_bug" do
before :each do
hide_deprecation_warnings
@guard = BugGuard.new "#1234", "x.x.x"
BugGuard.stub(:new).and_return(@guard)
ScratchPad.clear
end
it "yields when #match? returns false" do
@guard.stub(:match?).and_return(false)
ruby_bug("#1234", "1.8.6") { ScratchPad.record :yield }
ScratchPad.recorded.should == :yield
end
it "does not yield when #match? returns true" do
@guard.stub(:match?).and_return(true)
ruby_bug("#1234", "1.8.6") { ScratchPad.record :yield }
ScratchPad.recorded.should_not == :yield
end
it "requires a bug tracker number and a version number" do
lambda { ruby_bug { } }.should raise_error(ArgumentError)
lambda { ruby_bug("#1234") { } }.should raise_error(ArgumentError)
end
it "sets the name of the guard to :ruby_bug" do
ruby_bug("#1234", "1.8.6") { }
@guard.name.should == :ruby_bug
end
it "calls #unregister even when an exception is raised in the guard block" do
@guard.should_receive(:unregister)
lambda do
ruby_bug("", "") { raise Exception }
end.should raise_error(Exception)
end
end
|