rspec 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -0
- data/Rakefile.rb +11 -1
- data/lib/spec/mock.rb +24 -8
- data/lib/spec/text_runner.rb +4 -4
- metadata +1 -1
data/CHANGES
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
= RSpec Changelog
|
2
2
|
|
3
|
+
== Version 0.1.2
|
4
|
+
|
5
|
+
This release adds some improvements to the mock API and minor syntax improvements
|
6
|
+
|
7
|
+
* Added Mock.should_expect for a more consistent DSL
|
8
|
+
* Added MockExpectation.and_returns for a better DSL
|
9
|
+
* Made Mock behave as a null object after a call to Mock.ignore_missing
|
10
|
+
* Internal syntax improvements
|
11
|
+
* Improved exception trace by adding exception class name to error message
|
12
|
+
* Renamed some tests for better consistency
|
13
|
+
|
3
14
|
== Version 0.1.1
|
4
15
|
|
5
16
|
This release adds some shoulds and improves error reporting
|
data/Rakefile.rb
CHANGED
@@ -7,7 +7,17 @@ require 'rake/testtask'
|
|
7
7
|
require 'rake/rdoctask'
|
8
8
|
|
9
9
|
PKG_NAME = "rspec"
|
10
|
-
|
10
|
+
# Versioning scheme: MAJOR.MINOR.PATCH
|
11
|
+
# MAJOR bumps when API is broken backwards
|
12
|
+
# MINOR bumps when the API is broken backwards in a very slight/subtle (but not fatal) way
|
13
|
+
# -OR when a new release is made and propaganda is sent out.
|
14
|
+
# PATCH is bumped for every API addition and/or bugfix (ideally for every commit)
|
15
|
+
# Later DamageControl can bump PATCH automatically.
|
16
|
+
#
|
17
|
+
# (This is subject to change - AH)
|
18
|
+
#
|
19
|
+
# REMEMBER TO KEEP PKG_VERSION IN SYNC WITH CHANGELOG
|
20
|
+
PKG_VERSION = "0.1.2"
|
11
21
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
12
22
|
PKG_FILES = FileList[
|
13
23
|
'[A-Z]*',
|
data/lib/spec/mock.rb
CHANGED
@@ -3,14 +3,17 @@ require 'spec'
|
|
3
3
|
|
4
4
|
class Mock
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize(identifier="")
|
7
7
|
@expectations = Hash.new
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
# How about renaming this to should_expect. This would be well aligned with the rest of
|
11
|
+
# the API, as well as the recommendation to use should as prefix for methods (Aslak)
|
12
|
+
def __expects(sym, &block)
|
13
|
+
@expectations[sym] = MockExpectation.new(block_given? ? block : nil)
|
12
14
|
@expectations[sym]
|
13
|
-
end
|
15
|
+
end
|
16
|
+
alias :should_expect :__expects
|
14
17
|
|
15
18
|
def __verify
|
16
19
|
@expectations.keys.each do |method|
|
@@ -18,6 +21,8 @@ class Mock
|
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
24
|
+
# Tell the mock to act as a forgiving null object on missing methods, in which
|
25
|
+
# case it will return itself.
|
21
26
|
def ignore_missing
|
22
27
|
@ignore_missing = true
|
23
28
|
end
|
@@ -27,9 +32,10 @@ class Mock
|
|
27
32
|
expectation.verify_call(sym.to_s,args,block)
|
28
33
|
else
|
29
34
|
begin
|
30
|
-
|
35
|
+
# act as null object if method is missing and we ignore them. return value too!
|
36
|
+
@ignore_missing ? self : super(sym, *args, &block)
|
31
37
|
rescue NoMethodError
|
32
|
-
raise Spec::Exceptions::MockExpectationError, "Unexpected method
|
38
|
+
raise Spec::Exceptions::MockExpectationError, "Unexpected method '#{sym.to_s}' called."
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
@@ -47,7 +53,13 @@ class MockExpectation
|
|
47
53
|
end
|
48
54
|
|
49
55
|
def verify_call(message,args,block)
|
50
|
-
unless @
|
56
|
+
unless @method_block.nil?
|
57
|
+
result = @method_block.call(*args)
|
58
|
+
@call_count = @call_count + 1
|
59
|
+
return result
|
60
|
+
end
|
61
|
+
|
62
|
+
unless @expected_params.nil? or @expected_params == args
|
51
63
|
raise Spec::Exceptions::MockExpectationError,
|
52
64
|
message+": Parameter mismatch: Expected <#{@expected_params}>, got <#{@args}>"
|
53
65
|
end
|
@@ -56,7 +68,8 @@ class MockExpectation
|
|
56
68
|
@block.call(*args)
|
57
69
|
end
|
58
70
|
|
59
|
-
def initialize
|
71
|
+
def initialize(block)
|
72
|
+
@method_block = block
|
60
73
|
@block = proc {}
|
61
74
|
@expected_call_count = 1
|
62
75
|
@call_count = 0
|
@@ -100,5 +113,8 @@ class MockExpectation
|
|
100
113
|
def returns(value=nil,&block)
|
101
114
|
@block = block_given? ? block : proc { value }
|
102
115
|
end
|
116
|
+
alias :and_return :returns
|
117
|
+
# this reads better: (AH)
|
118
|
+
# uri_specs.should_expect(:[]).with(:overview).and_return("http://some.host/look_here/\#{path}")
|
103
119
|
|
104
120
|
end
|
data/lib/spec/text_runner.rb
CHANGED
@@ -53,12 +53,12 @@ module Spec
|
|
53
53
|
dump_duration(@end_time - @start_time)
|
54
54
|
|
55
55
|
dump_counts
|
56
|
-
end
|
57
|
-
|
56
|
+
end
|
57
|
+
|
58
58
|
def dump_failures
|
59
59
|
@failures.inject(1) do |index, exception|
|
60
|
-
@output << index.to_s << ")
|
61
|
-
@output << exception.
|
60
|
+
@output << index.to_s << ")\n"
|
61
|
+
@output << "#{exception.message} (#{exception.class.name})\n"
|
62
62
|
dump_backtrace(exception.backtrace)
|
63
63
|
index + 1
|
64
64
|
end
|