mspec 1.5.7 → 1.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/mspec/guards/bug.rb +1 -1
- data/lib/mspec/guards/compliance.rb +13 -4
- data/lib/mspec/guards/extensions.rb +5 -0
- data/lib/mspec/guards/guard.rb +11 -7
- data/lib/mspec/guards/noncompliance.rb +5 -0
- data/lib/mspec/guards/support.rb +5 -0
- data/lib/mspec/matchers.rb +1 -0
- data/lib/mspec/matchers/have_instance_method.rb +4 -10
- data/lib/mspec/matchers/have_method.rb +24 -0
- data/lib/mspec/matchers/have_private_instance_method.rb +4 -10
- data/lib/mspec/matchers/method.rb +13 -0
- data/lib/mspec/version.rb +1 -1
- data/spec/guards/compliance_spec.rb +54 -38
- data/spec/guards/extensions_spec.rb +27 -20
- data/spec/guards/guard_spec.rb +37 -5
- data/spec/guards/noncompliance_spec.rb +27 -20
- data/spec/guards/support_spec.rb +27 -6
- data/spec/matchers/have_instance_method_spec.rb +8 -37
- data/spec/matchers/have_method_spec.rb +55 -0
- data/spec/matchers/have_private_instance_method_spec.rb +6 -35
- data/spec/matchers/method_spec.rb +36 -0
- metadata +6 -2
data/Rakefile
CHANGED
|
@@ -18,7 +18,7 @@ spec = Gem::Specification.new do |s|
|
|
|
18
18
|
|
|
19
19
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
20
20
|
s.authors = ["Brian Ford"]
|
|
21
|
-
s.date = %q{2009-2-
|
|
21
|
+
s.date = %q{2009-2-9}
|
|
22
22
|
s.email = %q{bford@engineyard.com}
|
|
23
23
|
s.has_rdoc = true
|
|
24
24
|
s.extra_rdoc_files = %w[ README LICENSE ]
|
data/lib/mspec/guards/bug.rb
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
require 'mspec/guards/guard'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class CompliantOnGuard < SpecGuard
|
|
4
|
+
def match?
|
|
5
|
+
standard? or implementation?(*@args)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class NotCompliantOnGuard < SpecGuard
|
|
10
|
+
def match?
|
|
11
|
+
standard? or !implementation?(*@args)
|
|
12
|
+
end
|
|
4
13
|
end
|
|
5
14
|
|
|
6
15
|
class Object
|
|
7
16
|
def compliant_on(*args)
|
|
8
|
-
g =
|
|
17
|
+
g = CompliantOnGuard.new(*args)
|
|
9
18
|
yield if g.yield?
|
|
10
19
|
g.unregister
|
|
11
20
|
end
|
|
12
21
|
|
|
13
22
|
def not_compliant_on(*args)
|
|
14
|
-
g =
|
|
15
|
-
yield if g.yield?
|
|
23
|
+
g = NotCompliantOnGuard.new(*args)
|
|
24
|
+
yield if g.yield?
|
|
16
25
|
g.unregister
|
|
17
26
|
end
|
|
18
27
|
end
|
data/lib/mspec/guards/guard.rb
CHANGED
|
@@ -39,7 +39,9 @@ class SpecGuard
|
|
|
39
39
|
n = 4
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
patch = RUBY_PATCHLEVEL.to_i
|
|
43
|
+
patch = 0 if patch < 0
|
|
44
|
+
version = "#{RUBY_VERSION}.#{patch}"
|
|
43
45
|
version.split('.')[0,n].join('.')
|
|
44
46
|
end
|
|
45
47
|
|
|
@@ -87,24 +89,26 @@ class SpecGuard
|
|
|
87
89
|
def implementation?(*args)
|
|
88
90
|
args.any? do |name|
|
|
89
91
|
!!case name
|
|
90
|
-
when :
|
|
92
|
+
when :rubinius
|
|
91
93
|
RUBY_NAME =~ /^rbx/
|
|
92
94
|
when :ruby
|
|
93
95
|
RUBY_NAME =~ /^ruby/
|
|
94
|
-
when :ruby18
|
|
95
|
-
RUBY_NAME =~ /^ruby(1.8)?/ and RUBY_VERSION =~ /^1.8/
|
|
96
|
-
when :ruby19
|
|
97
|
-
RUBY_NAME =~ /^ruby(1.9)?/ and RUBY_VERSION =~ /^1.9/
|
|
98
96
|
when :jruby
|
|
99
97
|
RUBY_NAME =~ /^jruby/
|
|
100
|
-
when :ironruby
|
|
98
|
+
when :ironruby
|
|
101
99
|
RUBY_NAME =~ /^ironruby/
|
|
100
|
+
when :macruby
|
|
101
|
+
RUBY_NAME =~ /^macruby/
|
|
102
102
|
else
|
|
103
103
|
false
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
+
def standard?
|
|
109
|
+
implementation? :ruby
|
|
110
|
+
end
|
|
111
|
+
|
|
108
112
|
def windows?(sym, key)
|
|
109
113
|
sym == :windows && SpecGuard.windows?(key)
|
|
110
114
|
end
|
data/lib/mspec/guards/support.rb
CHANGED
data/lib/mspec/matchers.rb
CHANGED
|
@@ -12,6 +12,7 @@ require 'mspec/matchers/equal'
|
|
|
12
12
|
require 'mspec/matchers/equal_element'
|
|
13
13
|
require 'mspec/matchers/equal_utf16'
|
|
14
14
|
require 'mspec/matchers/have_instance_method'
|
|
15
|
+
require 'mspec/matchers/have_method'
|
|
15
16
|
require 'mspec/matchers/have_private_instance_method'
|
|
16
17
|
require 'mspec/matchers/include'
|
|
17
18
|
require 'mspec/matchers/match_yaml'
|
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
require 'mspec/
|
|
2
|
-
|
|
3
|
-
class HaveInstanceMethodMatcher
|
|
4
|
-
def initialize(method, include_super=true)
|
|
5
|
-
@include_super = include_super
|
|
6
|
-
version = SpecVersion.new(RUBY_VERSION) <=> "1.9"
|
|
7
|
-
@method = version < 0 ? method.to_s : method
|
|
8
|
-
end
|
|
1
|
+
require 'mspec/matchers/method'
|
|
9
2
|
|
|
3
|
+
class HaveInstanceMethodMatcher < MethodMatcher
|
|
10
4
|
def matches?(mod)
|
|
11
5
|
@mod = mod
|
|
12
6
|
mod.instance_methods(@include_super).include? @method
|
|
13
7
|
end
|
|
14
8
|
|
|
15
9
|
def failure_message
|
|
16
|
-
["Expected #{@mod} to have
|
|
10
|
+
["Expected #{@mod} to have instance method '#{@method.to_s}'",
|
|
17
11
|
"but it does not"]
|
|
18
12
|
end
|
|
19
13
|
|
|
20
14
|
def negative_failure_message
|
|
21
|
-
["Expected #{@mod} NOT to have
|
|
15
|
+
["Expected #{@mod} NOT to have instance method '#{@method.to_s}'",
|
|
22
16
|
"but it does"]
|
|
23
17
|
end
|
|
24
18
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'mspec/matchers/method'
|
|
2
|
+
|
|
3
|
+
class HaveMethodMatcher < MethodMatcher
|
|
4
|
+
def matches?(mod)
|
|
5
|
+
@mod = mod
|
|
6
|
+
@mod.methods(@include_super).include? @method
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def failure_message
|
|
10
|
+
["Expected #{@mod} to have method '#{@method.to_s}'",
|
|
11
|
+
"but it does not"]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def negative_failure_message
|
|
15
|
+
["Expected #{@mod} NOT to have method '#{@method.to_s}'",
|
|
16
|
+
"but it does"]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Object
|
|
21
|
+
def have_method(method, include_super=true)
|
|
22
|
+
HaveMethodMatcher.new method, include_super
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
require 'mspec/
|
|
2
|
-
|
|
3
|
-
class HavePrivateInstanceMethodMatcher
|
|
4
|
-
def initialize(method, include_super=true)
|
|
5
|
-
@include_super = include_super
|
|
6
|
-
version = SpecVersion.new(RUBY_VERSION) <=> "1.9"
|
|
7
|
-
@method = version < 0 ? method.to_s : method
|
|
8
|
-
end
|
|
1
|
+
require 'mspec/matchers/method'
|
|
9
2
|
|
|
3
|
+
class HavePrivateInstanceMethodMatcher < MethodMatcher
|
|
10
4
|
def matches?(mod)
|
|
11
5
|
@mod = mod
|
|
12
6
|
mod.private_instance_methods(@include_super).include? @method
|
|
13
7
|
end
|
|
14
8
|
|
|
15
9
|
def failure_message
|
|
16
|
-
["Expected #{@mod} to have private method '#{@method.to_s}'",
|
|
10
|
+
["Expected #{@mod} to have private instance method '#{@method.to_s}'",
|
|
17
11
|
"but it does not"]
|
|
18
12
|
end
|
|
19
13
|
|
|
20
14
|
def negative_failure_message
|
|
21
|
-
["Expected #{@mod} NOT to have private method '#{@method.to_s}'",
|
|
15
|
+
["Expected #{@mod} NOT to have private instance method '#{@method.to_s}'",
|
|
22
16
|
"but it does"]
|
|
23
17
|
end
|
|
24
18
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'mspec/utils/version'
|
|
2
|
+
|
|
3
|
+
class MethodMatcher
|
|
4
|
+
def initialize(method, include_super=true)
|
|
5
|
+
@include_super = include_super
|
|
6
|
+
version = SpecVersion.new(RUBY_VERSION) <=> "1.9"
|
|
7
|
+
@method = version < 0 ? method.to_s : method
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def matches?(mod)
|
|
11
|
+
raise Exception, "define #matches? in the subclass"
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/mspec/version.rb
CHANGED
|
@@ -2,69 +2,85 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
|
2
2
|
require 'mspec/guards/compliance'
|
|
3
3
|
|
|
4
4
|
describe Object, "#compliant_on" do
|
|
5
|
+
before :all do
|
|
6
|
+
@verbose = $VERBOSE
|
|
7
|
+
$VERBOSE = nil
|
|
8
|
+
@ruby_name = Object.const_get :RUBY_NAME if Object.const_defined? :RUBY_NAME
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after :all do
|
|
12
|
+
$VERBOSE = @verbose
|
|
13
|
+
if @ruby_name
|
|
14
|
+
Object.const_set :RUBY_NAME, @ruby_name
|
|
15
|
+
else
|
|
16
|
+
Object.send :remove_const, :RUBY_NAME
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
5
20
|
before :each do
|
|
6
|
-
@guard = ComplianceGuard.new
|
|
7
|
-
ComplianceGuard.stub!(:new).and_return(@guard)
|
|
8
21
|
ScratchPad.clear
|
|
9
22
|
end
|
|
10
23
|
|
|
11
|
-
it "does not yield when #
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
compliant_on(:rbx) { @ScratchPad.record :yield }
|
|
24
|
+
it "does not yield when #standard? and #implementation? return false" do
|
|
25
|
+
Object.const_set :RUBY_NAME, "jruby"
|
|
26
|
+
compliant_on(:rubinius, :ironruby) { ScratchPad.record :yield }
|
|
15
27
|
ScratchPad.recorded.should_not == :yield
|
|
16
28
|
end
|
|
17
29
|
|
|
18
|
-
it "yields when #
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
compliant_on(:rbx) { ScratchPad.record :yield }
|
|
30
|
+
it "yields when #standard? returns true" do
|
|
31
|
+
Object.const_set :RUBY_NAME, "ruby"
|
|
32
|
+
compliant_on(:rubinius) { ScratchPad.record :yield }
|
|
22
33
|
ScratchPad.recorded.should == :yield
|
|
34
|
+
end
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
compliant_on(:
|
|
36
|
+
it "yields when #implementation? returns true" do
|
|
37
|
+
Object.const_set :RUBY_NAME, "jruby"
|
|
38
|
+
compliant_on(:jruby) { ScratchPad.record :yield }
|
|
27
39
|
ScratchPad.recorded.should == :yield
|
|
28
40
|
end
|
|
29
41
|
|
|
30
|
-
it "
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
ScratchPad.recorded.should == :yield
|
|
42
|
+
it "does not yield when #implementation? returns false" do
|
|
43
|
+
Object.const_set :RUBY_NAME, "jruby"
|
|
44
|
+
compliant_on(:rubinius) { ScratchPad.record :yield }
|
|
45
|
+
ScratchPad.recorded.should_not == :yield
|
|
35
46
|
end
|
|
36
47
|
end
|
|
37
48
|
|
|
38
49
|
describe Object, "#not_compliant_on" do
|
|
50
|
+
before :all do
|
|
51
|
+
@verbose = $VERBOSE
|
|
52
|
+
$VERBOSE = nil
|
|
53
|
+
@ruby_name = Object.const_get :RUBY_NAME if Object.const_defined? :RUBY_NAME
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
after :all do
|
|
57
|
+
$VERBOSE = @verbose
|
|
58
|
+
if @ruby_name
|
|
59
|
+
Object.const_set :RUBY_NAME, @ruby_name
|
|
60
|
+
else
|
|
61
|
+
Object.send :remove_const, :RUBY_NAME
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
39
65
|
before :each do
|
|
40
|
-
@guard = ComplianceGuard.new
|
|
41
|
-
ComplianceGuard.stub!(:new).and_return(@guard)
|
|
42
66
|
ScratchPad.clear
|
|
43
67
|
end
|
|
44
68
|
|
|
45
|
-
it "
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
ScratchPad.recorded.should_not == :yield
|
|
69
|
+
it "yields when #standard? returns true" do
|
|
70
|
+
Object.const_set :RUBY_NAME, "ruby"
|
|
71
|
+
not_compliant_on(:rubinius) { ScratchPad.record :yield }
|
|
72
|
+
ScratchPad.recorded.should == :yield
|
|
50
73
|
end
|
|
51
74
|
|
|
52
|
-
it "does not yield when #implementation?
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
not_compliant_on(:rbx) { ScratchPad.record :yield }
|
|
56
|
-
ScratchPad.recorded.should_not == :yield
|
|
57
|
-
|
|
58
|
-
@guard.stub!(:implementation?).and_return(false)
|
|
59
|
-
@guard.stub!(:platform?).and_return(true)
|
|
60
|
-
not_compliant_on(:rbx) { ScratchPad.record :yield }
|
|
75
|
+
it "does not yield when #implementation? returns true" do
|
|
76
|
+
Object.const_set :RUBY_NAME, "jruby "
|
|
77
|
+
not_compliant_on(:jruby) { ScratchPad.record :yield }
|
|
61
78
|
ScratchPad.recorded.should_not == :yield
|
|
62
79
|
end
|
|
63
80
|
|
|
64
|
-
it "yields when #implementation?
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
not_compliant_on(:rbx) { ScratchPad.record :yield }
|
|
81
|
+
it "yields when #implementation? returns false" do
|
|
82
|
+
Object.const_set :RUBY_NAME, "jruby "
|
|
83
|
+
not_compliant_on(:rubinius) { ScratchPad.record :yield }
|
|
68
84
|
ScratchPad.recorded.should == :yield
|
|
69
85
|
end
|
|
70
86
|
end
|
|
@@ -2,35 +2,42 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
|
2
2
|
require 'mspec/guards/extensions'
|
|
3
3
|
|
|
4
4
|
describe Object, "#extended_on" do
|
|
5
|
+
before :all do
|
|
6
|
+
@verbose = $VERBOSE
|
|
7
|
+
$VERBOSE = nil
|
|
8
|
+
@ruby_name = Object.const_get :RUBY_NAME if Object.const_defined? :RUBY_NAME
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after :all do
|
|
12
|
+
$VERBOSE = @verbose
|
|
13
|
+
if @ruby_name
|
|
14
|
+
Object.const_set :RUBY_NAME, @ruby_name
|
|
15
|
+
else
|
|
16
|
+
Object.send :remove_const, :RUBY_NAME
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
5
20
|
before :each do
|
|
6
|
-
@guard = ExtensionsGuard.new
|
|
7
|
-
ExtensionsGuard.stub!(:new).and_return(@guard)
|
|
8
21
|
ScratchPad.clear
|
|
9
22
|
end
|
|
10
23
|
|
|
11
|
-
it "
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
it "raises an Exception when #standard? returns true" do
|
|
25
|
+
Object.const_set :RUBY_NAME, "ruby"
|
|
26
|
+
lambda {
|
|
27
|
+
extended_on(:ruby) { ScratchPad.record :yield }
|
|
28
|
+
}.should raise_error(Exception)
|
|
15
29
|
ScratchPad.recorded.should_not == :yield
|
|
16
30
|
end
|
|
17
31
|
|
|
18
|
-
it "
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ScratchPad.recorded.should == :yield
|
|
23
|
-
|
|
24
|
-
@guard.stub!(:implementation?).and_return(false)
|
|
25
|
-
@guard.stub!(:platform?).and_return(true)
|
|
26
|
-
extended_on(:rbx) { ScratchPad.record :yield }
|
|
27
|
-
ScratchPad.recorded.should == :yield
|
|
32
|
+
it "does not yield when #implementation? returns false" do
|
|
33
|
+
Object.const_set :RUBY_NAME, "jruby"
|
|
34
|
+
extended_on(:rubinius) { ScratchPad.record :yield }
|
|
35
|
+
ScratchPad.recorded.should_not == :yield
|
|
28
36
|
end
|
|
29
37
|
|
|
30
|
-
it "yields when #implementation?
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
extended_on(:rbx) { ScratchPad.record :yield }
|
|
38
|
+
it "yields when #implementation? returns true" do
|
|
39
|
+
Object.const_set :RUBY_NAME, "rbx"
|
|
40
|
+
extended_on(:rubinius) { ScratchPad.record :yield }
|
|
34
41
|
ScratchPad.recorded.should == :yield
|
|
35
42
|
end
|
|
36
43
|
end
|
data/spec/guards/guard_spec.rb
CHANGED
|
@@ -57,6 +57,11 @@ describe SpecGuard, ".ruby_version" do
|
|
|
57
57
|
SpecGuard.ruby_version(:full).should == "8.2.3.71"
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
it "returns 0 for negative RUBY_PATCHLEVEL values" do
|
|
61
|
+
Object.const_set :RUBY_PATCHLEVEL, -1
|
|
62
|
+
SpecGuard.ruby_version(:full).should == "8.2.3.0"
|
|
63
|
+
end
|
|
64
|
+
|
|
60
65
|
it "returns major.minor.tiny for :tiny" do
|
|
61
66
|
SpecGuard.ruby_version(:tiny).should == "8.2.3"
|
|
62
67
|
end
|
|
@@ -182,11 +187,6 @@ describe SpecGuard, "#implementation?" do
|
|
|
182
187
|
@guard.implementation?(:ruby).should == true
|
|
183
188
|
end
|
|
184
189
|
|
|
185
|
-
it "returns true if passed :rbx and RUBY_NAME == 'rbx'" do
|
|
186
|
-
Object.const_set :RUBY_NAME, 'rbx'
|
|
187
|
-
@guard.implementation?(:rbx).should == true
|
|
188
|
-
end
|
|
189
|
-
|
|
190
190
|
it "returns true if passed :rubinius and RUBY_NAME == 'rbx'" do
|
|
191
191
|
Object.const_set :RUBY_NAME, 'rbx'
|
|
192
192
|
@guard.implementation?(:rubinius).should == true
|
|
@@ -197,12 +197,44 @@ describe SpecGuard, "#implementation?" do
|
|
|
197
197
|
@guard.implementation?(:jruby).should == true
|
|
198
198
|
end
|
|
199
199
|
|
|
200
|
+
it "returns true if passed :ironruby and RUBY_NAME == 'ironruby'" do
|
|
201
|
+
Object.const_set :RUBY_NAME, 'ironruby'
|
|
202
|
+
@guard.implementation?(:ironruby).should == true
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
it "returns true if passed :ruby and RUBY_NAME matches /^ruby/" do
|
|
206
|
+
Object.const_set :RUBY_NAME, 'ruby'
|
|
207
|
+
@guard.implementation?(:ruby).should == true
|
|
208
|
+
|
|
209
|
+
Object.const_set :RUBY_NAME, 'ruby1.8'
|
|
210
|
+
@guard.implementation?(:ruby).should == true
|
|
211
|
+
|
|
212
|
+
Object.const_set :RUBY_NAME, 'ruby1.9'
|
|
213
|
+
@guard.implementation?(:ruby).should == true
|
|
214
|
+
end
|
|
215
|
+
|
|
200
216
|
it "returns false when passed an unrecognized name" do
|
|
201
217
|
Object.const_set :RUBY_NAME, 'ruby'
|
|
202
218
|
@guard.implementation?(:python).should == false
|
|
203
219
|
end
|
|
204
220
|
end
|
|
205
221
|
|
|
222
|
+
describe SpecGuard, "#standard?" do
|
|
223
|
+
before :each do
|
|
224
|
+
@guard = SpecGuard.new
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
it "returns true if #implementation? returns true" do
|
|
228
|
+
@guard.should_receive(:implementation?).with(:ruby).and_return(true)
|
|
229
|
+
@guard.standard?.should be_true
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
it "returns false if #implementation? returns false" do
|
|
233
|
+
@guard.should_receive(:implementation?).with(:ruby).and_return(false)
|
|
234
|
+
@guard.standard?.should be_false
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
206
238
|
describe SpecGuard, "#platform?" do
|
|
207
239
|
before :all do
|
|
208
240
|
@verbose = $VERBOSE
|
|
@@ -2,35 +2,42 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
|
2
2
|
require 'mspec/guards/noncompliance'
|
|
3
3
|
|
|
4
4
|
describe Object, "#deviates_on" do
|
|
5
|
+
before :all do
|
|
6
|
+
@verbose = $VERBOSE
|
|
7
|
+
$VERBOSE = nil
|
|
8
|
+
@ruby_name = Object.const_get :RUBY_NAME if Object.const_defined? :RUBY_NAME
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after :all do
|
|
12
|
+
$VERBOSE = @verbose
|
|
13
|
+
if @ruby_name
|
|
14
|
+
Object.const_set :RUBY_NAME, @ruby_name
|
|
15
|
+
else
|
|
16
|
+
Object.send :remove_const, :RUBY_NAME
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
5
20
|
before :each do
|
|
6
|
-
@guard = NonComplianceGuard.new
|
|
7
|
-
NonComplianceGuard.stub!(:new).and_return(@guard)
|
|
8
21
|
ScratchPad.clear
|
|
9
22
|
end
|
|
10
23
|
|
|
11
|
-
it "
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
it "raises an Exception when when #standard? returns true" do
|
|
25
|
+
Object.const_set :RUBY_NAME, "ruby"
|
|
26
|
+
lambda {
|
|
27
|
+
deviates_on(:ruby) { ScratchPad.record :yield }
|
|
28
|
+
}.should raise_error(Exception)
|
|
15
29
|
ScratchPad.recorded.should_not == :yield
|
|
16
30
|
end
|
|
17
31
|
|
|
18
|
-
it "
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ScratchPad.recorded.should == :yield
|
|
23
|
-
|
|
24
|
-
@guard.stub!(:implementation?).and_return(false)
|
|
25
|
-
@guard.stub!(:platform?).and_return(true)
|
|
26
|
-
deviates_on(:rbx) { ScratchPad.record :yield }
|
|
27
|
-
ScratchPad.recorded.should == :yield
|
|
32
|
+
it "does not yield when #implementation? returns false" do
|
|
33
|
+
Object.const_set :RUBY_NAME, "jruby"
|
|
34
|
+
deviates_on(:rubinius) { ScratchPad.record :yield }
|
|
35
|
+
ScratchPad.recorded.should_not == :yield
|
|
28
36
|
end
|
|
29
37
|
|
|
30
|
-
it "yields when #implementation?
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
deviates_on(:rbx) { ScratchPad.record :yield }
|
|
38
|
+
it "yields when #implementation? returns true" do
|
|
39
|
+
Object.const_set :RUBY_NAME, "jruby"
|
|
40
|
+
deviates_on(:jruby) { ScratchPad.record :yield }
|
|
34
41
|
ScratchPad.recorded.should == :yield
|
|
35
42
|
end
|
|
36
43
|
end
|
data/spec/guards/support_spec.rb
CHANGED
|
@@ -2,21 +2,42 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
|
2
2
|
require 'mspec/guards/support'
|
|
3
3
|
|
|
4
4
|
describe Object, "#not_supported_on" do
|
|
5
|
+
before :all do
|
|
6
|
+
@verbose = $VERBOSE
|
|
7
|
+
$VERBOSE = nil
|
|
8
|
+
@ruby_name = Object.const_get :RUBY_NAME if Object.const_defined? :RUBY_NAME
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after :all do
|
|
12
|
+
$VERBOSE = @verbose
|
|
13
|
+
if @ruby_name
|
|
14
|
+
Object.const_set :RUBY_NAME, @ruby_name
|
|
15
|
+
else
|
|
16
|
+
Object.send :remove_const, :RUBY_NAME
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
5
20
|
before :each do
|
|
6
|
-
@guard = SupportedGuard.new
|
|
7
|
-
SupportedGuard.stub!(:new).and_return(@guard)
|
|
8
21
|
ScratchPad.clear
|
|
9
22
|
end
|
|
10
23
|
|
|
24
|
+
it "raises an Exception when when #standard? returns true" do
|
|
25
|
+
Object.const_set :RUBY_NAME, "ruby"
|
|
26
|
+
lambda {
|
|
27
|
+
not_supported_on(:ruby) { ScratchPad.record :yield }
|
|
28
|
+
}.should raise_error(Exception)
|
|
29
|
+
ScratchPad.recorded.should_not == :yield
|
|
30
|
+
end
|
|
31
|
+
|
|
11
32
|
it "does not yield when #implementation? returns true" do
|
|
12
|
-
|
|
13
|
-
not_supported_on(:
|
|
33
|
+
Object.const_set :RUBY_NAME, "jruby"
|
|
34
|
+
not_supported_on(:jruby) { ScratchPad.record :yield }
|
|
14
35
|
ScratchPad.recorded.should_not == :yield
|
|
15
36
|
end
|
|
16
37
|
|
|
17
38
|
it "yields when #implementation? returns false" do
|
|
18
|
-
|
|
19
|
-
not_supported_on(:
|
|
39
|
+
Object.const_set :RUBY_NAME, "ruby"
|
|
40
|
+
not_supported_on(:rubinius) { ScratchPad.record :yield }
|
|
20
41
|
ScratchPad.recorded.should == :yield
|
|
21
42
|
end
|
|
22
43
|
end
|
|
@@ -13,13 +13,17 @@ class HIMMSpecs
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
describe HaveInstanceMethodMatcher do
|
|
16
|
-
it "
|
|
16
|
+
it "inherits from MethodMatcher" do
|
|
17
|
+
HaveInstanceMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "matches when mod has the instance method" do
|
|
17
21
|
matcher = HaveInstanceMethodMatcher.new :instance_method
|
|
18
22
|
matcher.matches?(HIMMSpecs).should be_true
|
|
19
23
|
matcher.matches?(HIMMSpecs::Subclass).should be_true
|
|
20
24
|
end
|
|
21
25
|
|
|
22
|
-
it "does not match when mod does not have the
|
|
26
|
+
it "does not match when mod does not have the instance method" do
|
|
23
27
|
matcher = HaveInstanceMethodMatcher.new :another_method
|
|
24
28
|
matcher.matches?(HIMMSpecs).should be_false
|
|
25
29
|
end
|
|
@@ -33,7 +37,7 @@ describe HaveInstanceMethodMatcher do
|
|
|
33
37
|
matcher = HaveInstanceMethodMatcher.new :some_method
|
|
34
38
|
matcher.matches?(HIMMSpecs)
|
|
35
39
|
matcher.failure_message.should == [
|
|
36
|
-
"Expected HIMMSpecs to have
|
|
40
|
+
"Expected HIMMSpecs to have instance method 'some_method'",
|
|
37
41
|
"but it does not"
|
|
38
42
|
]
|
|
39
43
|
end
|
|
@@ -42,41 +46,8 @@ describe HaveInstanceMethodMatcher do
|
|
|
42
46
|
matcher = HaveInstanceMethodMatcher.new :some_method
|
|
43
47
|
matcher.matches?(HIMMSpecs)
|
|
44
48
|
matcher.negative_failure_message.should == [
|
|
45
|
-
"Expected HIMMSpecs NOT to have
|
|
49
|
+
"Expected HIMMSpecs NOT to have instance method 'some_method'",
|
|
46
50
|
"but it does"
|
|
47
51
|
]
|
|
48
52
|
end
|
|
49
53
|
end
|
|
50
|
-
|
|
51
|
-
describe HaveInstanceMethodMatcher do
|
|
52
|
-
before :all do
|
|
53
|
-
@verbose = $VERBOSE
|
|
54
|
-
$VERBOSE = nil
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
after :all do
|
|
58
|
-
$VERBOSE = @verbose
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
before :each do
|
|
62
|
-
@ruby_version = Object.const_get :RUBY_VERSION
|
|
63
|
-
|
|
64
|
-
@method = mock("method name")
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
after :each do
|
|
68
|
-
Object.const_set :RUBY_VERSION, @ruby_version
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "converts the method name to a string if RUBY_VERSION < 1.9" do
|
|
72
|
-
Object.const_set :RUBY_VERSION, "1.8.6"
|
|
73
|
-
@method.should_receive(:to_s).and_return("method_name")
|
|
74
|
-
HaveInstanceMethodMatcher.new @method
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "does not convert the method name to a string if RUBY_VERSION >= 1.9" do
|
|
78
|
-
Object.const_set :RUBY_VERSION, "1.9.0"
|
|
79
|
-
@method.should_not_receive(:to_s)
|
|
80
|
-
HaveInstanceMethodMatcher.new @method
|
|
81
|
-
end
|
|
82
|
-
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
require 'mspec/expectations/expectations'
|
|
3
|
+
require 'mspec/matchers/have_method'
|
|
4
|
+
|
|
5
|
+
class HMMSpecs
|
|
6
|
+
def instance_method
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class Subclass < HMMSpecs
|
|
10
|
+
def instance_sub_method
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe HaveMethodMatcher do
|
|
16
|
+
it "inherits from MethodMatcher" do
|
|
17
|
+
HaveMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "matches when mod has the method" do
|
|
21
|
+
matcher = HaveMethodMatcher.new :instance_method
|
|
22
|
+
matcher.matches?(HMMSpecs).should be_true
|
|
23
|
+
matcher.matches?(HMMSpecs.new).should be_true
|
|
24
|
+
matcher.matches?(HMMSpecs::Subclass).should be_true
|
|
25
|
+
matcher.matches?(HMMSpecs::Subclass.new).should be_true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "does not match when mod does not have the method" do
|
|
29
|
+
matcher = HaveMethodMatcher.new :another_method
|
|
30
|
+
matcher.matches?(HMMSpecs).should be_false
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "does not match if the method is in a superclass and include_super is false" do
|
|
34
|
+
matcher = HaveMethodMatcher.new :instance_method, false
|
|
35
|
+
matcher.matches?(HMMSpecs::Subclass).should be_false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "provides a failure message for #should" do
|
|
39
|
+
matcher = HaveMethodMatcher.new :some_method
|
|
40
|
+
matcher.matches?(HMMSpecs)
|
|
41
|
+
matcher.failure_message.should == [
|
|
42
|
+
"Expected HMMSpecs to have method 'some_method'",
|
|
43
|
+
"but it does not"
|
|
44
|
+
]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "provides a failure messoge for #should_not" do
|
|
48
|
+
matcher = HaveMethodMatcher.new :some_method
|
|
49
|
+
matcher.matches?(HMMSpecs)
|
|
50
|
+
matcher.negative_failure_message.should == [
|
|
51
|
+
"Expected HMMSpecs NOT to have method 'some_method'",
|
|
52
|
+
"but it does"
|
|
53
|
+
]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -17,6 +17,10 @@ class HPIMMSpecs
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
describe HavePrivateInstanceMethodMatcher do
|
|
20
|
+
it "inherits from MethodMatcher" do
|
|
21
|
+
HavePrivateInstanceMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
|
|
22
|
+
end
|
|
23
|
+
|
|
20
24
|
it "matches when mod has the private instance method" do
|
|
21
25
|
matcher = HavePrivateInstanceMethodMatcher.new :private_method
|
|
22
26
|
matcher.matches?(HPIMMSpecs).should be_true
|
|
@@ -37,7 +41,7 @@ describe HavePrivateInstanceMethodMatcher do
|
|
|
37
41
|
matcher = HavePrivateInstanceMethodMatcher.new :some_method
|
|
38
42
|
matcher.matches?(HPIMMSpecs)
|
|
39
43
|
matcher.failure_message.should == [
|
|
40
|
-
"Expected HPIMMSpecs to have private method 'some_method'",
|
|
44
|
+
"Expected HPIMMSpecs to have private instance method 'some_method'",
|
|
41
45
|
"but it does not"
|
|
42
46
|
]
|
|
43
47
|
end
|
|
@@ -46,41 +50,8 @@ describe HavePrivateInstanceMethodMatcher do
|
|
|
46
50
|
matcher = HavePrivateInstanceMethodMatcher.new :some_method
|
|
47
51
|
matcher.matches?(HPIMMSpecs)
|
|
48
52
|
matcher.negative_failure_message.should == [
|
|
49
|
-
"Expected HPIMMSpecs NOT to have private method 'some_method'",
|
|
53
|
+
"Expected HPIMMSpecs NOT to have private instance method 'some_method'",
|
|
50
54
|
"but it does"
|
|
51
55
|
]
|
|
52
56
|
end
|
|
53
57
|
end
|
|
54
|
-
|
|
55
|
-
describe HavePrivateInstanceMethodMatcher do
|
|
56
|
-
before :all do
|
|
57
|
-
@verbose = $VERBOSE
|
|
58
|
-
$VERBOSE = nil
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
after :all do
|
|
62
|
-
$VERBOSE = @verbose
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
before :each do
|
|
66
|
-
@ruby_version = Object.const_get :RUBY_VERSION
|
|
67
|
-
|
|
68
|
-
@method = mock("method name")
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
after :each do
|
|
72
|
-
Object.const_set :RUBY_VERSION, @ruby_version
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "converts the method name to a string if RUBY_VERSION < 1.9" do
|
|
76
|
-
Object.const_set :RUBY_VERSION, "1.8.6"
|
|
77
|
-
@method.should_receive(:to_s).and_return("method_name")
|
|
78
|
-
HavePrivateInstanceMethodMatcher.new @method
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "does not convert the method name to a string if RUBY_VERSION >= 1.9" do
|
|
82
|
-
Object.const_set :RUBY_VERSION, "1.9.0"
|
|
83
|
-
@method.should_not_receive(:to_s)
|
|
84
|
-
HavePrivateInstanceMethodMatcher.new @method
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
require 'mspec/expectations/expectations'
|
|
3
|
+
require 'mspec/matchers/have_instance_method'
|
|
4
|
+
|
|
5
|
+
describe MethodMatcher do
|
|
6
|
+
before :all do
|
|
7
|
+
@verbose = $VERBOSE
|
|
8
|
+
$VERBOSE = nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after :all do
|
|
12
|
+
$VERBOSE = @verbose
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
before :each do
|
|
16
|
+
@ruby_version = Object.const_get :RUBY_VERSION
|
|
17
|
+
|
|
18
|
+
@method = mock("method name")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
after :each do
|
|
22
|
+
Object.const_set :RUBY_VERSION, @ruby_version
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "converts the method name to a string if RUBY_VERSION < 1.9" do
|
|
26
|
+
Object.const_set :RUBY_VERSION, "1.8.6"
|
|
27
|
+
@method.should_receive(:to_s).and_return("method_name")
|
|
28
|
+
MethodMatcher.new @method
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "does not convert the method name to a string if RUBY_VERSION >= 1.9" do
|
|
32
|
+
Object.const_set :RUBY_VERSION, "1.9.0"
|
|
33
|
+
@method.should_not_receive(:to_s)
|
|
34
|
+
MethodMatcher.new @method
|
|
35
|
+
end
|
|
36
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mspec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.5.
|
|
4
|
+
version: 1.5.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brian Ford
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-02-
|
|
12
|
+
date: 2009-02-09 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -77,9 +77,11 @@ files:
|
|
|
77
77
|
- lib/mspec/matchers/equal_element.rb
|
|
78
78
|
- lib/mspec/matchers/equal_utf16.rb
|
|
79
79
|
- lib/mspec/matchers/have_instance_method.rb
|
|
80
|
+
- lib/mspec/matchers/have_method.rb
|
|
80
81
|
- lib/mspec/matchers/have_private_instance_method.rb
|
|
81
82
|
- lib/mspec/matchers/include.rb
|
|
82
83
|
- lib/mspec/matchers/match_yaml.rb
|
|
84
|
+
- lib/mspec/matchers/method.rb
|
|
83
85
|
- lib/mspec/matchers/output.rb
|
|
84
86
|
- lib/mspec/matchers/output_to_fd.rb
|
|
85
87
|
- lib/mspec/matchers/raise_error.rb
|
|
@@ -184,9 +186,11 @@ files:
|
|
|
184
186
|
- spec/matchers/equal_spec.rb
|
|
185
187
|
- spec/matchers/equal_utf16_spec.rb
|
|
186
188
|
- spec/matchers/have_instance_method_spec.rb
|
|
189
|
+
- spec/matchers/have_method_spec.rb
|
|
187
190
|
- spec/matchers/have_private_instance_method_spec.rb
|
|
188
191
|
- spec/matchers/include_spec.rb
|
|
189
192
|
- spec/matchers/match_yaml_spec.rb
|
|
193
|
+
- spec/matchers/method_spec.rb
|
|
190
194
|
- spec/matchers/output_spec.rb
|
|
191
195
|
- spec/matchers/output_to_fd_spec.rb
|
|
192
196
|
- spec/matchers/raise_error_spec.rb
|