expectations 0.1.3 → 0.1.4
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 -6
- data/lib/expectations/range.rb +1 -1
- data/lib/expectations/regexp.rb +1 -1
- data/lib/expectations/suite.rb +11 -11
- data/lib/expectations/suite_results.rb +7 -4
- data/lib/expectations/suite_runner.rb +9 -7
- data/rakefile.rb +8 -3
- data/test/expectations/expectations_test.rb +13 -0
- data/test/expectations/range_test.rb +11 -0
- data/test/expectations/regexp_test.rb +11 -0
- data/test/expectations/suite_results_test.rb +12 -8
- data/test/expectations/suite_runner_test.rb +13 -0
- data/test/expectations/suite_test.rb +16 -0
- data/test/failures_test.rb +70 -0
- metadata +7 -3
- data/test/failures.rb +0 -53
data/lib/expectations.rb
CHANGED
@@ -2,12 +2,10 @@ module Expectations
|
|
2
2
|
end
|
3
3
|
|
4
4
|
def Expectations(&block)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
raise
|
10
|
-
end
|
5
|
+
Expectations::SuiteRunner.suite_eval &block
|
6
|
+
rescue
|
7
|
+
Expectations::SuiteRunner.do_not_run
|
8
|
+
raise
|
11
9
|
end
|
12
10
|
|
13
11
|
require 'rubygems'
|
data/lib/expectations/range.rb
CHANGED
data/lib/expectations/regexp.rb
CHANGED
data/lib/expectations/suite.rb
CHANGED
@@ -1,29 +1,25 @@
|
|
1
1
|
class Expectations::Suite
|
2
|
-
|
2
|
+
|
3
3
|
def mock
|
4
4
|
Expectations::MockRecorder.new(Mocha::Mock.new)
|
5
5
|
end
|
6
6
|
|
7
7
|
def execute(out=STDOUT)
|
8
|
+
return true if @do_not_run
|
8
9
|
suite_result = Expectations::SuiteResults.new(out)
|
9
|
-
benchmark = Benchmark.measure
|
10
|
-
ENV["LINE"].nil? ? run_all(suite_result) : run_one(suite_result)
|
11
|
-
end
|
10
|
+
benchmark = Benchmark.measure { ENV["LINE"].nil? ? run_all(suite_result) : run_one(suite_result) }
|
12
11
|
suite_result.print_results(benchmark)
|
13
12
|
suite_result.write_junit_xml(ENV["JUnitXmlPath"]) unless ENV["JUnitXmlPath"].nil?
|
14
|
-
suite_result
|
13
|
+
yield suite_result if block_given?
|
14
|
+
suite_result.succeeded?
|
15
15
|
end
|
16
16
|
|
17
17
|
def run_all(suite_result)
|
18
|
-
expectations.each
|
19
|
-
suite_result << expectation.execute
|
20
|
-
end
|
18
|
+
expectations.each { |expectation| suite_result << expectation.execute }
|
21
19
|
end
|
22
20
|
|
23
21
|
def run_one(suite_result)
|
24
|
-
one = expectations.inject
|
25
|
-
expectation.line > ENV["LINE"].to_i ? result : expectation
|
26
|
-
end
|
22
|
+
one = expectations.inject { |result, expectation| expectation.line > ENV["LINE"].to_i ? result : expectation }
|
27
23
|
suite_result << one.execute
|
28
24
|
end
|
29
25
|
|
@@ -34,4 +30,8 @@ class Expectations::Suite
|
|
34
30
|
def expect(expected, &block)
|
35
31
|
self.expectations << Expectations::Expectation.new(expected, &block)
|
36
32
|
end
|
33
|
+
|
34
|
+
def do_not_run
|
35
|
+
@do_not_run = true
|
36
|
+
end
|
37
37
|
end
|
@@ -1,18 +1,21 @@
|
|
1
1
|
class Expectations::SuiteResults
|
2
|
-
attr_accessor :
|
2
|
+
attr_accessor :out, :expectations
|
3
3
|
|
4
4
|
def initialize(out)
|
5
|
-
self.out, self.
|
5
|
+
self.out, self.expectations = out, []
|
6
6
|
out.print "Expectations "
|
7
7
|
end
|
8
8
|
|
9
9
|
def <<(expectation_result)
|
10
10
|
out.print expectation_result.char
|
11
11
|
self.expectations << expectation_result
|
12
|
-
self.result &&= expectation_result.fulfilled?
|
13
12
|
self
|
14
13
|
end
|
15
14
|
|
15
|
+
def succeeded?
|
16
|
+
expectations.all? { |expectation| expectation.fulfilled? }
|
17
|
+
end
|
18
|
+
|
16
19
|
def fulfilled
|
17
20
|
expectations.select { |expectation| expectation.fulfilled? }
|
18
21
|
end
|
@@ -29,7 +32,7 @@ class Expectations::SuiteResults
|
|
29
32
|
run_time = benchmark.real
|
30
33
|
run_time = 0.001 if run_time < 0.001
|
31
34
|
out.puts "\nFinished in #{run_time.to_s.gsub(/(\d*)\.(\d{0,5}).*/,'\1.\2')} seconds"
|
32
|
-
if
|
35
|
+
if succeeded?
|
33
36
|
out.puts "\nSuccess: #{fulfilled.size} fulfilled"
|
34
37
|
else
|
35
38
|
out.puts "\nFailure: #{failures.size} failed, #{errors.size} errors, #{fulfilled.size} fulfilled"
|
@@ -1,20 +1,22 @@
|
|
1
1
|
class Expectations::SuiteRunner
|
2
2
|
include Singleton
|
3
|
-
attr_accessor :suite
|
3
|
+
attr_accessor :suite
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
self.suite = Expectations::Suite.new
|
7
|
-
self.runnable = true
|
8
7
|
at_exit do
|
9
|
-
|
8
|
+
suite.execute do |result|
|
9
|
+
exit 1 unless result.succeeded?
|
10
|
+
end
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
def do_not_run
|
14
|
-
self.
|
14
|
+
def self.do_not_run
|
15
|
+
self.instance.suite.do_not_run
|
15
16
|
end
|
16
17
|
|
17
|
-
def suite_eval(&block)
|
18
|
-
self.suite.instance_eval &block
|
18
|
+
def self.suite_eval(&block)
|
19
|
+
self.instance.suite.instance_eval &block
|
19
20
|
end
|
21
|
+
|
20
22
|
end
|
data/rakefile.rb
CHANGED
@@ -2,9 +2,14 @@ require 'rubygems'
|
|
2
2
|
require 'rake/gempackagetask'
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
require 'rake/contrib/sshpublisher'
|
5
|
+
require 'rake/testtask'
|
5
6
|
|
6
|
-
task :default
|
7
|
-
|
7
|
+
task :default => [:test]
|
8
|
+
|
9
|
+
Rake::TestTask.new do |t|
|
10
|
+
t.libs << "test"
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
8
13
|
end
|
9
14
|
|
10
15
|
desc 'Generate RDoc'
|
@@ -41,7 +46,7 @@ specification = Gem::Specification.new do |s|
|
|
41
46
|
expect NoMethodError do
|
42
47
|
Object.invalid_method_call
|
43
48
|
end."
|
44
|
-
s.version = "0.1.
|
49
|
+
s.version = "0.1.4"
|
45
50
|
s.author = 'Jay Fields'
|
46
51
|
s.description = "A lightweight unit testing framework. Tests (expectations) will be written as follows
|
47
52
|
expect 2 do
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
|
5
|
+
expect Expectations::SuiteRunner.to_receive(:suite_eval) do |suite|
|
6
|
+
Expectations { }
|
7
|
+
end
|
8
|
+
|
9
|
+
expect Expectations::SuiteRunner.to_receive(:do_not_run) do |suite|
|
10
|
+
Expectations { Object.no_method_error_should_raise } rescue nil
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -13,21 +13,25 @@ Expectations do
|
|
13
13
|
results.errors.size
|
14
14
|
end
|
15
15
|
|
16
|
-
expect true do
|
17
|
-
results = Expectations::SuiteResults.new(Silent)
|
18
|
-
results << Object.new.extend(Expectations::Results::Fulfilled)
|
19
|
-
results.result
|
20
|
-
end
|
21
|
-
|
22
16
|
expect false do
|
23
17
|
results = Expectations::SuiteResults.new(Silent)
|
24
18
|
results << Object.new.extend(Expectations::Results::StateBasedFailure)
|
25
|
-
results.
|
19
|
+
results << Object.new.extend(Expectations::Results::Fulfilled)
|
20
|
+
results.succeeded?
|
26
21
|
end
|
27
22
|
|
28
23
|
expect false do
|
29
24
|
results = Expectations::SuiteResults.new(Silent)
|
30
25
|
results << Object.new.extend(Expectations::Results::BehaviorFailure)
|
31
|
-
results.
|
26
|
+
results << Object.new.extend(Expectations::Results::Fulfilled)
|
27
|
+
results.succeeded?
|
32
28
|
end
|
29
|
+
|
30
|
+
expect true do
|
31
|
+
results = Expectations::SuiteResults.new(Silent)
|
32
|
+
results << Object.new.extend(Expectations::Results::Fulfilled)
|
33
|
+
results << Object.new.extend(Expectations::Results::Fulfilled)
|
34
|
+
results.succeeded?
|
35
|
+
end
|
36
|
+
|
33
37
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect mock.to_receive(:instance_eval) do |suite|
|
5
|
+
Expectations::SuiteRunner.stubs(:instance).returns stub(:suite => suite)
|
6
|
+
Expectations::SuiteRunner.suite_eval {}
|
7
|
+
end
|
8
|
+
|
9
|
+
expect mock.to_receive(:do_not_run) do |suite|
|
10
|
+
Expectations::SuiteRunner.stubs(:instance).returns stub(:suite => suite)
|
11
|
+
Expectations::SuiteRunner.do_not_run
|
12
|
+
end
|
13
|
+
end
|
@@ -12,10 +12,26 @@ Expectations do
|
|
12
12
|
suite.execute(Silent)
|
13
13
|
end
|
14
14
|
|
15
|
+
expect true do
|
16
|
+
suite = Expectations::Suite.new
|
17
|
+
suite.expect(1) { 2 }
|
18
|
+
suite.do_not_run
|
19
|
+
suite.execute(Silent)
|
20
|
+
end
|
21
|
+
|
15
22
|
expect false do
|
16
23
|
suite = Expectations::Suite.new
|
17
24
|
suite.expect(1) { 2 }
|
18
25
|
suite.execute(Silent)
|
19
26
|
end
|
27
|
+
|
28
|
+
expect true do
|
29
|
+
suite = Expectations::Suite.new
|
30
|
+
result=nil
|
31
|
+
suite.execute(Silent) do |yielded_value|
|
32
|
+
result = yielded_value.succeeded?
|
33
|
+
end
|
34
|
+
result
|
35
|
+
end
|
20
36
|
|
21
37
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect Expectations::Results::StateBasedFailure do
|
5
|
+
suite = Expectations::Suite.new
|
6
|
+
suite.expect(2) { 3 }
|
7
|
+
suite.execute(Silent)
|
8
|
+
suite.expectations.first
|
9
|
+
end
|
10
|
+
|
11
|
+
expect Expectations::Results::Error do
|
12
|
+
suite = Expectations::Suite.new
|
13
|
+
suite.expect(ArgumentError) { Object.no_method }
|
14
|
+
suite.execute(Silent)
|
15
|
+
suite.expectations.first
|
16
|
+
end
|
17
|
+
|
18
|
+
expect Expectations::Results::BehaviorFailure do
|
19
|
+
suite = Expectations::Suite.new
|
20
|
+
suite.expect(mock.to_receive(:dial).with("2125551212").times(2)) do |phone|
|
21
|
+
phone.dial("2125551212")
|
22
|
+
phone.dial("2125551212")
|
23
|
+
phone.dial("2125551212")
|
24
|
+
end
|
25
|
+
suite.execute(Silent)
|
26
|
+
suite.expectations.first
|
27
|
+
end
|
28
|
+
|
29
|
+
expect Expectations::Results::BehaviorFailure do
|
30
|
+
suite = Expectations::Suite.new
|
31
|
+
suite.expect(mock.to_receive(:dial).with("2125551212").times(2)) { |phone| phone.dial("2125551212") }
|
32
|
+
suite.execute(Silent)
|
33
|
+
suite.expectations.first
|
34
|
+
end
|
35
|
+
|
36
|
+
expect Expectations::Results::BehaviorFailure do
|
37
|
+
suite = Expectations::Suite.new
|
38
|
+
suite.expect(Object.to_receive(:deal)) { }
|
39
|
+
suite.execute(Silent)
|
40
|
+
suite.expectations.first
|
41
|
+
end
|
42
|
+
|
43
|
+
expect Expectations::Results::Error do
|
44
|
+
suite = Expectations::Suite.new
|
45
|
+
suite.expect(2) { stub(:two => 2).twos }
|
46
|
+
suite.execute(Silent)
|
47
|
+
suite.expectations.first
|
48
|
+
end
|
49
|
+
|
50
|
+
expect Expectations::Results::Error do
|
51
|
+
suite = Expectations::Suite.new
|
52
|
+
suite.expect(2) do
|
53
|
+
Object.expects(:bar).returns 2
|
54
|
+
Object.barter
|
55
|
+
end
|
56
|
+
suite.execute(Silent)
|
57
|
+
suite.expectations.first
|
58
|
+
end
|
59
|
+
|
60
|
+
expect Expectations::Results::Error do
|
61
|
+
suite = Expectations::Suite.new
|
62
|
+
suite.expect(1) do
|
63
|
+
Object.expects(:give_me_three).with(3).returns 1
|
64
|
+
Object.give_me_three(stub(:three=>3).threes)
|
65
|
+
end
|
66
|
+
suite.execute(Silent)
|
67
|
+
suite.expectations.first
|
68
|
+
end
|
69
|
+
|
70
|
+
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.4
|
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-21 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -39,11 +39,15 @@ files:
|
|
39
39
|
- lib/expectations.rb
|
40
40
|
- test/all_tests.rb
|
41
41
|
- test/expectations/expectation_test.rb
|
42
|
+
- test/expectations/expectations_test.rb
|
43
|
+
- test/expectations/range_test.rb
|
44
|
+
- test/expectations/regexp_test.rb
|
42
45
|
- test/expectations/results_test.rb
|
43
46
|
- test/expectations/string_test.rb
|
44
47
|
- test/expectations/suite_results_test.rb
|
48
|
+
- test/expectations/suite_runner_test.rb
|
45
49
|
- test/expectations/suite_test.rb
|
46
|
-
- test/
|
50
|
+
- test/failures_test.rb
|
47
51
|
- test/sample_expectations_test.rb
|
48
52
|
- test/silent.rb
|
49
53
|
- test/test_helper.rb
|
data/test/failures.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/test_helper"
|
2
|
-
|
3
|
-
Expectations do
|
4
|
-
|
5
|
-
# State based expectation where a value equals another value
|
6
|
-
expect 2 do
|
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
|