fakes 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jean-Paul S. Boodhoo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -6,6 +6,10 @@ module Fakes
6
6
  @return_value = item
7
7
  end
8
8
 
9
+ def throws(exception)
10
+ @exception = exception
11
+ end
12
+
9
13
  def capture_args(args)
10
14
  @times_called += 1
11
15
  @called_args = args
@@ -18,5 +22,12 @@ module Fakes
18
22
  def was_called_with?(args)
19
23
  return @called_args == args
20
24
  end
25
+
26
+ def process
27
+ return @return_value unless @exception
28
+ if @exception
29
+ raise @exception
30
+ end
31
+ end
21
32
  end
22
33
  end
@@ -14,6 +14,9 @@ module Fakes
14
14
  return add_new_set(ArgSet.new(args))
15
15
  end
16
16
 
17
+ def throws(exception)
18
+ ignore_arg.throws(exception)
19
+ end
17
20
 
18
21
  def ignore_arg
19
22
  return add_new_set(IgnoreSet.new)
@@ -27,7 +30,7 @@ module Fakes
27
30
  def invoke(args)
28
31
  set = @arg_sets.find{|item| item.matches?(args)} || ignore_arg
29
32
  set.capture_args(args)
30
- return set.return_value
33
+ return set.process
31
34
  end
32
35
 
33
36
  def called_with(*args)
data/lib/core/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fakes
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -13,12 +13,27 @@ module Fakes
13
13
  before (:each) do
14
14
  sut.send(:extend,ArgBehaviour)
15
15
  end
16
- context "when a return value is specified" do
17
- before (:each) do
18
- sut.and_return(2)
16
+ context "when continuing its execution" do
17
+ context "and no exception has been specified to be thrown" do
18
+ before (:each) do
19
+ sut.and_return(2)
20
+ end
21
+ it "should store the return value to be returned during invocation" do
22
+ sut.process().should == 2
23
+ end
19
24
  end
20
- it "should store the return value to be returned during invocation" do
21
- sut.return_value.should == 2
25
+ context "and an exception has been specified to be thrown" do
26
+ let(:exception){Exception.new}
27
+ before (:each) do
28
+ sut.throws(exception)
29
+ end
30
+ it "should throw the exception" do
31
+ begin
32
+ sut.process()
33
+ rescue Exception => e
34
+ e.should == exception
35
+ end
36
+ end
22
37
  end
23
38
  end
24
39
 
@@ -42,6 +42,34 @@ module Fakes
42
42
  end
43
43
  end
44
44
 
45
+ context "when specified to throw an exception" do
46
+ let(:ignored_set){DummyArgSet.new}
47
+ let(:exception){Object.new}
48
+ let(:arg_sets){[]}
49
+ let(:sut){MethodStub.new(arg_sets)}
50
+
51
+ class DummyArgSet
52
+ attr_accessor :exception
53
+
54
+ def throws(exception)
55
+ @exception = exception
56
+ end
57
+ end
58
+
59
+ before (:each) do
60
+ IgnoreSet.stub(:new).and_return(ignored_set)
61
+ end
62
+
63
+ before (:each) do
64
+ sut.throws(exception)
65
+ end
66
+ it "should add the ignored set to the set of args sets" do
67
+ arg_sets[0].should == ignored_set
68
+ end
69
+ it "should have stored the exception on the new argument set" do
70
+ ignored_set.exception.should == exception
71
+ end
72
+ end
45
73
  context "when invoked with a set of arguments" do
46
74
  let(:arg_sets){[]}
47
75
  let(:sut){MethodStub.new(arg_sets)}
@@ -58,7 +86,7 @@ module Fakes
58
86
  before (:each) do
59
87
  arg_sets.push(arg_set)
60
88
  arg_set.stub(:matches?).and_return(true)
61
- arg_set.stub(:return_value).and_return(2)
89
+ arg_set.stub(:process).and_return(2)
62
90
  end
63
91
  before (:each) do
64
92
  @result = sut.invoke(arguments)
@@ -76,7 +104,7 @@ module Fakes
76
104
  let(:arg_set){DummyArgSet.new}
77
105
  before (:each) do
78
106
  sut.stub(:ignore_arg).and_return(arg_set)
79
- arg_set.stub(:return_value).and_return(2)
107
+ arg_set.stub(:process).and_return(2)
80
108
  end
81
109
  before (:each) do
82
110
  @result = sut.invoke(arguments)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-29 00:00:00.000000000 Z
12
+ date: 2012-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -103,6 +103,7 @@ files:
103
103
  - .rvmrc
104
104
  - Gemfile
105
105
  - Guardfile
106
+ - LICENSE
106
107
  - README.md
107
108
  - Rakefile
108
109
  - fakes.gemspec