expectations 0.1.0 → 0.1.1
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/lib/expectations/behavior_based_expectation.rb +1 -1
- data/lib/expectations/module.rb +7 -0
- data/lib/expectations/object.rb +4 -0
- data/lib/expectations/range.rb +7 -0
- data/lib/expectations/regexp.rb +7 -0
- data/lib/expectations/results.rb +2 -10
- data/lib/expectations/state_based_expectation.rb +2 -2
- data/lib/expectations.rb +3 -0
- data/rakefile.rb +1 -1
- data/test/expectations/expectation_test.rb +1 -1
- data/test/expectations/results_test.rb +2 -2
- data/test/failures.rb +112 -0
- data/test/sample_expectations_test.rb +30 -0
- metadata +6 -2
@@ -9,7 +9,7 @@ module Expectations::BehaviorBasedExpectation
|
|
9
9
|
self.extend(Expectations::Results::BehaviorFailure)
|
10
10
|
self.message = ex.message
|
11
11
|
rescue Exception => ex
|
12
|
-
self.extend(Expectations::Results::
|
12
|
+
self.extend(Expectations::Results::Error)
|
13
13
|
self.exception = ex
|
14
14
|
ensure
|
15
15
|
mocha_teardown
|
data/lib/expectations/object.rb
CHANGED
data/lib/expectations/results.rb
CHANGED
@@ -12,7 +12,7 @@ module Expectations::Results
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def error?
|
15
|
-
self.is_a?(Expectations::Results::
|
15
|
+
self.is_a?(Expectations::Results::Error)
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.included(klass)
|
@@ -56,15 +56,7 @@ module Expectations::Results
|
|
56
56
|
end
|
57
57
|
|
58
58
|
module Expectations::Results
|
59
|
-
module
|
60
|
-
attr_accessor :exception, :message
|
61
|
-
include Expectations::Results
|
62
|
-
char "E"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
module Expectations::Results
|
67
|
-
module StateBasedError
|
59
|
+
module Error
|
68
60
|
attr_accessor :exception, :message
|
69
61
|
include Expectations::Results
|
70
62
|
char "E"
|
@@ -3,10 +3,10 @@ module Expectations::StateBasedExpectation
|
|
3
3
|
begin
|
4
4
|
mocha_setup
|
5
5
|
self.actual = instance_eval &block
|
6
|
-
return self.extend(Expectations::Results::Fulfilled) if expected
|
6
|
+
return self.extend(Expectations::Results::Fulfilled) if expected.expectations_equal_to(actual)
|
7
7
|
rescue Exception => ex
|
8
8
|
return self.extend(Expectations::Results::Fulfilled) if expected == ex.class
|
9
|
-
self.extend(Expectations::Results::
|
9
|
+
self.extend(Expectations::Results::Error)
|
10
10
|
self.exception = ex
|
11
11
|
self.message = "expected: <#{expected.inspect}> got: <#{ex.class.inspect}>" if expected.is_a?(Class) && expected < StandardError
|
12
12
|
return self
|
data/lib/expectations.rb
CHANGED
@@ -17,6 +17,9 @@ require 'benchmark'
|
|
17
17
|
require 'erb'
|
18
18
|
require 'fileutils'
|
19
19
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/object')
|
20
|
+
require File.expand_path(File.dirname(__FILE__) + '/expectations/regexp')
|
21
|
+
require File.expand_path(File.dirname(__FILE__) + '/expectations/range')
|
22
|
+
require File.expand_path(File.dirname(__FILE__) + '/expectations/module')
|
20
23
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/string')
|
21
24
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/mocha')
|
22
25
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/suite')
|
data/rakefile.rb
CHANGED
@@ -41,7 +41,7 @@ specification = Gem::Specification.new do |s|
|
|
41
41
|
expect NoMethodError do
|
42
42
|
Object.invalid_method_call
|
43
43
|
end."
|
44
|
-
s.version = "0.1.
|
44
|
+
s.version = "0.1.1"
|
45
45
|
s.author = 'Jay Fields'
|
46
46
|
s.description = "A lightweight unit testing framework. Tests (expectations) will be written as follows
|
47
47
|
expect 2 do
|
@@ -10,7 +10,7 @@ Expectations do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
expect true do
|
13
|
-
Expectations::Expectation.new(1) { raise }.execute.is_a?(Expectations::Results::
|
13
|
+
Expectations::Expectation.new(1) { raise }.execute.is_a?(Expectations::Results::Error)
|
14
14
|
end
|
15
15
|
|
16
16
|
expect "undefined method `no_method' for Object:Class" do
|
@@ -15,7 +15,7 @@ Expectations do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
expect "E" do
|
18
|
-
Object.new.extend(Expectations::Results::
|
18
|
+
Object.new.extend(Expectations::Results::Error).char
|
19
19
|
end
|
20
20
|
|
21
21
|
expect true do
|
@@ -31,7 +31,7 @@ Expectations do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
expect false do
|
34
|
-
Object.new.extend(Expectations::Results::
|
34
|
+
Object.new.extend(Expectations::Results::Error).fulfilled?
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
data/test/failures.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
|
5
|
+
# State based expectation where a value equals another value # !> `&' interpreted as argument prefix
|
6
|
+
expect 2 do # !> `&' interpreted as argument prefix
|
7
|
+
3
|
8
|
+
end
|
9
|
+
|
10
|
+
# State based expectation where an exception is expected. Simply expect the Class of the intended exception
|
11
|
+
expect ArgumentError do
|
12
|
+
Object.no_method
|
13
|
+
end
|
14
|
+
|
15
|
+
# Behavior based test using a traditional mock
|
16
|
+
expect mock.to_receive(:dial).with("2125551212").times(2) do |phone|
|
17
|
+
phone.dial("2125551212")
|
18
|
+
phone.dial("2125551212") # !> `&' interpreted as argument prefix
|
19
|
+
phone.dial("2125551212")
|
20
|
+
end
|
21
|
+
|
22
|
+
# Behavior based test using a traditional mock
|
23
|
+
expect mock.to_receive(:dial).with("2125551212").times(2) do |phone|
|
24
|
+
phone.dial("2125551212")
|
25
|
+
end
|
26
|
+
|
27
|
+
# Behavior based test on a concrete mock
|
28
|
+
expect Object.to_receive(:deal) do
|
29
|
+
Object.no_deal
|
30
|
+
end
|
31
|
+
|
32
|
+
# Behavior based test on a concrete mock
|
33
|
+
expect Object.to_receive(:deal) do
|
34
|
+
end
|
35
|
+
|
36
|
+
# State based test utilizing a stub
|
37
|
+
expect 2 do
|
38
|
+
stub(:two => 2).twos
|
39
|
+
end
|
40
|
+
|
41
|
+
# State based test utilizing a concrete mock
|
42
|
+
expect 2 do
|
43
|
+
Object.expects(:bar).returns 2
|
44
|
+
Object.barter
|
45
|
+
end
|
46
|
+
|
47
|
+
# Behavior based test utilizing a stub and a concrete mock
|
48
|
+
expect 1 do
|
49
|
+
Object.expects(:give_me_three).with(3).returns 1
|
50
|
+
Object.give_me_three(stub(:three=>3).threes)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
# >> Expectations FE..EFEEE
|
55
|
+
# >> Finished in 0.00240 seconds
|
56
|
+
# >>
|
57
|
+
# >> Failure: 2 failed, 5 errors, 2 fulfilled
|
58
|
+
# >>
|
59
|
+
# >> --Errors--
|
60
|
+
# >> -:11:in `expect'
|
61
|
+
# >> file <->
|
62
|
+
# >> line <11>
|
63
|
+
# >> error <undefined method `no_method' for Object:Class>
|
64
|
+
# >> trace
|
65
|
+
# >> -:12
|
66
|
+
# >> -:3
|
67
|
+
# >> expected: <ArgumentError> got: <NoMethodError>
|
68
|
+
# >>
|
69
|
+
# >> -:28:in `expect'
|
70
|
+
# >> file <->
|
71
|
+
# >> line <28>
|
72
|
+
# >> error <undefined method `no_deal' for Object:Class>
|
73
|
+
# >> trace
|
74
|
+
# >> -:29:in `__instance_exec0'
|
75
|
+
# >> -:3
|
76
|
+
# >>
|
77
|
+
# >> -:37:in `expect'
|
78
|
+
# >> file <->
|
79
|
+
# >> line <37>
|
80
|
+
# >> error <#<Mock:0x66e57c>.twos() - expected calls: 0, actual calls: 1>
|
81
|
+
# >> trace
|
82
|
+
# >> -:38
|
83
|
+
# >> -:3
|
84
|
+
# >>
|
85
|
+
# >> -:42:in `expect'
|
86
|
+
# >> file <->
|
87
|
+
# >> line <42>
|
88
|
+
# >> error <undefined method `barter' for Object:Class>
|
89
|
+
# >> trace
|
90
|
+
# >> -:44
|
91
|
+
# >> -:3
|
92
|
+
# >>
|
93
|
+
# >> -:48:in `expect'
|
94
|
+
# >> file <->
|
95
|
+
# >> line <48>
|
96
|
+
# >> error <#<Mock:0x66caec>.threes() - expected calls: 0, actual calls: 1>
|
97
|
+
# >> trace
|
98
|
+
# >> -:50
|
99
|
+
# >> -:3
|
100
|
+
# >>
|
101
|
+
# >>
|
102
|
+
# >> --Failures--
|
103
|
+
# >> -:6:in `expect'
|
104
|
+
# >> file <->
|
105
|
+
# >> line <6>
|
106
|
+
# >> expected: <2> got: <3>
|
107
|
+
# >>
|
108
|
+
# >> -:33:in `expect'
|
109
|
+
# >> file <->
|
110
|
+
# >> line <33>
|
111
|
+
# >> #<Mock:0x66f120>.deal(any_parameters) - expected calls: 1, actual calls: 0
|
112
|
+
# >>
|
@@ -40,4 +40,34 @@ Expectations do
|
|
40
40
|
Object.give_me_three(stub(:three=>3).three)
|
41
41
|
end
|
42
42
|
|
43
|
+
# State based test matching a Regexp
|
44
|
+
expect /a string/ do
|
45
|
+
"a string"
|
46
|
+
end
|
47
|
+
|
48
|
+
# State based test checking if actual is in the expected Range
|
49
|
+
expect 1..5 do
|
50
|
+
3
|
51
|
+
end
|
52
|
+
|
53
|
+
# State based test to determine if the object is an instance of the module
|
54
|
+
expect Enumerable do
|
55
|
+
[]
|
56
|
+
end
|
57
|
+
|
58
|
+
# State based test to determine if the object is an instance of the class
|
59
|
+
expect String do
|
60
|
+
"a string"
|
61
|
+
end
|
62
|
+
|
63
|
+
# State based test to determine if the modules are the same
|
64
|
+
expect Enumerable do
|
65
|
+
Enumerable
|
66
|
+
end
|
67
|
+
|
68
|
+
# State based test to determine if the classes are the same
|
69
|
+
expect String do
|
70
|
+
String
|
71
|
+
end
|
72
|
+
|
43
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expectations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Fields
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-01-
|
12
|
+
date: 2008-01-15 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,7 +26,10 @@ files:
|
|
26
26
|
- lib/expectations/expectation.rb
|
27
27
|
- lib/expectations/mocha.rb
|
28
28
|
- lib/expectations/mock_recorder.rb
|
29
|
+
- lib/expectations/module.rb
|
29
30
|
- lib/expectations/object.rb
|
31
|
+
- lib/expectations/range.rb
|
32
|
+
- lib/expectations/regexp.rb
|
30
33
|
- lib/expectations/results.rb
|
31
34
|
- lib/expectations/state_based_expectation.rb
|
32
35
|
- lib/expectations/string.rb
|
@@ -40,6 +43,7 @@ files:
|
|
40
43
|
- test/expectations/string_test.rb
|
41
44
|
- test/expectations/suite_results_test.rb
|
42
45
|
- test/expectations/suite_test.rb
|
46
|
+
- test/failures.rb
|
43
47
|
- test/sample_expectations_test.rb
|
44
48
|
- test/silent.rb
|
45
49
|
- test/test_helper.rb
|