developwithpassion_fakes 0.0.3 → 0.0.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/Guardfile +5 -0
- data/developwithpassion_fakes.gemspec +2 -0
- data/lib/developwithpassion_fakes/arg_behaviour.rb +6 -4
- data/lib/developwithpassion_fakes/arg_set.rb +2 -2
- data/lib/developwithpassion_fakes/fake.rb +3 -3
- data/lib/developwithpassion_fakes/ignore_set.rb +3 -3
- data/lib/developwithpassion_fakes/method_stub.rb +5 -5
- data/lib/developwithpassion_fakes/version.rb +1 -1
- data/spec/specs/arg_behaviour_spec.rb +12 -3
- data/spec/specs/fake_spec.rb +77 -2
- data/spec/specs/ignore_set_spec.rb +2 -2
- data/spec/specs/method_stub_spec.rb +3 -3
- metadata +29 -6
data/Guardfile
ADDED
@@ -21,5 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
# specify any dependencies here; for example:
|
22
22
|
s.add_development_dependency "rspec"
|
23
23
|
s.add_development_dependency "rake"
|
24
|
+
s.add_development_dependency "guard"
|
25
|
+
s.add_development_dependency "guard-rspec"
|
24
26
|
# s.add_runtime_dependency "rest-client"
|
25
27
|
end
|
@@ -7,16 +7,18 @@ module DevelopWithPassion
|
|
7
7
|
@return_value = item
|
8
8
|
end
|
9
9
|
|
10
|
-
def capture_args(
|
10
|
+
def capture_args(args)
|
11
11
|
@times_called += 1
|
12
|
-
@called_args =
|
12
|
+
@called_args = args
|
13
13
|
end
|
14
14
|
|
15
|
-
def matches?(
|
15
|
+
def matches?(args)
|
16
|
+
puts @args.class
|
17
|
+
puts args[0].class
|
16
18
|
return @args == args
|
17
19
|
end
|
18
20
|
|
19
|
-
def was_called_with?(
|
21
|
+
def was_called_with?(args)
|
20
22
|
return @called_args == args
|
21
23
|
end
|
22
24
|
end
|
@@ -6,13 +6,13 @@ module DevelopWithPassion
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def method_missing(name,*args,&block)
|
9
|
-
return @method_invocations.has_key?(name.to_sym) ? @method_invocations[name.to_sym].invoke(
|
9
|
+
return @method_invocations.has_key?(name.to_sym) ? @method_invocations[name.to_sym].invoke(args) : handle_unexpected_method_invocation(name,args,block)
|
10
10
|
end
|
11
11
|
|
12
|
-
def handle_unexpected_method_invocation(name
|
12
|
+
def handle_unexpected_method_invocation(name,args,block)
|
13
13
|
method = stub(name.to_sym)
|
14
14
|
method.ignore_arg
|
15
|
-
return method.invoke(
|
15
|
+
return method.invoke(args)
|
16
16
|
end
|
17
17
|
|
18
18
|
def stub(symbol)
|
@@ -9,16 +9,16 @@ module DevelopWithPassion
|
|
9
9
|
@arg_sets = []
|
10
10
|
end
|
11
11
|
|
12
|
-
def matches?(
|
12
|
+
def matches?(args)
|
13
13
|
return true
|
14
14
|
end
|
15
15
|
|
16
|
-
def capture_args(
|
16
|
+
def capture_args(args)
|
17
17
|
@times_called += 1
|
18
18
|
@arg_sets << args
|
19
19
|
end
|
20
20
|
|
21
|
-
def was_called_with?(
|
21
|
+
def was_called_with?(args)
|
22
22
|
return @arg_sets.select{|set| set == args}.count > 0
|
23
23
|
end
|
24
24
|
end
|
@@ -6,7 +6,7 @@ module DevelopWithPassion
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def with(*args)
|
9
|
-
return add_new_set(ArgSet.new(
|
9
|
+
return add_new_set(ArgSet.new(args))
|
10
10
|
end
|
11
11
|
|
12
12
|
def add_new_set(set)
|
@@ -23,14 +23,14 @@ module DevelopWithPassion
|
|
23
23
|
end
|
24
24
|
|
25
25
|
|
26
|
-
def invoke(
|
27
|
-
set = @arg_sets.find{|item| item.matches?(
|
28
|
-
set.capture_args(
|
26
|
+
def invoke(args)
|
27
|
+
set = @arg_sets.find{|item| item.matches?(args)} || ignore_arg
|
28
|
+
set.capture_args(args)
|
29
29
|
return set.return_value
|
30
30
|
end
|
31
31
|
|
32
32
|
def called_with(*args)
|
33
|
-
return @arg_sets.find{|item| item.was_called_with?(
|
33
|
+
return @arg_sets.find{|item| item.was_called_with?(args)}
|
34
34
|
end
|
35
35
|
|
36
36
|
def times?(value)
|
@@ -31,13 +31,13 @@ module DevelopWithPassion
|
|
31
31
|
sut.times_called.should == 1
|
32
32
|
end
|
33
33
|
it "should store the arguments it was called with" do
|
34
|
-
sut.called_args.should ==
|
34
|
+
sut.called_args.should == 2
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context "when matching a set of arguments" do
|
39
39
|
before (:each) do
|
40
|
-
sut.args =
|
40
|
+
sut.args = 2
|
41
41
|
end
|
42
42
|
it "should match if its own set of arguments are the same" do
|
43
43
|
sut.matches?(2).should be_true
|
@@ -45,9 +45,18 @@ module DevelopWithPassion
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
context "when matching a set of arguments that is passed in as a dictionary" do
|
49
|
+
before (:each) do
|
50
|
+
sut.args = {:id => 0,:name => "JP"}
|
51
|
+
end
|
52
|
+
it "should match if its hash is the same" do
|
53
|
+
sut.matches?(:id => 0,:name => "JP").should be_true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
48
57
|
context "when determining whether it was called with a set of arguments" do
|
49
58
|
before (:each) do
|
50
|
-
sut.called_args =
|
59
|
+
sut.called_args = 2
|
51
60
|
end
|
52
61
|
|
53
62
|
it "should match if the arguments are the same as the arguments it was invoked with" do
|
data/spec/specs/fake_spec.rb
CHANGED
@@ -104,7 +104,7 @@ module DevelopWithPassion
|
|
104
104
|
@result = sut.hello(args)
|
105
105
|
end
|
106
106
|
it "should trigger the invocation with the arguments" do
|
107
|
-
invocation.args.should == args
|
107
|
+
invocation.args.should == [args]
|
108
108
|
end
|
109
109
|
it "should return the result of triggering the invocation" do
|
110
110
|
@result.should == invocation.return_value
|
@@ -126,14 +126,89 @@ module DevelopWithPassion
|
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should invoke the invocation with the arguments" do
|
129
|
-
invocation.args.should == args
|
129
|
+
invocation.args.should == [args]
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should return the result of triggering the new invocation" do
|
133
133
|
@result.should == invocation.return_value
|
134
134
|
end
|
135
135
|
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "scenarios" do
|
139
|
+
context "setting up return values" do
|
140
|
+
it "should be able to intercept on methods that take a singular value" do
|
141
|
+
fake = Fake.new
|
142
|
+
fake.stub(:hello).with("World").and_return("Hello World")
|
143
|
+
fake.hello("World").should == "Hello World"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should be able to intercept on methods that take a hash" do
|
147
|
+
fake = Fake.new
|
148
|
+
fake.stub(:hello).with(:id => "JP",:age => 33).and_return("Hello World")
|
149
|
+
fake.hello(:id => "JP",:age => 33).should == "Hello World"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should be able to intercept on methods that take a value and a hash" do
|
153
|
+
fake = Fake.new
|
154
|
+
fake.stub(:hello).with(1,:id => "JP",:age => 33).and_return("Hello World")
|
155
|
+
|
156
|
+
fake.hello(1,:id => "JP",:age => 33).should == "Hello World"
|
157
|
+
fake.hello(2,:id => "JP",:age => 33).should be_nil
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should be able to intercept on methods that take an array" do
|
161
|
+
fake = Fake.new
|
162
|
+
fake.stub(:hello).with([1,2,3,4]).and_return("Hello World")
|
163
|
+
|
164
|
+
fake.hello([1,2,3,4]).should == "Hello World"
|
165
|
+
end
|
136
166
|
|
167
|
+
it "should be able to intercept on methods that take an value, and an array" do
|
168
|
+
fake = Fake.new
|
169
|
+
fake.stub(:hello).with(1,[1,2,3,4]).and_return("Hello World")
|
170
|
+
|
171
|
+
fake.hello(1,[1,2,3,4]).should == "Hello World"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
context "verifying calls were made" do
|
175
|
+
it "should be able to intercept on methods that take a singular value" do
|
176
|
+
fake = Fake.new
|
177
|
+
fake.hello("World")
|
178
|
+
fake.received(:hello).called_with("World").should be_true
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should be able to intercept on methods that take a hash" do
|
182
|
+
fake = Fake.new
|
183
|
+
fake.hello(:id => "JP",:age => 33)
|
184
|
+
fake.received(:hello).called_with(:id => "JP",:age => 33).should_not be_nil
|
185
|
+
fake.received(:hello).called_with(:id => "JS",:age => 33).should be_nil
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should be able to intercept on methods that take a value and a hash" do
|
189
|
+
fake = Fake.new
|
190
|
+
|
191
|
+
fake.hello(1,:id => "JP",:age => 33)
|
192
|
+
fake.received(:hello).called_with(1,:id => "JP",:age => 33).should_not be_nil
|
193
|
+
fake.received(:hello).called_with(1,:id => "JS",:age => 33).should be_nil
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should be able to intercept on methods that take an array" do
|
197
|
+
fake = Fake.new
|
198
|
+
|
199
|
+
fake.hello([1,2,3,4])
|
200
|
+
fake.received(:hello).called_with([1,2,3,4]).should_not be_nil
|
201
|
+
fake.received(:hello).called_with([1,2,3,5]).should be_nil
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should be able to intercept on methods that take an value, and an array" do
|
205
|
+
fake = Fake.new
|
206
|
+
fake.hello(1,[1,2,3,4])
|
207
|
+
|
208
|
+
fake.received(:hello).called_with(1,[1,2,3,4]).should_not be_nil
|
209
|
+
fake.received(:hello).called_with(1,[1,2,3,5]).should be_nil
|
210
|
+
end
|
211
|
+
end
|
137
212
|
end
|
138
213
|
end
|
139
214
|
end
|
@@ -13,8 +13,8 @@ module DevelopWithPassion
|
|
13
13
|
|
14
14
|
context "when matching an argument set" do
|
15
15
|
it "should match any argument set" do
|
16
|
-
sut.matches?(1,2,3,4).should be_true
|
17
|
-
sut.matches?(3,"hello",4,5).should be_true
|
16
|
+
sut.matches?([1,2,3,4]).should be_true
|
17
|
+
sut.matches?([3,"hello",4,5]).should be_true
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -11,7 +11,7 @@ module DevelopWithPassion
|
|
11
11
|
let(:sut){MethodStub.new(arg_sets)}
|
12
12
|
|
13
13
|
before (:each) do
|
14
|
-
ArgSet.stub(:new).with(args).and_return(argument_set)
|
14
|
+
ArgSet.stub(:new).with([args]).and_return(argument_set)
|
15
15
|
end
|
16
16
|
before (:each) do
|
17
17
|
@result = sut.with(args)
|
@@ -102,13 +102,13 @@ module DevelopWithPassion
|
|
102
102
|
@args = *args
|
103
103
|
end
|
104
104
|
end
|
105
|
-
let(:arguments){
|
105
|
+
let(:arguments){1}
|
106
106
|
|
107
107
|
context "and one of its argument sets was called with the set of arguments" do
|
108
108
|
let(:arg_set){DummyArgSet.new}
|
109
109
|
before (:each) do
|
110
110
|
arg_sets.push(arg_set)
|
111
|
-
arg_set.stub(:was_called_with?).with(arguments).and_return(true)
|
111
|
+
arg_set.stub(:was_called_with?).with([arguments]).and_return(true)
|
112
112
|
end
|
113
113
|
before (:each) do
|
114
114
|
@result = sut.called_with(arguments)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: developwithpassion_fakes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70290466330660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70290466330660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70290466330200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,29 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70290466330200
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: guard
|
38
|
+
requirement: &70290466329760 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70290466329760
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: guard-rspec
|
49
|
+
requirement: &70290466329320 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70290466329320
|
36
58
|
description: Faking library that allows inspection of received calls after they have
|
37
59
|
been made. Also supports tracking calls with multiple argument sets.
|
38
60
|
email:
|
@@ -44,6 +66,7 @@ files:
|
|
44
66
|
- .gitignore
|
45
67
|
- .rvmrc
|
46
68
|
- Gemfile
|
69
|
+
- Guardfile
|
47
70
|
- README.md
|
48
71
|
- Rakefile
|
49
72
|
- developwithpassion_fakes.gemspec
|
@@ -81,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
104
|
version: '0'
|
82
105
|
requirements: []
|
83
106
|
rubyforge_project: developwithpassion_fakes
|
84
|
-
rubygems_version: 1.8.
|
107
|
+
rubygems_version: 1.8.17
|
85
108
|
signing_key:
|
86
109
|
specification_version: 3
|
87
110
|
summary: Simple faking library
|