expectations 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +17 -0
- data/lib/expectations/behavior_based_expectation.rb +1 -1
- data/lib/expectations/results.rb +2 -2
- data/lib/expectations/suite.rb +19 -16
- data/lib/expectations/suite_runner.rb +1 -3
- data/lib/expectations/xml_string.rb +10 -0
- data/lib/expectations.rb +1 -1
- data/rakefile.rb +1 -2
- data/test/expectations/module_test.rb +11 -0
- data/test/expectations/object_test.rb +12 -0
- data/test/expectations/results_test.rb +34 -2
- data/test/expectations/suite_results_test.rb +1 -1
- data/test/expectations/suite_test.rb +31 -15
- data/test/expectations/xml_string_test.rb +44 -0
- data/test/failures_test.rb +11 -19
- data/test/{sample_expectations_test.rb → successes_test.rb} +17 -0
- metadata +9 -7
- data/lib/expectations/mocha.rb +0 -9
- data/test/all_tests.rb +0 -1
data/README
CHANGED
@@ -114,6 +114,23 @@ expectations can be used for state based and behavior based testing.
|
|
114
114
|
String
|
115
115
|
end
|
116
116
|
|
117
|
+
expect xml("<a><foo>bar</foo></a>") do
|
118
|
+
"<a>\n\t<foo>bar</foo> \n</a>"
|
119
|
+
end
|
120
|
+
|
121
|
+
expect xml(<<-eos) do
|
122
|
+
<one>
|
123
|
+
<two>
|
124
|
+
<three>4</three>
|
125
|
+
<five> 6 </five>
|
126
|
+
</two>
|
127
|
+
</one>
|
128
|
+
eos
|
129
|
+
"<one><two><three>4</three>
|
130
|
+
<five> 6 </five>
|
131
|
+
</two></one>"
|
132
|
+
end
|
133
|
+
|
117
134
|
end
|
118
135
|
|
119
136
|
== Contributors
|
@@ -6,7 +6,7 @@ module Expectations::BehaviorBasedExpectation
|
|
6
6
|
expected.verify
|
7
7
|
self.extend(Expectations::Results::Fulfilled)
|
8
8
|
rescue Mocha::ExpectationError => ex
|
9
|
-
self.extend(Expectations::Results::
|
9
|
+
self.extend(Expectations::Results::BehaviorBasedFailure)
|
10
10
|
self.message = ex.message
|
11
11
|
rescue Exception => ex
|
12
12
|
self.extend(Expectations::Results::Error)
|
data/lib/expectations/results.rb
CHANGED
@@ -8,7 +8,7 @@ module Expectations::Results
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def failure?
|
11
|
-
self.is_a?(Expectations::Results::StateBasedFailure) || self.is_a?(Expectations::Results::
|
11
|
+
self.is_a?(Expectations::Results::StateBasedFailure) || self.is_a?(Expectations::Results::BehaviorBasedFailure)
|
12
12
|
end
|
13
13
|
|
14
14
|
def error?
|
@@ -41,7 +41,7 @@ module Expectations::Results
|
|
41
41
|
end
|
42
42
|
|
43
43
|
module Expectations::Results
|
44
|
-
module
|
44
|
+
module BehaviorBasedFailure
|
45
45
|
attr_accessor :message
|
46
46
|
include Expectations::Results
|
47
47
|
char "F"
|
data/lib/expectations/suite.rb
CHANGED
@@ -4,34 +4,37 @@ class Expectations::Suite
|
|
4
4
|
Expectations::MockRecorder.new(Mocha::Mock.new)
|
5
5
|
end
|
6
6
|
|
7
|
+
def xml(string)
|
8
|
+
Expectations::XmlString.new(string)
|
9
|
+
end
|
10
|
+
|
7
11
|
def execute(out=STDOUT)
|
8
|
-
return true if @do_not_run
|
9
12
|
suite_result = Expectations::SuiteResults.new(out)
|
10
|
-
|
13
|
+
return suite_result if @do_not_run
|
14
|
+
benchmark = Benchmark.measure do
|
15
|
+
expectations_for(ENV["LINE"]).each { |expectation| suite_result << expectation.execute }
|
16
|
+
end
|
11
17
|
suite_result.print_results(benchmark)
|
12
18
|
suite_result.write_junit_xml(ENV["JUnitXmlPath"]) unless ENV["JUnitXmlPath"].nil?
|
13
|
-
|
14
|
-
suite_result.succeeded?
|
19
|
+
suite_result
|
15
20
|
end
|
16
21
|
|
17
|
-
def
|
18
|
-
expectations
|
22
|
+
def expect(expected, &block)
|
23
|
+
expectations << Expectations::Expectation.new(expected, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def do_not_run
|
27
|
+
@do_not_run = true
|
19
28
|
end
|
20
29
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
30
|
+
def expectations_for(line)
|
31
|
+
return expectations if line.nil?
|
32
|
+
[expectations.inject { |result, expectation| expectation.line > line.to_i ? result : expectation }]
|
24
33
|
end
|
25
34
|
|
35
|
+
private
|
26
36
|
def expectations
|
27
37
|
@expectations ||= []
|
28
38
|
end
|
29
39
|
|
30
|
-
def expect(expected, &block)
|
31
|
-
self.expectations << Expectations::Expectation.new(expected, &block)
|
32
|
-
end
|
33
|
-
|
34
|
-
def do_not_run
|
35
|
-
@do_not_run = true
|
36
|
-
end
|
37
40
|
end
|
data/lib/expectations.rb
CHANGED
@@ -16,11 +16,11 @@ require 'benchmark'
|
|
16
16
|
require 'erb'
|
17
17
|
require 'fileutils'
|
18
18
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/object')
|
19
|
+
require File.expand_path(File.dirname(__FILE__) + '/expectations/xml_string')
|
19
20
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/regexp')
|
20
21
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/range')
|
21
22
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/module')
|
22
23
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/string')
|
23
|
-
require File.expand_path(File.dirname(__FILE__) + '/expectations/mocha')
|
24
24
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/suite')
|
25
25
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/suite_runner')
|
26
26
|
require File.expand_path(File.dirname(__FILE__) + '/expectations/suite_results')
|
data/rakefile.rb
CHANGED
@@ -46,7 +46,7 @@ specification = Gem::Specification.new do |s|
|
|
46
46
|
expect NoMethodError do
|
47
47
|
Object.invalid_method_call
|
48
48
|
end."
|
49
|
-
s.version = "0.1.
|
49
|
+
s.version = "0.1.5"
|
50
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
|
@@ -65,7 +65,6 @@ specification = Gem::Specification.new do |s|
|
|
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.test_file = "test/all_tests.rb"
|
69
68
|
end
|
70
69
|
|
71
70
|
Rake::GemPackageTask.new(specification) do |package|
|
@@ -11,7 +11,7 @@ Expectations do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
expect "F" do
|
14
|
-
Object.new.extend(Expectations::Results::
|
14
|
+
Object.new.extend(Expectations::Results::BehaviorBasedFailure).char
|
15
15
|
end
|
16
16
|
|
17
17
|
expect "E" do
|
@@ -27,11 +27,43 @@ Expectations do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
expect false do
|
30
|
-
Object.new.extend(Expectations::Results::
|
30
|
+
Object.new.extend(Expectations::Results::BehaviorBasedFailure).fulfilled?
|
31
31
|
end
|
32
32
|
|
33
33
|
expect false do
|
34
34
|
Object.new.extend(Expectations::Results::Error).fulfilled?
|
35
35
|
end
|
36
36
|
|
37
|
+
expect false do
|
38
|
+
Object.new.extend(Expectations::Results::Fulfilled).error?
|
39
|
+
end
|
40
|
+
|
41
|
+
expect false do
|
42
|
+
Object.new.extend(Expectations::Results::StateBasedFailure).error?
|
43
|
+
end
|
44
|
+
|
45
|
+
expect false do
|
46
|
+
Object.new.extend(Expectations::Results::BehaviorBasedFailure).error?
|
47
|
+
end
|
48
|
+
|
49
|
+
expect true do
|
50
|
+
Object.new.extend(Expectations::Results::Error).error?
|
51
|
+
end
|
52
|
+
|
53
|
+
expect false do
|
54
|
+
Object.new.extend(Expectations::Results::Fulfilled).failure?
|
55
|
+
end
|
56
|
+
|
57
|
+
expect true do
|
58
|
+
Object.new.extend(Expectations::Results::StateBasedFailure).failure?
|
59
|
+
end
|
60
|
+
|
61
|
+
expect true do
|
62
|
+
Object.new.extend(Expectations::Results::BehaviorBasedFailure).failure?
|
63
|
+
end
|
64
|
+
|
65
|
+
expect false do
|
66
|
+
Object.new.extend(Expectations::Results::Error).failure?
|
67
|
+
end
|
68
|
+
|
37
69
|
end
|
@@ -22,7 +22,7 @@ Expectations do
|
|
22
22
|
|
23
23
|
expect false do
|
24
24
|
results = Expectations::SuiteResults.new(Silent)
|
25
|
-
results << Object.new.extend(Expectations::Results::
|
25
|
+
results << Object.new.extend(Expectations::Results::BehaviorBasedFailure)
|
26
26
|
results << Object.new.extend(Expectations::Results::Fulfilled)
|
27
27
|
results.succeeded?
|
28
28
|
end
|
@@ -1,37 +1,53 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../test_helper"
|
2
2
|
|
3
3
|
Expectations do
|
4
|
-
expect 1 do
|
5
|
-
suite = Expectations::Suite.new
|
6
|
-
suite.expect(1) { 1 }
|
7
|
-
suite.expectations.size
|
8
|
-
end
|
9
4
|
|
10
5
|
expect true do
|
11
6
|
suite = Expectations::Suite.new
|
12
|
-
suite.execute(Silent)
|
7
|
+
suite.execute(Silent).succeeded?
|
13
8
|
end
|
14
9
|
|
15
10
|
expect true do
|
16
11
|
suite = Expectations::Suite.new
|
17
12
|
suite.expect(1) { 2 }
|
18
13
|
suite.do_not_run
|
19
|
-
suite.execute(Silent)
|
14
|
+
suite.execute(Silent).succeeded?
|
20
15
|
end
|
21
16
|
|
22
17
|
expect false do
|
23
18
|
suite = Expectations::Suite.new
|
24
19
|
suite.expect(1) { 2 }
|
25
|
-
suite.execute(Silent)
|
20
|
+
suite.execute(Silent).succeeded?
|
26
21
|
end
|
27
22
|
|
28
|
-
expect
|
23
|
+
expect Expectations::MockRecorder do
|
24
|
+
Expectations::Suite.new.mock
|
25
|
+
end
|
26
|
+
|
27
|
+
expect Mocha::Mock do
|
28
|
+
Expectations::Suite.new.mock.target
|
29
|
+
end
|
30
|
+
|
31
|
+
expect 3 do
|
29
32
|
suite = Expectations::Suite.new
|
30
|
-
|
31
|
-
suite.
|
32
|
-
|
33
|
-
|
34
|
-
result
|
33
|
+
suite.expect(1) { 2 }
|
34
|
+
suite.expect(1) { 2 }
|
35
|
+
suite.expect(1) { 2 }
|
36
|
+
suite.expectations_for(nil).size
|
35
37
|
end
|
36
|
-
|
38
|
+
|
39
|
+
expect 1 do
|
40
|
+
suite = Expectations::Suite.new
|
41
|
+
suite.expect(1) { 2 }
|
42
|
+
suite.expect(1) { 2 }
|
43
|
+
suite.expectations_for(__LINE__ - 1).size
|
44
|
+
end
|
45
|
+
|
46
|
+
expect :expected do
|
47
|
+
suite = Expectations::Suite.new
|
48
|
+
suite.expect(1) { 2 }
|
49
|
+
suite.expect(:expected) { 2 }
|
50
|
+
suite.expectations_for(__LINE__ - 1).first.expected
|
51
|
+
end
|
52
|
+
|
37
53
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect true do
|
5
|
+
Expectations::XmlString.new("<foo>bar</foo>").expectations_equal_to "<foo>bar</foo>"
|
6
|
+
end
|
7
|
+
|
8
|
+
expect true do
|
9
|
+
Expectations::XmlString.new("<foo>bar</foo>").expectations_equal_to " <foo>bar</foo> "
|
10
|
+
end
|
11
|
+
|
12
|
+
expect true do
|
13
|
+
Expectations::XmlString.new(" <foo>bar</foo> ").expectations_equal_to "<foo>bar</foo>"
|
14
|
+
end
|
15
|
+
|
16
|
+
expect true do
|
17
|
+
Expectations::XmlString.new("<foo>bar</foo>").expectations_equal_to "<foo>bar</foo>\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
expect true do
|
21
|
+
Expectations::XmlString.new("\n<foo>bar</foo>").expectations_equal_to "<foo>bar</foo>"
|
22
|
+
end
|
23
|
+
|
24
|
+
expect true do
|
25
|
+
Expectations::XmlString.new("\t<foo>bar</foo>").expectations_equal_to "<foo>bar</foo>"
|
26
|
+
end
|
27
|
+
|
28
|
+
expect true do
|
29
|
+
Expectations::XmlString.new("<foo>bar</foo>").expectations_equal_to "<foo>bar</foo>\t"
|
30
|
+
end
|
31
|
+
|
32
|
+
expect true do
|
33
|
+
Expectations::XmlString.new("<a>\n<foo>bar</foo>").expectations_equal_to "<a><foo>bar</foo>"
|
34
|
+
end
|
35
|
+
|
36
|
+
expect true do
|
37
|
+
Expectations::XmlString.new("<a>\n<foo>\t \n bar</foo>").expectations_equal_to "<a><foo>\t \n bar</foo>"
|
38
|
+
end
|
39
|
+
|
40
|
+
expect true do
|
41
|
+
Expectations::XmlString.new("<a>\n<foo>\t \n bar</foo>\n \t </a>").expectations_equal_to "<a><foo>\t \n bar</foo></a>"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/test/failures_test.rb
CHANGED
@@ -4,47 +4,41 @@ Expectations do
|
|
4
4
|
expect Expectations::Results::StateBasedFailure do
|
5
5
|
suite = Expectations::Suite.new
|
6
6
|
suite.expect(2) { 3 }
|
7
|
-
suite.execute(Silent)
|
8
|
-
suite.expectations.first
|
7
|
+
suite.execute(Silent).expectations.first
|
9
8
|
end
|
10
9
|
|
11
10
|
expect Expectations::Results::Error do
|
12
11
|
suite = Expectations::Suite.new
|
13
12
|
suite.expect(ArgumentError) { Object.no_method }
|
14
|
-
suite.execute(Silent)
|
15
|
-
suite.expectations.first
|
13
|
+
suite.execute(Silent).expectations.first
|
16
14
|
end
|
17
15
|
|
18
|
-
expect Expectations::Results::
|
16
|
+
expect Expectations::Results::BehaviorBasedFailure do
|
19
17
|
suite = Expectations::Suite.new
|
20
18
|
suite.expect(mock.to_receive(:dial).with("2125551212").times(2)) do |phone|
|
21
19
|
phone.dial("2125551212")
|
22
20
|
phone.dial("2125551212")
|
23
21
|
phone.dial("2125551212")
|
24
22
|
end
|
25
|
-
suite.execute(Silent)
|
26
|
-
suite.expectations.first
|
23
|
+
suite.execute(Silent).expectations.first
|
27
24
|
end
|
28
25
|
|
29
|
-
expect Expectations::Results::
|
26
|
+
expect Expectations::Results::BehaviorBasedFailure do
|
30
27
|
suite = Expectations::Suite.new
|
31
28
|
suite.expect(mock.to_receive(:dial).with("2125551212").times(2)) { |phone| phone.dial("2125551212") }
|
32
|
-
suite.execute(Silent)
|
33
|
-
suite.expectations.first
|
29
|
+
suite.execute(Silent).expectations.first
|
34
30
|
end
|
35
31
|
|
36
|
-
expect Expectations::Results::
|
32
|
+
expect Expectations::Results::BehaviorBasedFailure do
|
37
33
|
suite = Expectations::Suite.new
|
38
34
|
suite.expect(Object.to_receive(:deal)) { }
|
39
|
-
suite.execute(Silent)
|
40
|
-
suite.expectations.first
|
35
|
+
suite.execute(Silent).expectations.first
|
41
36
|
end
|
42
37
|
|
43
38
|
expect Expectations::Results::Error do
|
44
39
|
suite = Expectations::Suite.new
|
45
40
|
suite.expect(2) { stub(:two => 2).twos }
|
46
|
-
suite.execute(Silent)
|
47
|
-
suite.expectations.first
|
41
|
+
suite.execute(Silent).expectations.first
|
48
42
|
end
|
49
43
|
|
50
44
|
expect Expectations::Results::Error do
|
@@ -53,8 +47,7 @@ Expectations do
|
|
53
47
|
Object.expects(:bar).returns 2
|
54
48
|
Object.barter
|
55
49
|
end
|
56
|
-
suite.execute(Silent)
|
57
|
-
suite.expectations.first
|
50
|
+
suite.execute(Silent).expectations.first
|
58
51
|
end
|
59
52
|
|
60
53
|
expect Expectations::Results::Error do
|
@@ -63,8 +56,7 @@ Expectations do
|
|
63
56
|
Object.expects(:give_me_three).with(3).returns 1
|
64
57
|
Object.give_me_three(stub(:three=>3).threes)
|
65
58
|
end
|
66
|
-
suite.execute(Silent)
|
67
|
-
suite.expectations.first
|
59
|
+
suite.execute(Silent).expectations.first
|
68
60
|
end
|
69
61
|
|
70
62
|
end
|
@@ -70,4 +70,21 @@ Expectations do
|
|
70
70
|
String
|
71
71
|
end
|
72
72
|
|
73
|
+
expect xml("<a><foo>bar</foo></a>") do
|
74
|
+
"<a>\n\t<foo>bar</foo> \n</a>"
|
75
|
+
end
|
76
|
+
|
77
|
+
expect xml(<<-eos) do
|
78
|
+
<one>
|
79
|
+
<two>
|
80
|
+
<three>4</three>
|
81
|
+
<five> 6 </five>
|
82
|
+
</two>
|
83
|
+
</one>
|
84
|
+
eos
|
85
|
+
"<one><two><three>4</three>
|
86
|
+
<five> 6 </five>
|
87
|
+
</two></one>"
|
88
|
+
end
|
89
|
+
|
73
90
|
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.5
|
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-23 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -24,7 +24,6 @@ extra_rdoc_files:
|
|
24
24
|
files:
|
25
25
|
- lib/expectations/behavior_based_expectation.rb
|
26
26
|
- lib/expectations/expectation.rb
|
27
|
-
- lib/expectations/mocha.rb
|
28
27
|
- lib/expectations/mock_recorder.rb
|
29
28
|
- lib/expectations/module.rb
|
30
29
|
- lib/expectations/object.rb
|
@@ -36,10 +35,12 @@ files:
|
|
36
35
|
- lib/expectations/suite.rb
|
37
36
|
- lib/expectations/suite_results.rb
|
38
37
|
- lib/expectations/suite_runner.rb
|
38
|
+
- lib/expectations/xml_string.rb
|
39
39
|
- lib/expectations.rb
|
40
|
-
- test/all_tests.rb
|
41
40
|
- test/expectations/expectation_test.rb
|
42
41
|
- test/expectations/expectations_test.rb
|
42
|
+
- test/expectations/module_test.rb
|
43
|
+
- test/expectations/object_test.rb
|
43
44
|
- test/expectations/range_test.rb
|
44
45
|
- test/expectations/regexp_test.rb
|
45
46
|
- test/expectations/results_test.rb
|
@@ -47,9 +48,10 @@ files:
|
|
47
48
|
- test/expectations/suite_results_test.rb
|
48
49
|
- test/expectations/suite_runner_test.rb
|
49
50
|
- test/expectations/suite_test.rb
|
51
|
+
- test/expectations/xml_string_test.rb
|
50
52
|
- test/failures_test.rb
|
51
|
-
- test/sample_expectations_test.rb
|
52
53
|
- test/silent.rb
|
54
|
+
- test/successes_test.rb
|
53
55
|
- test/test_helper.rb
|
54
56
|
- rakefile.rb
|
55
57
|
- README
|
@@ -83,5 +85,5 @@ rubygems_version: 1.0.1
|
|
83
85
|
signing_key:
|
84
86
|
specification_version: 2
|
85
87
|
summary: 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.
|
86
|
-
test_files:
|
87
|
-
|
88
|
+
test_files: []
|
89
|
+
|
data/lib/expectations/mocha.rb
DELETED
data/test/all_tests.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Dir['**/*_test.rb'].each { |test_case| require test_case }
|