spicycode-micronaut 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +23 -10
- data/examples/example_helper.rb +3 -3
- data/examples/lib/micronaut/behaviour_group_example.rb +175 -0
- data/examples/lib/micronaut/expectations/differs/default_example.rb +1 -2
- data/examples/lib/micronaut/expectations/extensions/object_example.rb +15 -8
- data/examples/lib/micronaut/expectations/fail_with_example.rb +2 -2
- data/examples/lib/micronaut/matchers/be_close_example.rb +42 -0
- data/examples/lib/micronaut/matchers/be_example.rb +257 -0
- data/examples/lib/micronaut/matchers/change_example.rb +329 -0
- data/examples/lib/micronaut/matchers/description_generation_example.rb +167 -0
- data/examples/lib/micronaut/matchers/eql_example.rb +29 -0
- data/examples/lib/micronaut/matchers/equal_example.rb +29 -0
- data/examples/lib/micronaut/matchers/exist_example.rb +69 -0
- data/examples/lib/micronaut/matchers/handler_example.rb +146 -0
- data/examples/lib/micronaut/matchers/has_example.rb +63 -0
- data/examples/lib/micronaut/matchers/have_example.rb +575 -0
- data/examples/lib/micronaut/matchers/include_example.rb +88 -0
- data/examples/lib/micronaut/matchers/match_example.rb +41 -0
- data/examples/lib/micronaut/matchers/matcher_methods_example.rb +66 -0
- data/examples/lib/micronaut/matchers/operator_matcher_example.rb +191 -0
- data/examples/lib/micronaut/matchers/raise_error_example.rb +315 -0
- data/examples/lib/micronaut/matchers/respond_to_example.rb +54 -0
- data/examples/lib/micronaut/matchers/satisfy_example.rb +36 -0
- data/examples/lib/micronaut/matchers/simple_matcher_example.rb +93 -0
- data/examples/lib/micronaut/matchers/throw_symbol_example.rb +96 -0
- data/examples/resources/example_classes.rb +67 -0
- data/lib/autotest/micronaut.rb +9 -4
- data/lib/micronaut/behaviour_group.rb +43 -0
- data/lib/micronaut/behaviour_group_class_methods.rb +134 -0
- data/lib/micronaut/example_runner.rb +7 -9
- data/lib/micronaut/example_world.rb +11 -7
- data/lib/micronaut/expectations/differs/default.rb +6 -15
- data/lib/micronaut/expectations/errors.rb +7 -0
- data/lib/micronaut/expectations/{object_extensions.rb → extensions/object.rb} +5 -4
- data/lib/micronaut/expectations/{string_and_symbol_extensions.rb → extensions/string_and_symbol.rb} +0 -0
- data/lib/micronaut/expectations/extensions.rb +2 -0
- data/lib/micronaut/expectations/wrap_expectation.rb +5 -0
- data/lib/micronaut/expectations.rb +5 -5
- data/lib/micronaut/extensions/kernel.rb +2 -4
- data/lib/micronaut/matchers/be_close.rb +6 -22
- data/lib/micronaut/matchers/eql.rb +7 -25
- data/lib/micronaut/matchers/equal.rb +6 -24
- data/lib/micronaut/matchers/exist.rb +8 -14
- data/lib/micronaut/matchers/has.rb +12 -28
- data/lib/micronaut/matchers/include.rb +12 -9
- data/lib/micronaut/matchers/match.rb +8 -27
- data/lib/micronaut/matchers/method_missing.rb +1 -1
- data/lib/micronaut/matchers/operator_matcher.rb +23 -46
- data/lib/micronaut/matchers/raise_error.rb +4 -8
- data/lib/micronaut/matchers/respond_to.rb +2 -1
- data/lib/micronaut/matchers/throw_symbol.rb +9 -3
- data/lib/micronaut/matchers.rb +10 -3
- data/lib/micronaut/mocking/with_mocha.rb +0 -1
- data/lib/micronaut.rb +3 -3
- metadata +31 -7
- data/examples/lib/micronaut/example_group_example.rb +0 -116
- data/lib/micronaut/example_group.rb +0 -100
- data/lib/micronaut/exceptions.rb +0 -7
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rubygems/specification'
|
|
4
4
|
require 'date'
|
5
5
|
|
6
6
|
GEM = "micronaut"
|
7
|
-
GEM_VERSION = "0.0.
|
7
|
+
GEM_VERSION = "0.0.3"
|
8
8
|
AUTHOR = "Chad Humphries"
|
9
9
|
EMAIL = "chad@spicycode.com"
|
10
10
|
HOMEPAGE = "http://spicycode.com"
|
@@ -30,14 +30,6 @@ spec = Gem::Specification.new do |s|
|
|
30
30
|
s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,examples}/**/*")
|
31
31
|
end
|
32
32
|
|
33
|
-
desc "Run all examples"
|
34
|
-
task :default do
|
35
|
-
examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
|
36
|
-
examples.map! {|f| %Q(require "#{f}")}
|
37
|
-
command = "-e '#{examples.join("; ")}'"
|
38
|
-
ruby command
|
39
|
-
end
|
40
|
-
|
41
33
|
Rake::GemPackageTask.new(spec) do |pkg|
|
42
34
|
pkg.gem_spec = spec
|
43
35
|
end
|
@@ -52,4 +44,25 @@ task :make_spec do
|
|
52
44
|
File.open("#{GEM}.gemspec", "w") do |file|
|
53
45
|
file.puts spec.to_ruby
|
54
46
|
end
|
55
|
-
end
|
47
|
+
end
|
48
|
+
|
49
|
+
namespace :micronaut do
|
50
|
+
|
51
|
+
desc 'Run all examples'
|
52
|
+
task :examples do
|
53
|
+
examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
|
54
|
+
examples.map! {|f| %Q(require "#{f}")}
|
55
|
+
command = "-e '#{examples.join("; ")}'"
|
56
|
+
ruby command
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Run all examples using rcov"
|
60
|
+
task :coverage do
|
61
|
+
examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
|
62
|
+
system "rcov --exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-report --sort coverage --no-validator-links #{examples.join(' ')}"
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
task :default => 'micronaut:coverage'
|
68
|
+
|
data/examples/example_helper.rb
CHANGED
@@ -2,16 +2,16 @@ lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib")
|
|
2
2
|
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
3
3
|
|
4
4
|
require 'micronaut'
|
5
|
-
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + "/resources/example_classes")
|
6
6
|
|
7
7
|
module Micronaut
|
8
8
|
module Matchers
|
9
9
|
def fail
|
10
|
-
raise_error(::Micronaut::
|
10
|
+
raise_error(::Micronaut::Expectations::ExpectationNotMetError)
|
11
11
|
end
|
12
12
|
|
13
13
|
def fail_with(message)
|
14
|
-
raise_error(::Micronaut::
|
14
|
+
raise_error(::Micronaut::Expectations::ExpectationNotMetError, message)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
|
2
|
+
|
3
|
+
describe Micronaut::BehaviourGroup do
|
4
|
+
|
5
|
+
class Foo
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def empty_behaviour_group
|
10
|
+
Micronaut::BehaviourGroup.describe(Foo, 'Empty Behaviour Group') { }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "describing behaviour with #describe" do
|
14
|
+
|
15
|
+
it "should raise an ArgumentError if no name is given" do
|
16
|
+
lambda { Micronaut::BehaviourGroup.describe() {} }.should raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise an ArgumentError if no block is given" do
|
20
|
+
lambda { Micronaut::BehaviourGroup.describe('foo') }.should raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#name' do
|
24
|
+
|
25
|
+
it "should expose the first parameter as name" do
|
26
|
+
Micronaut::BehaviourGroup.describe("my favorite pony") { }.name.should == 'my favorite pony'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should call to_s on the first parameter in case it is a constant" do
|
30
|
+
Micronaut::BehaviourGroup.describe(Foo) { }.name.should == 'Foo'
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#described_type' do
|
36
|
+
|
37
|
+
it "should be the first parameter when it is a constant" do
|
38
|
+
Micronaut::BehaviourGroup.describe(Foo) { }.described_type.should == Foo
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be Object when the first parameter is a string" do
|
42
|
+
Micronaut::BehaviourGroup.describe("i'm a computer") { }.described_type.should == Object
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#description' do
|
48
|
+
|
49
|
+
it "should expose the second parameter as description" do
|
50
|
+
Micronaut::BehaviourGroup.describe(Foo, "my desc") { }.description.should == 'my desc'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should allow the second parameter to be nil" do
|
54
|
+
Micronaut::BehaviourGroup.describe(Foo, nil) { }.description.should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#options' do
|
60
|
+
|
61
|
+
it "should expose the third parameter as options" do
|
62
|
+
Micronaut::BehaviourGroup.describe(Foo, nil, 'foo' => 'bar') { }.options.should == { "foo" => 'bar' }
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should be an empty hash if no options are supplied" do
|
66
|
+
Micronaut::BehaviourGroup.describe(Foo, nil) { }.options.should == {}
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "adding before and after hooks" do
|
72
|
+
|
73
|
+
it "should expose the before each blocks at before_eachs" do
|
74
|
+
group = empty_behaviour_group
|
75
|
+
group.before(:each) { 'foo' }
|
76
|
+
group.should have(1).before_eachs
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should maintain the before each block order" do
|
80
|
+
group = empty_behaviour_group
|
81
|
+
group.before(:each) { 15 }
|
82
|
+
group.before(:each) { 'A' }
|
83
|
+
group.before(:each) { 33.5 }
|
84
|
+
|
85
|
+
group.before_eachs[0].call.should == 15
|
86
|
+
group.before_eachs[1].call.should == 'A'
|
87
|
+
group.before_eachs[2].call.should == 33.5
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should expose the before all blocks at before_alls" do
|
91
|
+
group = empty_behaviour_group
|
92
|
+
group.before(:all) { 'foo' }
|
93
|
+
group.should have(1).before_alls
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should maintain the before all block order" do
|
97
|
+
group = empty_behaviour_group
|
98
|
+
group.before(:all) { 15 }
|
99
|
+
group.before(:all) { 'A' }
|
100
|
+
group.before(:all) { 33.5 }
|
101
|
+
|
102
|
+
group.before_alls[0].call.should == 15
|
103
|
+
group.before_alls[1].call.should == 'A'
|
104
|
+
group.before_alls[2].call.should == 33.5
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should expose the after each blocks at after_eachs" do
|
108
|
+
group = empty_behaviour_group
|
109
|
+
group.after(:each) { 'foo' }
|
110
|
+
group.should have(1).after_eachs
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should maintain the after each block order" do
|
114
|
+
group = empty_behaviour_group
|
115
|
+
group.after(:each) { 15 }
|
116
|
+
group.after(:each) { 'A' }
|
117
|
+
group.after(:each) { 33.5 }
|
118
|
+
|
119
|
+
group.after_eachs[0].call.should == 15
|
120
|
+
group.after_eachs[1].call.should == 'A'
|
121
|
+
group.after_eachs[2].call.should == 33.5
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should expose the after all blocks at after_alls" do
|
125
|
+
group = empty_behaviour_group
|
126
|
+
group.after(:all) { 'foo' }
|
127
|
+
group.should have(1).after_alls
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should maintain the after each block order" do
|
131
|
+
group = empty_behaviour_group
|
132
|
+
group.after(:all) { 15 }
|
133
|
+
group.after(:all) { 'A' }
|
134
|
+
group.after(:all) { 33.5 }
|
135
|
+
|
136
|
+
group.after_alls[0].call.should == 15
|
137
|
+
group.after_alls[1].call.should == 'A'
|
138
|
+
group.after_alls[2].call.should == 33.5
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "adding examples" do
|
144
|
+
|
145
|
+
it "should allow adding an example using 'it'" do
|
146
|
+
group = empty_behaviour_group
|
147
|
+
group.it("should do something") { }
|
148
|
+
group.examples.size.should == 1
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should expose all examples at examples" do
|
152
|
+
group = empty_behaviour_group
|
153
|
+
group.it("should do something 1") { }
|
154
|
+
group.it("should do something 2") { }
|
155
|
+
group.it("should do something 3") { }
|
156
|
+
group.examples.size.should == 3
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should maintain the example order" do
|
160
|
+
group = empty_behaviour_group
|
161
|
+
group.it("should 1") { }
|
162
|
+
group.it("should 2") { }
|
163
|
+
group.it("should 3") { }
|
164
|
+
group.examples[0].first.should == 'should 1'
|
165
|
+
group.examples[1].first.should == 'should 2'
|
166
|
+
group.examples[2].first.should == 'should 3'
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
end
|
@@ -21,7 +21,6 @@ module Micronaut
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "Diff" do
|
24
|
-
|
25
24
|
before do
|
26
25
|
@differ = Micronaut::Expectations::Differs::Default.new(:unified)
|
27
26
|
end
|
@@ -97,7 +96,7 @@ end
|
|
97
96
|
|
98
97
|
|
99
98
|
describe "Diff in context format" do
|
100
|
-
before
|
99
|
+
before do
|
101
100
|
@differ = Micronaut::Expectations::Differs::Default.new(:context)
|
102
101
|
end
|
103
102
|
|
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../../example_helper")
|
|
2
2
|
|
3
3
|
describe Object, "#should" do
|
4
4
|
|
5
|
-
before
|
5
|
+
before do
|
6
6
|
@target = "target"
|
7
7
|
@matcher = mock("matcher")
|
8
8
|
@matcher.stubs(:matches?).returns(true)
|
@@ -17,27 +17,34 @@ describe Object, "#should" do
|
|
17
17
|
it "should ask for a failure_message when matches? returns false" do
|
18
18
|
@matcher.expects(:matches?).with(@target).returns(false)
|
19
19
|
@matcher.expects(:failure_message).returns("the failure message")
|
20
|
-
|
21
|
-
|
20
|
+
lambda {
|
21
|
+
@target.should @matcher
|
22
|
+
}.should fail_with("the failure message")
|
22
23
|
end
|
23
24
|
|
24
25
|
it "should raise error if it receives false directly" do
|
25
|
-
lambda {
|
26
|
+
lambda {
|
27
|
+
@target.should false
|
28
|
+
}.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
26
29
|
end
|
27
30
|
|
28
31
|
it "should raise error if it receives false (evaluated)" do
|
29
|
-
lambda {
|
32
|
+
lambda {
|
33
|
+
@target.should eql?("foo")
|
34
|
+
}.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
30
35
|
end
|
31
36
|
|
32
37
|
it "should raise error if it receives true" do
|
33
|
-
lambda {
|
38
|
+
lambda {
|
39
|
+
@target.should true
|
40
|
+
}.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
34
41
|
end
|
35
42
|
|
36
43
|
end
|
37
44
|
|
38
45
|
describe Object, "#should_not" do
|
39
46
|
|
40
|
-
before
|
47
|
+
before do
|
41
48
|
@target = "target"
|
42
49
|
@matcher = mock("matcher")
|
43
50
|
end
|
@@ -74,5 +81,5 @@ describe Object, "#should_not" do
|
|
74
81
|
@target.should_not true
|
75
82
|
}.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
76
83
|
end
|
77
|
-
|
84
|
+
|
78
85
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
2
|
|
3
3
|
describe Micronaut::Expectations, "#fail_with with no diff" do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@old_differ = Micronaut::Expectations.differ
|
6
6
|
Micronaut::Expectations.differ = nil
|
7
7
|
end
|
@@ -24,7 +24,7 @@ describe Micronaut::Expectations, "#fail_with with no diff" do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe Micronaut::Expectations, "#fail_with with diff" do
|
27
|
-
before
|
27
|
+
before do
|
28
28
|
@old_differ = Micronaut::Expectations.differ
|
29
29
|
@differ = mock("differ")
|
30
30
|
Micronaut::Expectations.differ = @differ
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
module Micronaut
|
4
|
+
module Matchers
|
5
|
+
describe "be_close" do
|
6
|
+
it "should match when value == target" do
|
7
|
+
be_close(5.0, 0.5).matches?(5.0).should be_true
|
8
|
+
end
|
9
|
+
it "should match when value < (target + delta)" do
|
10
|
+
be_close(5.0, 0.5).matches?(5.49).should be_true
|
11
|
+
end
|
12
|
+
it "should match when value > (target - delta)" do
|
13
|
+
be_close(5.0, 0.5).matches?(4.51).should be_true
|
14
|
+
end
|
15
|
+
it "should not match when value == (target - delta)" do
|
16
|
+
be_close(5.0, 0.5).matches?(4.5).should be_false
|
17
|
+
end
|
18
|
+
it "should not match when value < (target - delta)" do
|
19
|
+
be_close(5.0, 0.5).matches?(4.49).should be_false
|
20
|
+
end
|
21
|
+
it "should not match when value == (target + delta)" do
|
22
|
+
be_close(5.0, 0.5).matches?(5.5).should be_false
|
23
|
+
end
|
24
|
+
it "should not match when value > (target + delta)" do
|
25
|
+
be_close(5.0, 0.5).matches?(5.51).should be_false
|
26
|
+
end
|
27
|
+
it "should provide a useful failure message" do
|
28
|
+
#given
|
29
|
+
matcher = be_close(5.0, 0.5)
|
30
|
+
#when
|
31
|
+
matcher.matches?(5.51)
|
32
|
+
#then
|
33
|
+
matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
|
34
|
+
end
|
35
|
+
it "should describe itself" do
|
36
|
+
matcher = be_close(5.0, 0.5)
|
37
|
+
matcher.matches?(5.1)
|
38
|
+
matcher.description.should == "be close to 5.0 (within +- 0.5)"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,257 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
describe "should be_predicate" do
|
4
|
+
it "should pass when actual returns true for :predicate?" do
|
5
|
+
actual = stub("actual", :happy? => true)
|
6
|
+
actual.should be_happy
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should pass when actual returns true for :predicates? (present tense)" do
|
10
|
+
actual = stub("actual", :exists? => true, :exist? => true)
|
11
|
+
actual.should be_exist
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should fail when actual returns false for :predicate?" do
|
15
|
+
actual = stub("actual", :happy? => false)
|
16
|
+
lambda {
|
17
|
+
actual.should be_happy
|
18
|
+
}.should fail_with("expected happy? to return true, got false")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should fail when actual does not respond to :predicate?" do
|
22
|
+
lambda {
|
23
|
+
Object.new.should be_happy
|
24
|
+
}.should raise_error(NameError, /happy\?/)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should fail on error other than NameError" do
|
28
|
+
actual = stub("actual")
|
29
|
+
actual.expects(:foo?).raises("aaaah")
|
30
|
+
lambda {
|
31
|
+
actual.should be_foo
|
32
|
+
}.should raise_error(/aaaah/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should fail on error other than NameError (with the present tense predicate)" do
|
36
|
+
actual = Object.new
|
37
|
+
actual.expects(:foos?).raises("aaaah")
|
38
|
+
lambda {
|
39
|
+
actual.should be_foo
|
40
|
+
}.should raise_error(/aaaah/)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "should_not be_predicate" do
|
45
|
+
it "should pass when actual returns false for :sym?" do
|
46
|
+
actual = stub("actual", :happy? => false)
|
47
|
+
actual.should_not be_happy
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should fail when actual returns true for :sym?" do
|
51
|
+
actual = stub("actual", :happy? => true)
|
52
|
+
lambda {
|
53
|
+
actual.should_not be_happy
|
54
|
+
}.should fail_with("expected happy? to return false, got true")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should fail when actual does not respond to :sym?" do
|
58
|
+
lambda {
|
59
|
+
Object.new.should_not be_happy
|
60
|
+
}.should raise_error(NameError)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "should be_predicate(*args)" do
|
65
|
+
it "should pass when actual returns true for :predicate?(*args)" do
|
66
|
+
actual = mock("actual")
|
67
|
+
actual.expects(:older_than?).with(3).returns(true)
|
68
|
+
actual.should be_older_than(3)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should fail when actual returns false for :predicate?(*args)" do
|
72
|
+
actual = mock("actual")
|
73
|
+
actual.expects(:older_than?).with(3).returns(false)
|
74
|
+
lambda {
|
75
|
+
actual.should be_older_than(3)
|
76
|
+
}.should fail_with("expected older_than?(3) to return true, got false")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should fail when actual does not respond to :predicate?" do
|
80
|
+
lambda {
|
81
|
+
Object.new.should be_older_than(3)
|
82
|
+
}.should raise_error(NameError)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "should_not be_predicate(*args)" do
|
87
|
+
it "should pass when actual returns false for :predicate?(*args)" do
|
88
|
+
actual = mock("actual")
|
89
|
+
actual.expects(:older_than?).with(3).returns(false)
|
90
|
+
actual.should_not be_older_than(3)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should fail when actual returns true for :predicate?(*args)" do
|
94
|
+
actual = mock("actual")
|
95
|
+
actual.expects(:older_than?).with(3).returns(true)
|
96
|
+
lambda {
|
97
|
+
actual.should_not be_older_than(3)
|
98
|
+
}.should fail_with("expected older_than?(3) to return false, got true")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should fail when actual does not respond to :predicate?" do
|
102
|
+
lambda {
|
103
|
+
Object.new.should_not be_older_than(3)
|
104
|
+
}.should raise_error(NameError)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "should be_true" do
|
109
|
+
it "should pass when actual equal(true)" do
|
110
|
+
true.should be_true
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should fail when actual equal(false)" do
|
114
|
+
lambda {
|
115
|
+
false.should be_true
|
116
|
+
}.should fail_with("expected true, got false")
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "should be_false" do
|
121
|
+
it "should pass when actual equal(false)" do
|
122
|
+
false.should be_false
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should fail when actual equal(true)" do
|
126
|
+
lambda {
|
127
|
+
true.should be_false
|
128
|
+
}.should fail_with("expected false, got true")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "should be_nil" do
|
133
|
+
it "should pass when actual is nil" do
|
134
|
+
nil.should be_nil
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should fail when actual is not nil" do
|
138
|
+
lambda {
|
139
|
+
:not_nil.should be_nil
|
140
|
+
}.should fail_with("expected nil? to return true, got false")
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "should_not be_nil" do
|
145
|
+
it "should pass when actual is not nil" do
|
146
|
+
:not_nil.should_not be_nil
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should fail when actual is nil" do
|
150
|
+
lambda {
|
151
|
+
nil.should_not be_nil
|
152
|
+
}.should fail_with("expected nil? to return false, got true")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "should be <" do
|
157
|
+
it "should pass when < operator returns true" do
|
158
|
+
3.should be < 4
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should fail when < operator returns false" do
|
162
|
+
lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "should be <=" do
|
167
|
+
it "should pass when <= operator returns true" do
|
168
|
+
3.should be <= 4
|
169
|
+
4.should be <= 4
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should fail when <= operator returns false" do
|
173
|
+
lambda { 3.should be <= 2 }.should fail_with("expected <= 2, got 3")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "should be >=" do
|
178
|
+
it "should pass when >= operator returns true" do
|
179
|
+
4.should be >= 4
|
180
|
+
5.should be >= 4
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should fail when >= operator returns false" do
|
184
|
+
lambda { 3.should be >= 4 }.should fail_with("expected >= 4, got 3")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "should be >" do
|
189
|
+
it "should pass when > operator returns true" do
|
190
|
+
5.should be > 4
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should fail when > operator returns false" do
|
194
|
+
lambda { 3.should be > 4 }.should fail_with("expected > 4, got 3")
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "should be ==" do
|
199
|
+
it "should pass when == operator returns true" do
|
200
|
+
5.should be == 5
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should fail when == operator returns false" do
|
204
|
+
lambda { 3.should be == 4 }.should fail_with("expected == 4, got 3")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "should be ===" do
|
209
|
+
it "should pass when === operator returns true" do
|
210
|
+
Hash.should be === Hash.new
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should fail when === operator returns false" do
|
214
|
+
lambda { Hash.should be === "not a hash" }.should fail_with(%[expected === not a hash, got Hash])
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "should_not with operators" do
|
219
|
+
it "should coach user to stop using operators with should_not" do
|
220
|
+
lambda {
|
221
|
+
5.should_not be < 6
|
222
|
+
}.should raise_error(/not only FAILED,\nit reads really poorly./m)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "should be" do
|
227
|
+
it "should pass if actual is true or a set value" do
|
228
|
+
true.should be
|
229
|
+
1.should be
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should fail if actual is false" do
|
233
|
+
lambda {false.should be}.should fail_with("expected true, got false")
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should fail if actual is nil" do
|
237
|
+
lambda {nil.should be}.should fail_with("expected true, got nil")
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe "should be(value)" do
|
242
|
+
it "should pass if actual.equal?(value)" do
|
243
|
+
5.should be(5)
|
244
|
+
end
|
245
|
+
it "should fail if !actual.equal?(value)" do
|
246
|
+
lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe "'should be' with operator" do
|
251
|
+
it "should include 'be' in the description" do
|
252
|
+
(be > 6).description.should =~ /be > 6/
|
253
|
+
(be >= 6).description.should =~ /be >= 6/
|
254
|
+
(be <= 6).description.should =~ /be <= 6/
|
255
|
+
(be < 6).description.should =~ /be < 6/
|
256
|
+
end
|
257
|
+
end
|