expectations 0.1.8 → 0.2.0
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.rb +4 -0
- data/lib/expectations/expectation.rb +2 -0
- data/lib/expectations/negative_state_based_recorder.rb +12 -0
- data/lib/expectations/object.rb +8 -0
- data/lib/expectations/positive_state_based_recorder.rb +7 -0
- data/lib/expectations/recorded_state_based_expectation.rb +21 -0
- data/lib/expectations/state_based_recorder.rb +33 -0
- data/rakefile.rb +9 -8
- data/test/expectations/results_test.rb +24 -24
- data/test/expectations/suite_results_test.rb +3 -9
- metadata +16 -4
data/lib/expectations.rb
CHANGED
|
@@ -18,6 +18,10 @@ require 'fileutils'
|
|
|
18
18
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/object')
|
|
19
19
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/delegate_expectation')
|
|
20
20
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/delegate_recorder')
|
|
21
|
+
require File.expand_path(File.dirname(__FILE__) + '/expectations/recorded_state_based_expectation')
|
|
22
|
+
require File.expand_path(File.dirname(__FILE__) + '/expectations/state_based_recorder')
|
|
23
|
+
require File.expand_path(File.dirname(__FILE__) + '/expectations/positive_state_based_recorder')
|
|
24
|
+
require File.expand_path(File.dirname(__FILE__) + '/expectations/negative_state_based_recorder')
|
|
21
25
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/xml_string')
|
|
22
26
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/regexp')
|
|
23
27
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/range')
|
|
@@ -7,6 +7,8 @@ class Expectations::Expectation
|
|
|
7
7
|
self.file, self.line = eval "[__FILE__, __LINE__]", block.binding
|
|
8
8
|
case
|
|
9
9
|
when expected.is_a?(Expectations::DelegateRecorder) then extend(Expectations::DelegateExpectation)
|
|
10
|
+
when expected.is_a?(Expectations::PositiveStateBasedRecorder) then extend(Expectations::RecordedStateBasedExpectation)
|
|
11
|
+
when expected.is_a?(Expectations::NegativeStateBasedRecorder) then extend(Expectations::RecordedStateBasedExpectation)
|
|
10
12
|
when expected.is_a?(Expectations::MockRecorder) then extend(Expectations::BehaviorBasedExpectation)
|
|
11
13
|
else extend(Expectations::StateBasedExpectation)
|
|
12
14
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class Expectations::NegativeStateBasedRecorder < Expectations::StateBasedRecorder
|
|
2
|
+
|
|
3
|
+
def to
|
|
4
|
+
@message_parts << "to"
|
|
5
|
+
self
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def verify
|
|
9
|
+
not method_stack.inject(subject) { |result, element| result.send element.first, *element.last }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
data/lib/expectations/object.rb
CHANGED
|
@@ -7,6 +7,14 @@ class Object
|
|
|
7
7
|
Expectations::DelegateRecorder.new(self, method)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def to
|
|
11
|
+
Expectations::PositiveStateBasedRecorder.new(self)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def not
|
|
15
|
+
Expectations::NegativeStateBasedRecorder.new(self)
|
|
16
|
+
end
|
|
17
|
+
|
|
10
18
|
def expectations_equal_to(other)
|
|
11
19
|
self == other
|
|
12
20
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Expectations::RecordedStateBasedExpectation
|
|
2
|
+
def execute
|
|
3
|
+
begin
|
|
4
|
+
mocha_setup
|
|
5
|
+
instance_exec expected.subject, &block
|
|
6
|
+
if expected.verify
|
|
7
|
+
self.extend(Expectations::Results::Fulfilled)
|
|
8
|
+
else
|
|
9
|
+
self.extend(Expectations::Results::StateBasedFailure)
|
|
10
|
+
self.message = "expected #{expected.subject} to #{expected.message}"
|
|
11
|
+
end
|
|
12
|
+
rescue Exception => ex
|
|
13
|
+
self.extend(Expectations::Results::Error)
|
|
14
|
+
self.exception = ex
|
|
15
|
+
ensure
|
|
16
|
+
mocha_teardown
|
|
17
|
+
end
|
|
18
|
+
self
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class Expectations::StateBasedRecorder
|
|
2
|
+
attr_reader :subject
|
|
3
|
+
def initialize(subject)
|
|
4
|
+
@subject = subject
|
|
5
|
+
@message_parts = []
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def have
|
|
9
|
+
@message_parts << "have"
|
|
10
|
+
self
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def be
|
|
14
|
+
@message_parts << "be"
|
|
15
|
+
self
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def message
|
|
19
|
+
@message_parts.join(" ")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def method_stack
|
|
23
|
+
@method_stack ||= []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def method_missing(sym, *args)
|
|
27
|
+
@message_parts << "#{sym}"
|
|
28
|
+
args.each { |arg| @message_parts << arg.inspect }
|
|
29
|
+
method_stack << [sym, args]
|
|
30
|
+
self
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
data/rakefile.rb
CHANGED
|
@@ -37,22 +37,22 @@ end
|
|
|
37
37
|
Gem::manage_gems
|
|
38
38
|
|
|
39
39
|
specification = Gem::Specification.new do |s|
|
|
40
|
-
|
|
40
|
+
s.name = "expectations"
|
|
41
41
|
s.summary = "A lightweight unit testing framework. Tests (expectations) will be written as follows
|
|
42
42
|
expect 2 do
|
|
43
43
|
1 + 1
|
|
44
44
|
end
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
expect NoMethodError do
|
|
47
47
|
Object.invalid_method_call
|
|
48
48
|
end."
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
s.version = "0.2.0"
|
|
50
|
+
s.author = 'Jay Fields'
|
|
51
51
|
s.description = "A lightweight unit testing framework. Tests (expectations) will be written as follows
|
|
52
52
|
expect 2 do
|
|
53
53
|
1 + 1
|
|
54
54
|
end
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
expect NoMethodError do
|
|
57
57
|
Object.invalid_method_call
|
|
58
58
|
end."
|
|
@@ -62,12 +62,13 @@ specification = Gem::Specification.new do |s|
|
|
|
62
62
|
s.has_rdoc = true
|
|
63
63
|
s.extra_rdoc_files = ['README']
|
|
64
64
|
s.rdoc_options << '--title' << 'expectations' << '--main' << 'README' << '--line-numbers'
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
s.email = 'ruby@jayfields.com'
|
|
67
67
|
s.files = FileList['{lib,test}/**/*.rb', '[A-Z]*$', 'rakefile.rb'].to_a
|
|
68
|
+
s.add_dependency('mocha', '>= 0.5.5')
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
Rake::GemPackageTask.new(specification) do |package|
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
package.need_zip = false
|
|
73
|
+
package.need_tar = false
|
|
73
74
|
end
|
|
@@ -18,52 +18,52 @@ Expectations do
|
|
|
18
18
|
Object.new.extend(Expectations::Results::Error).char
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
expect
|
|
22
|
-
|
|
21
|
+
expect Object.new.to.be.fulfilled? do |instance|
|
|
22
|
+
instance.extend(Expectations::Results::Fulfilled)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
expect
|
|
26
|
-
|
|
25
|
+
expect Object.new.not.to.be.fulfilled? do |instance|
|
|
26
|
+
instance.extend(Expectations::Results::StateBasedFailure)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
expect
|
|
30
|
-
|
|
29
|
+
expect Object.new.not.to.be.fulfilled? do |instance|
|
|
30
|
+
instance.extend(Expectations::Results::BehaviorBasedFailure)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
expect
|
|
34
|
-
|
|
33
|
+
expect Object.new.not.to.be.fulfilled? do |instance|
|
|
34
|
+
instance.extend(Expectations::Results::Error)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
expect
|
|
38
|
-
|
|
37
|
+
expect Object.new.not.to.be.error? do |instance|
|
|
38
|
+
instance.extend(Expectations::Results::Fulfilled)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
expect
|
|
42
|
-
|
|
41
|
+
expect Object.new.not.to.be.error? do |instance|
|
|
42
|
+
instance.extend(Expectations::Results::StateBasedFailure)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
expect
|
|
46
|
-
|
|
45
|
+
expect Object.new.not.to.be.error? do |instance|
|
|
46
|
+
instance.extend(Expectations::Results::BehaviorBasedFailure)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
expect
|
|
50
|
-
|
|
49
|
+
expect Object.new.to.be.error? do |instance|
|
|
50
|
+
instance.extend(Expectations::Results::Error)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
expect
|
|
54
|
-
|
|
53
|
+
expect Object.new.not.to.be.failure? do |instance|
|
|
54
|
+
instance.extend(Expectations::Results::Fulfilled)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
expect
|
|
58
|
-
|
|
57
|
+
expect Object.new.to.be.failure? do |instance|
|
|
58
|
+
instance.extend(Expectations::Results::StateBasedFailure)
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
expect
|
|
62
|
-
|
|
61
|
+
expect Object.new.to.be.failure? do |instance|
|
|
62
|
+
instance.extend(Expectations::Results::BehaviorBasedFailure)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
expect
|
|
66
|
-
|
|
65
|
+
expect Object.new.not.to.be.failure? do |instance|
|
|
66
|
+
instance.extend(Expectations::Results::Error)
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
end
|
|
@@ -13,25 +13,19 @@ Expectations do
|
|
|
13
13
|
results.errors.size
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
expect
|
|
17
|
-
results = Expectations::SuiteResults.new(Silent)
|
|
16
|
+
expect Expectations::SuiteResults.new(Silent).not.to.have.succeeded? do |results|
|
|
18
17
|
results << Object.new.extend(Expectations::Results::StateBasedFailure)
|
|
19
18
|
results << Object.new.extend(Expectations::Results::Fulfilled)
|
|
20
|
-
results.succeeded?
|
|
21
19
|
end
|
|
22
20
|
|
|
23
|
-
expect
|
|
24
|
-
results = Expectations::SuiteResults.new(Silent)
|
|
21
|
+
expect Expectations::SuiteResults.new(Silent).not.to.have.succeeded? do |results|
|
|
25
22
|
results << Object.new.extend(Expectations::Results::BehaviorBasedFailure)
|
|
26
23
|
results << Object.new.extend(Expectations::Results::Fulfilled)
|
|
27
|
-
results.succeeded?
|
|
28
24
|
end
|
|
29
25
|
|
|
30
|
-
expect
|
|
31
|
-
results = Expectations::SuiteResults.new(Silent)
|
|
26
|
+
expect Expectations::SuiteResults.new(Silent).to.have.succeeded? do |results|
|
|
32
27
|
results << Object.new.extend(Expectations::Results::Fulfilled)
|
|
33
28
|
results << Object.new.extend(Expectations::Results::Fulfilled)
|
|
34
|
-
results.succeeded?
|
|
35
29
|
end
|
|
36
30
|
|
|
37
31
|
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.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jay Fields
|
|
@@ -9,10 +9,18 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-02
|
|
12
|
+
date: 2008-03-02 00:00:00 -08:00
|
|
13
13
|
default_executable:
|
|
14
|
-
dependencies:
|
|
15
|
-
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: mocha
|
|
17
|
+
version_requirement:
|
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 0.5.5
|
|
23
|
+
version:
|
|
16
24
|
description: A lightweight unit testing framework. Tests (expectations) will be written as follows expect 2 do 1 + 1 end expect NoMethodError do Object.invalid_method_call end.
|
|
17
25
|
email: ruby@jayfields.com
|
|
18
26
|
executables: []
|
|
@@ -28,11 +36,15 @@ files:
|
|
|
28
36
|
- lib/expectations/expectation.rb
|
|
29
37
|
- lib/expectations/mock_recorder.rb
|
|
30
38
|
- lib/expectations/module.rb
|
|
39
|
+
- lib/expectations/negative_state_based_recorder.rb
|
|
31
40
|
- lib/expectations/object.rb
|
|
41
|
+
- lib/expectations/positive_state_based_recorder.rb
|
|
32
42
|
- lib/expectations/range.rb
|
|
43
|
+
- lib/expectations/recorded_state_based_expectation.rb
|
|
33
44
|
- lib/expectations/regexp.rb
|
|
34
45
|
- lib/expectations/results.rb
|
|
35
46
|
- lib/expectations/state_based_expectation.rb
|
|
47
|
+
- lib/expectations/state_based_recorder.rb
|
|
36
48
|
- lib/expectations/string.rb
|
|
37
49
|
- lib/expectations/suite.rb
|
|
38
50
|
- lib/expectations/suite_results.rb
|