fakes 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -72,10 +72,16 @@ collaborator.stub(:method).with(1).and_return(first_return_value)
72
72
  #Setup a return value for 2
73
73
  collaborator.stub(:method).with(2).and_return(second_return_value)
74
74
 
75
+
75
76
  #Setup a return value when called with everything else
76
77
  #if you are going to use this, make sure it is used after
77
78
  #setting up return values for specific arguments
78
79
  collaborator.stub(:method).and_return(value_to_return_with_arguments_other_than_1_and_2)
80
+
81
+
82
+ #Setup a return value for any number greater than 2 - this makes use of the argument matching syntax described [here](http://blog.developwithpassion.com/2012/06/09/fakes-and-in-turn-fakes-rspec-new-feature-arbitrary-argument-matching-for-setup-and-verification-of-calls/)
83
+
84
+ collaborator.stub(:method).with(arg_match.greater_than(2)).and_return(second_return_value)
79
85
  ```
80
86
 
81
87
  ##Verifying calls made to the fake
@@ -145,26 +151,14 @@ it "should trigger its collaborator with the correct message" do
145
151
  end
146
152
  ```
147
153
 
148
- The nice thing is we can make the assertions after the fact, as opposed to needing to do them as part of setup, which I find is a much more natural way to read things, when you need to do this style of test. Notice that the called_with method return a method_invocation that will be nil if the call was not received. My recommendation would be to create a test utility method that allows you to leverage your testing frameworks assertion library to make the above assertion more terse. The
149
- following rspec sample demonstrates:
150
-
151
- ```ruby
152
- module RSpec
153
- Matchers.define :have_received do|symbol,*args|
154
- match do|fake|
155
- fake.received(symbol).called_with(*args) != nil
156
- end
157
- end
158
- end
159
- ```
154
+ The nice thing is we can make the assertions after the fact, as opposed to needing to do them as part of setup, which I find is a much more natural way to read things, when you need to do this style of test. Notice that the called_with method return a method_invocation that will be nil if the call was not received. My recommendation would be to use the [fakes-rspec](http://github.com/developwithpassion/fakes-rpsec) library (if you are using rspec) which gives you access to a predefined matcher that you can use as follows:
160
155
 
161
- Using the above utility method turns the previous assertion:
162
156
 
163
157
  ```ruby
164
158
  collaborator.received(:send_message).called_with("Hello World").should_not be_nil
165
159
  ```
166
160
 
167
- To this:
161
+ Can be done in fakes-rspec by doing this:
168
162
 
169
163
  ```ruby
170
164
  collaborator.should have_received(:send_message,"Hello World")
@@ -172,7 +166,7 @@ collaborator.should have_received(:send_message,"Hello World")
172
166
 
173
167
  ###Verifying that a call should not have been made
174
168
 
175
- Currently verifying that a call was not made does not take the arguments into consideration. It just ensures that no calls to a particular named method were made. Here is an example:
169
+ Verifying that a call was not made can be done with or without arguments:
176
170
 
177
171
  ```ruby
178
172
  class FirstCollaborator
@@ -221,9 +215,11 @@ describe SomeItem do
221
215
  it "should not trigger its second collaborator" do
222
216
  #again, here would be another option to use a convienience test utility method
223
217
  second.never_received?(:send_message).should be_true
218
+ #with fakes-rspec it looks like this
219
+ second.should_not have_received(:send_message)
224
220
  end
225
221
  end
226
222
  end
227
223
  ```
228
224
 
229
- As you can see, in this test we want to verify that one collaborator was triggered and the other not.
225
+ As you can see, in this test we want to verify that one collaborator was triggered and the other not. If you cared about specifying arguments it should not have been called with, you can do the same as a regular verification.
@@ -2,31 +2,31 @@ module Fakes
2
2
  class Matches
3
3
  class << self
4
4
  def not_nil
5
- condition(lambda{|item| item != nil})
5
+ condition{|item| item != nil}
6
6
  end
7
7
 
8
8
  def nil
9
- condition(lambda{|item| item == nil})
9
+ condition{|item| item == nil}
10
10
  end
11
11
 
12
12
  def any
13
- condition(lambda{|ignored| true})
13
+ condition{|ignored| true}
14
14
  end
15
15
 
16
16
  def greater_than(value)
17
- condition(lambda{|number| number > value})
17
+ condition{|number| number > value}
18
18
  end
19
19
 
20
20
 
21
21
  def in_range(range)
22
- condition(lambda{|item| range === item})
22
+ condition{|item| range === item}
23
23
  end
24
24
 
25
25
  def regex(regex)
26
- condition(lambda{|string| regex =~ string})
26
+ condition{|string| regex =~ string}
27
27
  end
28
28
 
29
- def condition(conditional_block)
29
+ def condition(&conditional_block)
30
30
  return BlockArgMatcher.new(conditional_block)
31
31
  end
32
32
  end
data/lib/core/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fakes
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -39,7 +39,7 @@ module Fakes
39
39
 
40
40
  fake.hello(7)
41
41
 
42
- fake.received(:hello).called_with(Matches.condition(lambda{|item| item < 10})).should_not be_nil
42
+ fake.received(:hello).called_with(Matches.condition{|item| item < 10}).should_not be_nil
43
43
  end
44
44
 
45
45
  it "should be able to intercept by mixing regular arguments with matchers" do
@@ -34,7 +34,7 @@ module Fakes
34
34
  end
35
35
 
36
36
  it "should be able to create a lambda based matcher" do
37
- match = Matches.condition(lambda{|item| item > 3})
37
+ match = Matches.condition{|item| item > 3}
38
38
  match.matches?(2).should be_false
39
39
  match.matches?(7).should be_true
40
40
  end
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.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: