orangutan 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 3
3
+ :patch: 4
4
4
  :major: 0
@@ -3,7 +3,7 @@ require 'orangutan/container'
3
3
 
4
4
  module Orangutan
5
5
  class Expectation
6
- attr_reader :return_container, :yield_container, :raiser
6
+ attr_reader :return_container, :yield_container, :raiser, :count
7
7
 
8
8
  def initialize
9
9
  @return_container = nil
@@ -38,8 +38,38 @@ module Orangutan
38
38
 
39
39
  def matches? method, *args
40
40
  return false unless method == @method
41
- return true unless @args
42
- @args == args
41
+ matched = @args ? @args == args : true
42
+ return false if @limit && @count && @count >= @limit
43
+ if matched
44
+ @count ||= 0
45
+ @count += 1
46
+ end
47
+ matched
48
+ end
49
+
50
+ def exactly count
51
+ @limit = count
52
+ self
53
+ end
54
+
55
+ def once
56
+ exactly 1
57
+ end
58
+
59
+ def twice
60
+ exactly 2
61
+ end
62
+
63
+ def times
64
+ self
65
+ end
66
+
67
+ def matched?
68
+ if @limit
69
+ @count && @count >= @limit
70
+ else
71
+ @count
72
+ end
43
73
  end
44
74
  end
45
75
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{orangutan}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mark Ryall"]
9
- s.date = %q{2009-05-11}
9
+ s.date = %q{2009-05-13}
10
10
  s.description = %q{A mocking library that supports creation of ironruby mock objects (in addition to pure ruby ones)}
11
11
  s.email = %q{mark@ryall.name}
12
12
  s.extra_rdoc_files = [
@@ -53,5 +53,51 @@ module Orangutan
53
53
  it 'should store raiser' do
54
54
  @e.raise('description').raiser.should.not == nil
55
55
  end
56
+
57
+ it 'should count matches' do
58
+ (1..10).each do |i|
59
+ @e.matches?(:foo)
60
+ @e.count.should == i
61
+ end
62
+ end
63
+
64
+ it 'should limit matches when given limit of once' do
65
+ @e.once.should == @e
66
+ @e.matches?(:foo).should == true
67
+ @e.matches?(:foo).should == false
68
+ end
69
+
70
+ it 'should limit matches when given limit of twice' do
71
+ @e.twice.should == @e
72
+ 2.times { @e.matches?(:foo).should == true }
73
+ @e.matches?(:foo).should == false
74
+ end
75
+
76
+ it 'should limit matches' do
77
+ @e.exactly(10).times.should == @e
78
+ 10.times { @e.matches?(:foo).should == true }
79
+ @e.matches?(:foo).should == false
80
+ end
81
+
82
+ it 'should initially indicate that expectation was not matched' do
83
+ @e.should.not.be.matched?
84
+ end
85
+
86
+ it 'should when no limit specified indicate that the expectation was matched once' do
87
+ @e.matches?(:foo)
88
+ @e.should.be.matched?
89
+ end
90
+
91
+ it 'should when a limit specified indicate that the expectation was not matched until the is limit reached' do
92
+ @e.twice
93
+ @e.matches?(:foo)
94
+ @e.should.not.be.matched?
95
+ end
96
+
97
+ it 'should when a limit specified indicate that the expectation was matched once the is limit reached' do
98
+ @e.twice
99
+ 2.times { @e.matches?(:foo) }
100
+ @e.should.be.matched?
101
+ end
56
102
  end
57
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orangutan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Ryall
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-11 00:00:00 +10:00
12
+ date: 2009-05-13 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies: []
15
15