mspec 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README +101 -0
- data/Rakefile +44 -0
- data/bin/mkspec +7 -0
- data/bin/mspec +7 -0
- data/bin/mspec-ci +8 -0
- data/bin/mspec-run +8 -0
- data/bin/mspec-tag +8 -0
- data/lib/mspec.rb +6 -0
- data/lib/mspec/commands/mkspec.rb +147 -0
- data/lib/mspec/commands/mspec-ci.rb +71 -0
- data/lib/mspec/commands/mspec-run.rb +80 -0
- data/lib/mspec/commands/mspec-tag.rb +87 -0
- data/lib/mspec/commands/mspec.rb +143 -0
- data/lib/mspec/expectations.rb +2 -0
- data/lib/mspec/expectations/expectations.rb +12 -0
- data/lib/mspec/expectations/should.rb +23 -0
- data/lib/mspec/guards.rb +13 -0
- data/lib/mspec/guards/bug.rb +27 -0
- data/lib/mspec/guards/compliance.rb +18 -0
- data/lib/mspec/guards/conflict.rb +16 -0
- data/lib/mspec/guards/endian.rb +40 -0
- data/lib/mspec/guards/extensions.rb +12 -0
- data/lib/mspec/guards/guard.rb +120 -0
- data/lib/mspec/guards/noncompliance.rb +12 -0
- data/lib/mspec/guards/platform.rb +38 -0
- data/lib/mspec/guards/quarantine.rb +15 -0
- data/lib/mspec/guards/runner.rb +30 -0
- data/lib/mspec/guards/superuser.rb +15 -0
- data/lib/mspec/guards/support.rb +12 -0
- data/lib/mspec/guards/version.rb +40 -0
- data/lib/mspec/helpers.rb +6 -0
- data/lib/mspec/helpers/bignum.rb +5 -0
- data/lib/mspec/helpers/const_lookup.rb +5 -0
- data/lib/mspec/helpers/flunk.rb +5 -0
- data/lib/mspec/helpers/io.rb +13 -0
- data/lib/mspec/helpers/scratch.rb +17 -0
- data/lib/mspec/helpers/tmp.rb +32 -0
- data/lib/mspec/matchers.rb +16 -0
- data/lib/mspec/matchers/base.rb +95 -0
- data/lib/mspec/matchers/be_ancestor_of.rb +24 -0
- data/lib/mspec/matchers/be_close.rb +27 -0
- data/lib/mspec/matchers/be_empty.rb +20 -0
- data/lib/mspec/matchers/be_false.rb +20 -0
- data/lib/mspec/matchers/be_kind_of.rb +24 -0
- data/lib/mspec/matchers/be_nil.rb +20 -0
- data/lib/mspec/matchers/be_true.rb +20 -0
- data/lib/mspec/matchers/complain.rb +56 -0
- data/lib/mspec/matchers/eql.rb +26 -0
- data/lib/mspec/matchers/equal.rb +26 -0
- data/lib/mspec/matchers/equal_utf16.rb +34 -0
- data/lib/mspec/matchers/include.rb +32 -0
- data/lib/mspec/matchers/output.rb +67 -0
- data/lib/mspec/matchers/output_to_fd.rb +71 -0
- data/lib/mspec/matchers/raise_error.rb +48 -0
- data/lib/mspec/mocks.rb +3 -0
- data/lib/mspec/mocks/mock.rb +123 -0
- data/lib/mspec/mocks/object.rb +28 -0
- data/lib/mspec/mocks/proxy.rb +112 -0
- data/lib/mspec/runner.rb +13 -0
- data/lib/mspec/runner/actions.rb +6 -0
- data/lib/mspec/runner/actions/debug.rb +17 -0
- data/lib/mspec/runner/actions/filter.rb +40 -0
- data/lib/mspec/runner/actions/gdb.rb +17 -0
- data/lib/mspec/runner/actions/tag.rb +97 -0
- data/lib/mspec/runner/actions/tally.rb +80 -0
- data/lib/mspec/runner/actions/timer.rb +22 -0
- data/lib/mspec/runner/filters.rb +4 -0
- data/lib/mspec/runner/filters/match.rb +22 -0
- data/lib/mspec/runner/filters/profile.rb +54 -0
- data/lib/mspec/runner/filters/regexp.rb +7 -0
- data/lib/mspec/runner/filters/tag.rb +29 -0
- data/lib/mspec/runner/formatters.rb +7 -0
- data/lib/mspec/runner/formatters/dotted.rb +81 -0
- data/lib/mspec/runner/formatters/html.rb +87 -0
- data/lib/mspec/runner/formatters/specdoc.rb +27 -0
- data/lib/mspec/runner/formatters/spinner.rb +89 -0
- data/lib/mspec/runner/formatters/summary.rb +8 -0
- data/lib/mspec/runner/formatters/unit.rb +25 -0
- data/lib/mspec/runner/formatters/yaml.rb +43 -0
- data/lib/mspec/runner/mspec.rb +232 -0
- data/lib/mspec/runner/object.rb +20 -0
- data/lib/mspec/runner/shared.rb +12 -0
- data/lib/mspec/runner/state.rb +116 -0
- data/lib/mspec/runner/tag.rb +20 -0
- data/lib/mspec/utils/name_map.rb +130 -0
- data/lib/mspec/utils/options.rb +344 -0
- data/lib/mspec/utils/script.rb +77 -0
- data/lib/mspec/version.rb +3 -0
- data/spec/commands/mkspec_spec.rb +321 -0
- data/spec/commands/mspec_ci_spec.rb +139 -0
- data/spec/commands/mspec_run_spec.rb +146 -0
- data/spec/commands/mspec_spec.rb +359 -0
- data/spec/commands/mspec_tag_spec.rb +131 -0
- data/spec/expectations/expectations_spec.rb +16 -0
- data/spec/expectations/should_spec.rb +99 -0
- data/spec/guards/bug_spec.rb +137 -0
- data/spec/guards/compliance_spec.rb +70 -0
- data/spec/guards/conflict_spec.rb +20 -0
- data/spec/guards/endian_spec.rb +42 -0
- data/spec/guards/extensions_spec.rb +36 -0
- data/spec/guards/guard_spec.rb +355 -0
- data/spec/guards/noncompliance_spec.rb +36 -0
- data/spec/guards/platform_spec.rb +84 -0
- data/spec/guards/quarantine_spec.rb +19 -0
- data/spec/guards/runner_spec.rb +75 -0
- data/spec/guards/superuser_spec.rb +22 -0
- data/spec/guards/support_spec.rb +22 -0
- data/spec/guards/version_spec.rb +133 -0
- data/spec/helpers/bignum_spec.rb +11 -0
- data/spec/helpers/const_lookup_spec.rb +19 -0
- data/spec/helpers/flunk_spec.rb +15 -0
- data/spec/helpers/io_spec.rb +34 -0
- data/spec/helpers/scratch_spec.rb +22 -0
- data/spec/helpers/tmp_spec.rb +72 -0
- data/spec/matchers/base_spec.rb +180 -0
- data/spec/matchers/be_ancestor_of_spec.rb +28 -0
- data/spec/matchers/be_close_spec.rb +46 -0
- data/spec/matchers/be_empty_spec.rb +26 -0
- data/spec/matchers/be_false_spec.rb +28 -0
- data/spec/matchers/be_kind_of_spec.rb +29 -0
- data/spec/matchers/be_nil_spec.rb +27 -0
- data/spec/matchers/be_true_spec.rb +28 -0
- data/spec/matchers/complain_spec.rb +52 -0
- data/spec/matchers/eql_spec.rb +33 -0
- data/spec/matchers/equal_spec.rb +33 -0
- data/spec/matchers/equal_utf16_spec.rb +47 -0
- data/spec/matchers/include_spec.rb +37 -0
- data/spec/matchers/output_spec.rb +74 -0
- data/spec/matchers/output_to_fd_spec.rb +33 -0
- data/spec/matchers/raise_error_spec.rb +56 -0
- data/spec/mocks/mock_spec.rb +272 -0
- data/spec/mocks/proxy_spec.rb +259 -0
- data/spec/runner/actions/debug_spec.rb +61 -0
- data/spec/runner/actions/filter_spec.rb +84 -0
- data/spec/runner/actions/gdb_spec.rb +61 -0
- data/spec/runner/actions/tag_spec.rb +253 -0
- data/spec/runner/actions/tally_spec.rb +107 -0
- data/spec/runner/actions/timer_spec.rb +42 -0
- data/spec/runner/filters/a.yaml +4 -0
- data/spec/runner/filters/b.yaml +11 -0
- data/spec/runner/filters/match_spec.rb +44 -0
- data/spec/runner/filters/profile_spec.rb +117 -0
- data/spec/runner/filters/regexp_spec.rb +13 -0
- data/spec/runner/filters/tag_spec.rb +77 -0
- data/spec/runner/formatters/dotted_spec.rb +184 -0
- data/spec/runner/formatters/html_spec.rb +191 -0
- data/spec/runner/formatters/specdoc_spec.rb +57 -0
- data/spec/runner/formatters/spinner_spec.rb +78 -0
- data/spec/runner/formatters/summary_spec.rb +29 -0
- data/spec/runner/formatters/unit_spec.rb +71 -0
- data/spec/runner/formatters/yaml_spec.rb +123 -0
- data/spec/runner/mspec_spec.rb +393 -0
- data/spec/runner/shared_spec.rb +41 -0
- data/spec/runner/state_spec.rb +535 -0
- data/spec/runner/tag_spec.rb +93 -0
- data/spec/runner/tags.txt +3 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/utils/name_map_spec.rb +178 -0
- data/spec/utils/options_spec.rb +862 -0
- data/spec/utils/script_spec.rb +240 -0
- metadata +217 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe IOStub do
|
4
|
+
before :each do
|
5
|
+
@out = IOStub.new
|
6
|
+
@sep = $\
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
$\ = @sep
|
11
|
+
end
|
12
|
+
|
13
|
+
it "provides a write method" do
|
14
|
+
@out.write "this"
|
15
|
+
@out.should == "this"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "concatenates the arguments sent to write" do
|
19
|
+
@out.write "flim ", "flam"
|
20
|
+
@out.should == "flim flam"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "provides a print method that appends the default separator" do
|
24
|
+
$\ = " [newline] "
|
25
|
+
@out.print "hello"
|
26
|
+
@out.print "world"
|
27
|
+
@out.should == "hello [newline] world [newline] "
|
28
|
+
end
|
29
|
+
|
30
|
+
it "provides a puts method that appends the default separator" do
|
31
|
+
@out.puts "hello", 1, 2, 3
|
32
|
+
@out.should == "hello\n1\n2\n3\n"
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe ScratchPad do
|
4
|
+
it "records an object and returns a previously recorded object" do
|
5
|
+
ScratchPad.record :this
|
6
|
+
ScratchPad.recorded.should == :this
|
7
|
+
end
|
8
|
+
|
9
|
+
it "clears the recorded object" do
|
10
|
+
ScratchPad.record :that
|
11
|
+
ScratchPad.recorded.should == :that
|
12
|
+
ScratchPad.clear
|
13
|
+
ScratchPad.recorded.should == nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "provides a convenience shortcut to append to a previously recorded object" do
|
17
|
+
ScratchPad.record []
|
18
|
+
ScratchPad << :new
|
19
|
+
ScratchPad << :another
|
20
|
+
ScratchPad.recorded.should == [:new, :another]
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'mspec/helpers/tmp'
|
3
|
+
|
4
|
+
describe Object, "#tmp" do
|
5
|
+
before :each do
|
6
|
+
File.stub!(:directory?).and_return(false)
|
7
|
+
File.stub!(:symlink?).and_return(false)
|
8
|
+
ENV.stub!(:[]).and_return(nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns /tmp/<name> if /tmp is a writable directory" do
|
12
|
+
dir = "/tmp"
|
13
|
+
File.should_receive(:directory?).with(dir).and_return(true)
|
14
|
+
File.should_receive(:writable?).with(dir).and_return(true)
|
15
|
+
File.should_receive(:expand_path).with(dir).and_return(dir)
|
16
|
+
tmp("test.txt").should == dir + "/test.txt"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns /var/tmp/<name> if /var/tmp is a writable directory" do
|
20
|
+
dir = "/var/tmp"
|
21
|
+
File.should_receive(:directory?).with(dir).and_return(true)
|
22
|
+
File.should_receive(:writable?).with(dir).and_return(true)
|
23
|
+
File.should_receive(:expand_path).with(dir).and_return(dir)
|
24
|
+
tmp("test.txt").should == dir + "/test.txt"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns ENV['TMPDIR']/<name> if ENV['TMPDIR'] is a writable directory" do
|
28
|
+
dir = "/tmpdir"
|
29
|
+
ENV.should_receive(:[]).with("TMPDIR").and_return(dir)
|
30
|
+
File.should_receive(:directory?).with(dir).and_return(true)
|
31
|
+
File.should_receive(:writable?).with(dir).and_return(true)
|
32
|
+
File.should_receive(:expand_path).with(dir).and_return(dir)
|
33
|
+
tmp("test.txt").should == dir + "/test.txt"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns ENV['TMP']/<name> if ENV['TMP'] is a writable directory" do
|
37
|
+
dir = "/tmp/tmp"
|
38
|
+
ENV.should_receive(:[]).with("TMP").and_return(dir)
|
39
|
+
File.should_receive(:directory?).with(dir).and_return(true)
|
40
|
+
File.should_receive(:writable?).with(dir).and_return(true)
|
41
|
+
File.should_receive(:expand_path).with(dir).and_return(dir)
|
42
|
+
tmp("test.txt").should == dir + "/test.txt"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns ENV['TEMP']/<name> if ENV['TEMP'] is a writable directory" do
|
46
|
+
dir = "/tmp/temp"
|
47
|
+
ENV.should_receive(:[]).with("TEMP").and_return(dir)
|
48
|
+
File.should_receive(:directory?).with(dir).and_return(true)
|
49
|
+
File.should_receive(:writable?).with(dir).and_return(true)
|
50
|
+
File.should_receive(:expand_path).with(dir).and_return(dir)
|
51
|
+
tmp("test.txt").should == dir + "/test.txt"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns ENV['USERPROFILE']/<name> if ENV['USERPROFILE'] is a writable directory" do
|
55
|
+
dir = "/tmp/temp"
|
56
|
+
ENV.should_receive(:[]).with("TEMP").and_return(dir)
|
57
|
+
File.should_receive(:directory?).with(dir).and_return(true)
|
58
|
+
File.should_receive(:writable?).with(dir).and_return(true)
|
59
|
+
File.should_receive(:expand_path).with(dir).and_return(dir)
|
60
|
+
tmp("test.txt").should == dir + "/test.txt"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns the actual file name if the file is a symlink" do
|
64
|
+
dir = "/tmp"
|
65
|
+
File.should_receive(:directory?).with(dir).and_return(true)
|
66
|
+
File.should_receive(:writable?).with(dir).and_return(true)
|
67
|
+
File.should_receive(:expand_path).with(dir).and_return(dir)
|
68
|
+
File.should_receive(:symlink?).with(dir).and_return(true)
|
69
|
+
File.should_receive(:readlink).with(dir).and_return("/ponies"+dir)
|
70
|
+
tmp("test.txt").should == "/ponies" + dir + "/test.txt"
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'mspec/expectations/expectations'
|
3
|
+
require 'mspec/matchers/base'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
describe PositiveOperatorMatcher, "== operator" do
|
7
|
+
it "raises an ExpectationNotMetError when expected == actual returns false" do
|
8
|
+
lambda {
|
9
|
+
PositiveOperatorMatcher.new(1) == 2
|
10
|
+
}.should raise_error(ExpectationNotMetError, "Expected 1 to equal 2")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not raise an exception when expected == actual returns true" do
|
14
|
+
lambda {
|
15
|
+
PositiveOperatorMatcher.new(1) == 1
|
16
|
+
}.should_not raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe PositiveOperatorMatcher, "=~ operator" do
|
21
|
+
it "raises an ExpectationNotMetError when expected =~ actual returns false" do
|
22
|
+
lambda {
|
23
|
+
PositiveOperatorMatcher.new('real') =~ /fake/
|
24
|
+
}.should raise_error(ExpectationNotMetError, %(Expected "real" to match /fake/))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "does not raise an exception when expected =~ actual returns true" do
|
28
|
+
lambda {
|
29
|
+
PositiveOperatorMatcher.new('real') =~ /real/
|
30
|
+
}.should_not raise_error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe PositiveOperatorMatcher, "> operator" do
|
35
|
+
it "raises an ExpectationNotMetError when expected > actual returns false" do
|
36
|
+
lambda {
|
37
|
+
PositiveOperatorMatcher.new(4) > 5
|
38
|
+
}.should raise_error(ExpectationNotMetError, "Expected 4 to be greater than 5")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "does not raise an exception when expected > actual returns true" do
|
42
|
+
lambda {
|
43
|
+
PositiveOperatorMatcher.new(5) > 4
|
44
|
+
}.should_not raise_error
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe PositiveOperatorMatcher, ">= operator" do
|
49
|
+
it "raises an ExpectationNotMetError when expected >= actual returns false" do
|
50
|
+
lambda {
|
51
|
+
PositiveOperatorMatcher.new(4) >= 5
|
52
|
+
}.should raise_error(ExpectationNotMetError, "Expected 4 to be greater than or equal to 5")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "does not raise an exception when expected > actual returns true" do
|
56
|
+
lambda {
|
57
|
+
PositiveOperatorMatcher.new(5) >= 4
|
58
|
+
PositiveOperatorMatcher.new(5) >= 5
|
59
|
+
}.should_not raise_error
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe PositiveOperatorMatcher, "< operater" do
|
64
|
+
it "raises an ExpectationNotMetError when expected < actual returns false" do
|
65
|
+
lambda {
|
66
|
+
PositiveOperatorMatcher.new(5) < 4
|
67
|
+
}.should raise_error(ExpectationNotMetError, "Expected 5 to be less than 4")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not raise an exception when expected < actual returns true" do
|
71
|
+
lambda {
|
72
|
+
PositiveOperatorMatcher.new(4) < 5
|
73
|
+
}.should_not raise_error
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe PositiveOperatorMatcher, "<= operater" do
|
78
|
+
it "raises an ExpectationNotMetError when expected < actual returns false" do
|
79
|
+
lambda {
|
80
|
+
PositiveOperatorMatcher.new(5) <= 4
|
81
|
+
}.should raise_error(ExpectationNotMetError, "Expected 5 to be less than or equal to 4")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "does not raise an exception when expected < actual returns true" do
|
85
|
+
lambda {
|
86
|
+
PositiveOperatorMatcher.new(4) <= 5
|
87
|
+
PositiveOperatorMatcher.new(4) <= 4
|
88
|
+
}.should_not raise_error
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe NegativeOperatorMatcher, "== operator" do
|
93
|
+
it "raises an ExpectationNotMetError when expected == actual returns true" do
|
94
|
+
lambda {
|
95
|
+
NegativeOperatorMatcher.new(1) == 1
|
96
|
+
}.should raise_error(ExpectationNotMetError, "Expected 1 not to equal 1")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "does not raise an exception when expected == actual returns false" do
|
100
|
+
lambda {
|
101
|
+
NegativeOperatorMatcher.new(1) == 2
|
102
|
+
}.should_not raise_error
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe NegativeOperatorMatcher, "=~ operator" do
|
107
|
+
it "raises an ExpectationNotMetError when expected =~ actual returns true" do
|
108
|
+
lambda {
|
109
|
+
NegativeOperatorMatcher.new('real') =~ /real/
|
110
|
+
}.should raise_error(ExpectationNotMetError, %(Expected "real" not to match /real/))
|
111
|
+
end
|
112
|
+
|
113
|
+
it "does not raise an exception when expected =~ actual returns false" do
|
114
|
+
lambda {
|
115
|
+
NegativeOperatorMatcher.new('real') =~ /fake/
|
116
|
+
}.should_not raise_error
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe NegativeOperatorMatcher, "< operator" do
|
121
|
+
it "raises an ExpectationNotMetError when expected < actual returns true" do
|
122
|
+
lambda {
|
123
|
+
NegativeOperatorMatcher.new(4) < 5
|
124
|
+
}.should raise_error(ExpectationNotMetError, "Expected 4 not to be less than 5")
|
125
|
+
end
|
126
|
+
|
127
|
+
it "does not raise an exception when expected < actual returns false" do
|
128
|
+
lambda {
|
129
|
+
NegativeOperatorMatcher.new(5) < 4
|
130
|
+
}.should_not raise_error
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe NegativeOperatorMatcher, "<= operator" do
|
135
|
+
it "raises an ExpectationNotMetError when expected <= actual returns true" do
|
136
|
+
lambda {
|
137
|
+
NegativeOperatorMatcher.new(4) <= 5
|
138
|
+
}.should raise_error(ExpectationNotMetError, "Expected 4 not to be less than or equal to 5")
|
139
|
+
lambda {
|
140
|
+
NegativeOperatorMatcher.new(5) <= 5
|
141
|
+
}.should raise_error(ExpectationNotMetError, "Expected 5 not to be less than or equal to 5")
|
142
|
+
end
|
143
|
+
|
144
|
+
it "does not raise an exception when expected <= actual returns false" do
|
145
|
+
lambda {
|
146
|
+
NegativeOperatorMatcher.new(5) <= 4
|
147
|
+
}.should_not raise_error
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe NegativeOperatorMatcher, "> operator" do
|
152
|
+
it "raises an ExpectationNotMetError when expected > actual returns true" do
|
153
|
+
lambda {
|
154
|
+
NegativeOperatorMatcher.new(5) > 4
|
155
|
+
}.should raise_error(ExpectationNotMetError, "Expected 5 not to be greater than 4")
|
156
|
+
end
|
157
|
+
|
158
|
+
it "does not raise an exception when expected > actual returns false" do
|
159
|
+
lambda {
|
160
|
+
NegativeOperatorMatcher.new(4) > 5
|
161
|
+
}.should_not raise_error
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe NegativeOperatorMatcher, ">= operator" do
|
166
|
+
it "raises an ExpectationNotMetError when expected >= actual returns true" do
|
167
|
+
lambda {
|
168
|
+
NegativeOperatorMatcher.new(5) >= 4
|
169
|
+
}.should raise_error(ExpectationNotMetError, "Expected 5 not to be greater than or equal to 4")
|
170
|
+
lambda {
|
171
|
+
NegativeOperatorMatcher.new(5) >= 5
|
172
|
+
}.should raise_error(ExpectationNotMetError, "Expected 5 not to be greater than or equal to 5")
|
173
|
+
end
|
174
|
+
|
175
|
+
it "does not raise an exception when expected >= actual returns false" do
|
176
|
+
lambda {
|
177
|
+
NegativeOperatorMatcher.new(4) >= 5
|
178
|
+
}.should_not raise_error
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'mspec/expectations/expectations'
|
3
|
+
require 'mspec/matchers/be_ancestor_of'
|
4
|
+
|
5
|
+
class Parent; end
|
6
|
+
class Child < Parent; end
|
7
|
+
|
8
|
+
describe BeAncestorOfMatcher do
|
9
|
+
it "matches when actual is an ancestor of expected" do
|
10
|
+
BeAncestorOfMatcher.new(Child).matches?(Parent).should == true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not match when actual is not an ancestor of expected" do
|
14
|
+
BeAncestorOfMatcher.new(Parent).matches?(Child).should == false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "provides a useful failure message" do
|
18
|
+
matcher = BeAncestorOfMatcher.new(Parent)
|
19
|
+
matcher.matches?(Child)
|
20
|
+
matcher.failure_message.should == ["Expected Child", "to be an ancestor of Parent"]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "provides a useful negative failure message" do
|
24
|
+
matcher = BeAncestorOfMatcher.new(Child)
|
25
|
+
matcher.matches?(Parent)
|
26
|
+
matcher.negative_failure_message.should == ["Expected Parent", "not to be an ancestor of Child"]
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'mspec/expectations/expectations'
|
3
|
+
require 'mspec/matchers/be_close'
|
4
|
+
|
5
|
+
# Adapted from RSpec 1.0.8
|
6
|
+
describe BeCloseMatcher do
|
7
|
+
it "matches when actual == expected" do
|
8
|
+
BeCloseMatcher.new(5.0, 0.5).matches?(5.0).should == true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "matches when actual < (expected + tolerance)" do
|
12
|
+
BeCloseMatcher.new(5.0, 0.5).matches?(5.49).should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "matches when actual > (expected - tolerance)" do
|
16
|
+
BeCloseMatcher.new(5.0, 0.5).matches?(4.51).should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "does not match when actual == (expected + tolerance)" do
|
20
|
+
BeCloseMatcher.new(5.0, 0.5).matches?(5.5).should == false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not match when actual == (expected - tolerance)" do
|
24
|
+
BeCloseMatcher.new(5.0, 0.5).matches?(4.5).should == false
|
25
|
+
end
|
26
|
+
|
27
|
+
it "does not match when actual < (expected - tolerance)" do
|
28
|
+
BeCloseMatcher.new(5.0, 0.5).matches?(4.49).should == false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "does not match when actual > (expected + tolerance)" do
|
32
|
+
BeCloseMatcher.new(5.0, 0.5).matches?(5.51).should == false
|
33
|
+
end
|
34
|
+
|
35
|
+
it "provides a useful failure message" do
|
36
|
+
matcher = BeCloseMatcher.new(5.0, 0.5)
|
37
|
+
matcher.matches?(5.51)
|
38
|
+
matcher.failure_message.should == ["Expected 5.0", "to be within +/- 0.5 of 5.51"]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "provides a useful negative failure message" do
|
42
|
+
matcher = BeCloseMatcher.new(5.0, 0.5)
|
43
|
+
matcher.matches?(5.0)
|
44
|
+
matcher.negative_failure_message.should == ["Expected 5.0", "not to be within +/- 0.5 of 5.0"]
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'mspec/expectations/expectations'
|
3
|
+
require 'mspec/matchers/be_empty'
|
4
|
+
|
5
|
+
describe BeEmptyMatcher do
|
6
|
+
it "matches when actual is empty" do
|
7
|
+
BeEmptyMatcher.new.matches?("").should == true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "does not match when actual is not empty" do
|
11
|
+
BeEmptyMatcher.new.matches?([10]).should == false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "provides a useful failure message" do
|
15
|
+
matcher = BeEmptyMatcher.new
|
16
|
+
matcher.matches?("not empty string")
|
17
|
+
matcher.failure_message.should == ["Expected \"not empty string\"", "to be empty"]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "provides a useful negative failure message" do
|
21
|
+
matcher = BeEmptyMatcher.new
|
22
|
+
matcher.matches?("")
|
23
|
+
matcher.negative_failure_message.should == ["Expected \"\"", "not to be empty"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'mspec/expectations/expectations'
|
3
|
+
require 'mspec/matchers/be_false'
|
4
|
+
|
5
|
+
describe BeFalseMatcher do
|
6
|
+
it "matches when actual is false" do
|
7
|
+
BeFalseMatcher.new.matches?(false).should == true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "does not match when actual is not false" do
|
11
|
+
BeFalseMatcher.new.matches?("").should == false
|
12
|
+
BeFalseMatcher.new.matches?(true).should == false
|
13
|
+
BeFalseMatcher.new.matches?(nil).should == false
|
14
|
+
BeFalseMatcher.new.matches?(0).should == false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "provides a useful failure message" do
|
18
|
+
matcher = BeFalseMatcher.new
|
19
|
+
matcher.matches?("some string")
|
20
|
+
matcher.failure_message.should == ["Expected \"some string\"", "to be false"]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "provides a useful negative failure message" do
|
24
|
+
matcher = BeFalseMatcher.new
|
25
|
+
matcher.matches?(false)
|
26
|
+
matcher.negative_failure_message.should == ["Expected false", "not to be false"]
|
27
|
+
end
|
28
|
+
end
|