fakes 1.1.1 → 1.1.2
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/lib/fakes.rb +1 -1
- data/lib/fakes/arg_matching/argument_matching.rb +34 -0
- data/lib/fakes/fakes.rb +5 -5
- data/lib/fakes/version.rb +1 -1
- data/spec/specs/arg_matching_scenarios_spec.rb +9 -9
- data/spec/specs/{matches_spec.rb → argument_matching_spec.rb} +8 -8
- data/spec/specs/fake_spec.rb +2 -2
- metadata +6 -6
- data/lib/fakes/arg_matching/matches.rb +0 -34
data/lib/fakes.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'fakes/arg_matching/arg_match_factory'
|
2
2
|
require 'fakes/arg_matching/block_arg_matcher'
|
3
3
|
require 'fakes/arg_matching/combined_arg_matcher'
|
4
|
-
require 'fakes/arg_matching/
|
4
|
+
require 'fakes/arg_matching/argument_matching'
|
5
5
|
require 'fakes/arg_matching/regular_arg_matcher'
|
6
6
|
require 'fakes/arg_behaviour'
|
7
7
|
require 'fakes/arg_set'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Fakes
|
2
|
+
module ArgumentMatching
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def not_nil
|
6
|
+
condition { |item| item != nil }
|
7
|
+
end
|
8
|
+
|
9
|
+
def nil
|
10
|
+
condition { |item| item == nil }
|
11
|
+
end
|
12
|
+
|
13
|
+
def any
|
14
|
+
condition { |ignored| true }
|
15
|
+
end
|
16
|
+
|
17
|
+
def greater_than(value)
|
18
|
+
condition { |number| number > value }
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def in_range(range)
|
23
|
+
condition { |item| range === item }
|
24
|
+
end
|
25
|
+
|
26
|
+
def regex(pattern)
|
27
|
+
condition { |string_value| pattern =~ string_value }
|
28
|
+
end
|
29
|
+
|
30
|
+
def condition(&conditional_block)
|
31
|
+
return BlockArgMatcher.new(conditional_block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/fakes/fakes.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
|
1
|
+
module Fakes
|
2
2
|
def fake(invocations = {})
|
3
|
-
item =
|
3
|
+
item = Fake.new
|
4
4
|
invocations.each{|method,return_value| item.stub(method).and_return(return_value)}
|
5
5
|
item
|
6
6
|
end
|
7
7
|
|
8
8
|
def arg_match
|
9
|
-
return
|
9
|
+
return ArgumentMatching
|
10
10
|
end
|
11
11
|
|
12
12
|
def fake_class(klass,invocations = {})
|
13
13
|
item = fake(invocations)
|
14
|
-
|
14
|
+
ClassSwaps.instance.add_fake_for(klass,item)
|
15
15
|
item
|
16
16
|
end
|
17
17
|
|
18
18
|
def reset_fake_classes
|
19
|
-
|
19
|
+
ClassSwaps.instance.reset
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
data/lib/fakes/version.rb
CHANGED
@@ -7,7 +7,7 @@ module Fakes
|
|
7
7
|
|
8
8
|
fake.hello("World")
|
9
9
|
|
10
|
-
fake.received(:hello).called_with(
|
10
|
+
fake.received(:hello).called_with(ArgumentMatching.any).should_not be_nil
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should be able to intercept using greater than matchers" do
|
@@ -15,7 +15,7 @@ module Fakes
|
|
15
15
|
|
16
16
|
fake.hello(10)
|
17
17
|
|
18
|
-
fake.received(:hello).called_with(
|
18
|
+
fake.received(:hello).called_with(ArgumentMatching.greater_than(2)).should_not be_nil
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should be able to intercept using regex matchers" do
|
@@ -23,7 +23,7 @@ module Fakes
|
|
23
23
|
|
24
24
|
fake.hello("This is cool")
|
25
25
|
|
26
|
-
fake.received(:hello).called_with(
|
26
|
+
fake.received(:hello).called_with(ArgumentMatching.regex(/is/)).should_not be_nil
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should be able to intercept using range matchers" do
|
@@ -31,7 +31,7 @@ module Fakes
|
|
31
31
|
|
32
32
|
fake.hello(7)
|
33
33
|
|
34
|
-
fake.received(:hello).called_with(
|
34
|
+
fake.received(:hello).called_with(ArgumentMatching.in_range(4..8)).should_not be_nil
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should be able to intercept using conditional matchers" do
|
@@ -39,7 +39,7 @@ module Fakes
|
|
39
39
|
|
40
40
|
fake.hello(7)
|
41
41
|
|
42
|
-
fake.received(:hello).called_with(
|
42
|
+
fake.received(:hello).called_with(ArgumentMatching.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
|
@@ -47,10 +47,10 @@ module Fakes
|
|
47
47
|
|
48
48
|
fake.hello(7,4,"Yes")
|
49
49
|
|
50
|
-
fake.received(:hello).called_with(7,
|
51
|
-
fake.received(:hello).called_with(7,
|
52
|
-
fake.received(:hello).called_with(7,
|
53
|
-
fake.received(:hello).called_with(6,
|
50
|
+
fake.received(:hello).called_with(7,ArgumentMatching.greater_than(2),ArgumentMatching.regex(/Y/)).should_not be_nil
|
51
|
+
fake.received(:hello).called_with(7,ArgumentMatching.any,ArgumentMatching.regex(/Y/)).should_not be_nil
|
52
|
+
fake.received(:hello).called_with(7,ArgumentMatching.any,"Yes").should_not be_nil
|
53
|
+
fake.received(:hello).called_with(6,ArgumentMatching.any,"Yes").should be_nil
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -1,40 +1,40 @@
|
|
1
1
|
module Fakes
|
2
|
-
describe
|
2
|
+
describe ArgumentMatching do
|
3
3
|
context "when creating matchers" do
|
4
4
|
it "should be able to create a matcher that matches anything" do
|
5
|
-
(1..10).each{|item|
|
5
|
+
(1..10).each{|item| ArgumentMatching.any.matches?(item).should be_true}
|
6
6
|
end
|
7
7
|
it "should be able to create a numeric greater than matcher" do
|
8
|
-
match =
|
8
|
+
match = ArgumentMatching.greater_than(5)
|
9
9
|
match.matches?(4).should be_false
|
10
10
|
match.matches?(5).should be_false
|
11
11
|
match.matches?(6).should be_true
|
12
12
|
|
13
13
|
end
|
14
14
|
it "should be able to create a range matcher" do
|
15
|
-
match =
|
15
|
+
match = ArgumentMatching.in_range((1..10))
|
16
16
|
match.matches?(4).should be_true
|
17
17
|
match.matches?(10).should be_true
|
18
18
|
match.matches?(11).should be_false
|
19
19
|
end
|
20
20
|
it "should be able to create a nil matcher" do
|
21
|
-
match =
|
21
|
+
match = ArgumentMatching.nil
|
22
22
|
match.matches?(nil).should be_true
|
23
23
|
match.matches?(10).should be_false
|
24
24
|
end
|
25
25
|
it "should be able to create a not nil matcher" do
|
26
|
-
match =
|
26
|
+
match = ArgumentMatching.not_nil
|
27
27
|
match.matches?(10).should be_true
|
28
28
|
match.matches?(nil).should be_false
|
29
29
|
end
|
30
30
|
it "should be able to create a regex string matcher" do
|
31
|
-
match =
|
31
|
+
match = ArgumentMatching.regex(/a|e|i|o|u/)
|
32
32
|
match.matches?("awwef").should be_true
|
33
33
|
match.matches?("rwwgf").should be_false
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should be able to create a lambda based matcher" do
|
37
|
-
match =
|
37
|
+
match = ArgumentMatching.condition{|item| item > 3}
|
38
38
|
match.matches?(2).should be_false
|
39
39
|
match.matches?(7).should be_true
|
40
40
|
end
|
data/spec/specs/fake_spec.rb
CHANGED
@@ -200,13 +200,13 @@ module Fakes
|
|
200
200
|
it "should be able to intercept on methods using the matches factory" do
|
201
201
|
fake = Fake.new
|
202
202
|
|
203
|
-
fake.stub(:hello).with(
|
203
|
+
fake.stub(:hello).with(ArgumentMatching.regex(/W/)).and_return("Hello World")
|
204
204
|
fake.hello("World").should == "Hello World"
|
205
205
|
end
|
206
206
|
it "should be able to intercept on methods using combinations of explicit values and matchers" do
|
207
207
|
fake = Fake.new
|
208
208
|
|
209
|
-
fake.stub(:hello).with(
|
209
|
+
fake.stub(:hello).with(ArgumentMatching.regex(/W/),ArgumentMatching.greater_than(3),10).and_return("Hello World")
|
210
210
|
|
211
211
|
fake.hello("World",4,10).should == "Hello World"
|
212
212
|
fake.hello("World",2,10).should == nil
|
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: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -93,9 +93,9 @@ files:
|
|
93
93
|
- lib/fakes.rb
|
94
94
|
- lib/fakes/arg_behaviour.rb
|
95
95
|
- lib/fakes/arg_matching/arg_match_factory.rb
|
96
|
+
- lib/fakes/arg_matching/argument_matching.rb
|
96
97
|
- lib/fakes/arg_matching/block_arg_matcher.rb
|
97
98
|
- lib/fakes/arg_matching/combined_arg_matcher.rb
|
98
|
-
- lib/fakes/arg_matching/matches.rb
|
99
99
|
- lib/fakes/arg_matching/regular_arg_matcher.rb
|
100
100
|
- lib/fakes/arg_set.rb
|
101
101
|
- lib/fakes/class_swap.rb
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- spec/specs/arg_match_factory_spec.rb
|
111
111
|
- spec/specs/arg_matching_scenarios_spec.rb
|
112
112
|
- spec/specs/arg_set_spec.rb
|
113
|
+
- spec/specs/argument_matching_spec.rb
|
113
114
|
- spec/specs/block_arg_matcher_spec.rb
|
114
115
|
- spec/specs/class_swap_spec.rb
|
115
116
|
- spec/specs/class_swaps_spec.rb
|
@@ -117,7 +118,6 @@ files:
|
|
117
118
|
- spec/specs/extensions_spec.rb
|
118
119
|
- spec/specs/fake_spec.rb
|
119
120
|
- spec/specs/ignore_set_spec.rb
|
120
|
-
- spec/specs/matches_spec.rb
|
121
121
|
- spec/specs/method_stub_spec.rb
|
122
122
|
- spec/specs/regular_arg_matcher_spec.rb
|
123
123
|
homepage: http://www.developwithpassion.com
|
@@ -134,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
segments:
|
136
136
|
- 0
|
137
|
-
hash:
|
137
|
+
hash: -2245733213966306634
|
138
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
segments:
|
145
145
|
- 0
|
146
|
-
hash:
|
146
|
+
hash: -2245733213966306634
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project: fakes
|
149
149
|
rubygems_version: 1.8.25
|
@@ -156,6 +156,7 @@ test_files:
|
|
156
156
|
- spec/specs/arg_match_factory_spec.rb
|
157
157
|
- spec/specs/arg_matching_scenarios_spec.rb
|
158
158
|
- spec/specs/arg_set_spec.rb
|
159
|
+
- spec/specs/argument_matching_spec.rb
|
159
160
|
- spec/specs/block_arg_matcher_spec.rb
|
160
161
|
- spec/specs/class_swap_spec.rb
|
161
162
|
- spec/specs/class_swaps_spec.rb
|
@@ -163,6 +164,5 @@ test_files:
|
|
163
164
|
- spec/specs/extensions_spec.rb
|
164
165
|
- spec/specs/fake_spec.rb
|
165
166
|
- spec/specs/ignore_set_spec.rb
|
166
|
-
- spec/specs/matches_spec.rb
|
167
167
|
- spec/specs/method_stub_spec.rb
|
168
168
|
- spec/specs/regular_arg_matcher_spec.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Fakes
|
2
|
-
class Matches
|
3
|
-
class << self
|
4
|
-
def not_nil
|
5
|
-
condition { |item| item != nil }
|
6
|
-
end
|
7
|
-
|
8
|
-
def nil
|
9
|
-
condition { |item| item == nil }
|
10
|
-
end
|
11
|
-
|
12
|
-
def any
|
13
|
-
condition { |ignored| true }
|
14
|
-
end
|
15
|
-
|
16
|
-
def greater_than(value)
|
17
|
-
condition { |number| number > value }
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def in_range(range)
|
22
|
-
condition { |item| range === item }
|
23
|
-
end
|
24
|
-
|
25
|
-
def regex(pattern)
|
26
|
-
condition { |string_value| pattern =~ string_value }
|
27
|
-
end
|
28
|
-
|
29
|
-
def condition(&conditional_block)
|
30
|
-
return BlockArgMatcher.new(conditional_block)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|