fakes 1.0.31 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/fakes.gemspec +1 -2
- data/lib/{core → fakes}/arg_behaviour.rb +0 -0
- data/lib/{core → fakes}/arg_matching/arg_match_factory.rb +0 -0
- data/lib/{core → fakes}/arg_matching/block_arg_matcher.rb +0 -0
- data/lib/{core → fakes}/arg_matching/combined_arg_matcher.rb +3 -2
- data/lib/{core → fakes}/arg_matching/matches.rb +7 -7
- data/lib/{core → fakes}/arg_matching/regular_arg_matcher.rb +0 -0
- data/lib/{core → fakes}/arg_set.rb +0 -0
- data/lib/{core → fakes}/class_swap.rb +0 -0
- data/lib/{core → fakes}/class_swaps.rb +0 -0
- data/lib/{core → fakes}/fake.rb +0 -0
- data/lib/fakes/fakes.rb +22 -0
- data/lib/{core → fakes}/ignore_set.rb +10 -7
- data/lib/{core → fakes}/method_stub.rb +7 -9
- data/lib/fakes/version.rb +3 -0
- data/lib/fakes.rb +14 -31
- data/spec/specs/extensions_spec.rb +1 -1
- metadata +21 -31
- data/.rvmrc +0 -1
- data/lib/core/version.rb +0 -3
data/.gitignore
CHANGED
data/fakes.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib",__FILE__)
|
3
|
-
require "
|
3
|
+
require "fakes/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "fakes"
|
@@ -21,5 +21,4 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_development_dependency "rake"
|
22
22
|
s.add_development_dependency "guard"
|
23
23
|
s.add_development_dependency "guard-rspec"
|
24
|
-
s.add_runtime_dependency "developwithpassion_arrays"
|
25
24
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -8,8 +8,9 @@ module Fakes
|
|
8
8
|
|
9
9
|
def matches?(args)
|
10
10
|
matches = true
|
11
|
-
|
12
|
-
|
11
|
+
@all_matchers.each_with_index do |matcher, index|
|
12
|
+
value = args[index]
|
13
|
+
matches &= matcher.matches?(value)
|
13
14
|
return false unless matches
|
14
15
|
end
|
15
16
|
matches
|
@@ -2,28 +2,28 @@ module Fakes
|
|
2
2
|
class Matches
|
3
3
|
class << self
|
4
4
|
def not_nil
|
5
|
-
condition{|item| item != nil}
|
5
|
+
condition { |item| item != nil }
|
6
6
|
end
|
7
7
|
|
8
8
|
def nil
|
9
|
-
condition{|item| item == nil}
|
9
|
+
condition { |item| item == nil }
|
10
10
|
end
|
11
11
|
|
12
12
|
def any
|
13
|
-
condition{|ignored| true}
|
13
|
+
condition { |ignored| true }
|
14
14
|
end
|
15
15
|
|
16
16
|
def greater_than(value)
|
17
|
-
condition{|number| number > value}
|
17
|
+
condition { |number| number > value }
|
18
18
|
end
|
19
19
|
|
20
20
|
|
21
21
|
def in_range(range)
|
22
|
-
condition{|item| range === item}
|
22
|
+
condition { |item| range === item }
|
23
23
|
end
|
24
24
|
|
25
|
-
def regex(
|
26
|
-
condition{|
|
25
|
+
def regex(pattern)
|
26
|
+
condition { |string_value| pattern =~ string_value }
|
27
27
|
end
|
28
28
|
|
29
29
|
def condition(&conditional_block)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/{core → fakes}/fake.rb
RENAMED
File without changes
|
data/lib/fakes/fakes.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fakes
|
2
|
+
def fake(invocations = {})
|
3
|
+
item = Fakes::Fake.new
|
4
|
+
invocations.each{|method,return_value| item.stub(method).and_return(return_value)}
|
5
|
+
item
|
6
|
+
end
|
7
|
+
|
8
|
+
def arg_match
|
9
|
+
return Fakes::Matches
|
10
|
+
end
|
11
|
+
|
12
|
+
def fake_class(klass,invocations = {})
|
13
|
+
item = fake(invocations)
|
14
|
+
Fakes::ClassSwaps.instance.add_fake_for(klass,item)
|
15
|
+
item
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset_fake_classes
|
19
|
+
Fakes::ClassSwaps.instance.reset
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -3,22 +3,25 @@ module Fakes
|
|
3
3
|
include ArgBehaviour
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
array :arg_sets do|a|
|
7
|
-
a.mutator :capture_args do|args|
|
8
|
-
@times_called += 1
|
9
|
-
@arg_sets << args
|
10
|
-
end
|
11
|
-
end
|
12
6
|
@times_called = 0
|
13
7
|
end
|
14
8
|
|
9
|
+
def arg_sets
|
10
|
+
@arg_sets ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
def capture_args(args)
|
14
|
+
@times_called += 1
|
15
|
+
self.arg_sets << args
|
16
|
+
end
|
17
|
+
|
15
18
|
def matches?(args)
|
16
19
|
return true
|
17
20
|
end
|
18
21
|
|
19
22
|
def was_called_with?(args)
|
20
23
|
matcher = ArgMatchFactory.create_arg_matcher_using(args)
|
21
|
-
return
|
24
|
+
return self.arg_sets.select{|set| matcher.matches?(set)}.count > 0
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module Fakes
|
2
2
|
class MethodStub
|
3
3
|
def initialize(arg_sets = [])
|
4
|
-
array :arg_sets do|a|
|
5
|
-
a.mutator :add_new_set do|set|
|
6
|
-
@arg_sets << set
|
7
|
-
set
|
8
|
-
end
|
9
|
-
end
|
10
4
|
@arg_sets = arg_sets
|
11
5
|
end
|
12
6
|
|
7
|
+
def add_new_argument_set(set)
|
8
|
+
@arg_sets << set
|
9
|
+
set
|
10
|
+
end
|
11
|
+
|
13
12
|
def with(*args)
|
14
|
-
return
|
13
|
+
return add_new_argument_set(ArgSet.new(args))
|
15
14
|
end
|
16
15
|
|
17
16
|
def throws(exception)
|
@@ -19,14 +18,13 @@ module Fakes
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def ignore_arg
|
22
|
-
return
|
21
|
+
return add_new_argument_set(IgnoreSet.new)
|
23
22
|
end
|
24
23
|
|
25
24
|
def and_return(item)
|
26
25
|
ignore_arg.and_return(item)
|
27
26
|
end
|
28
27
|
|
29
|
-
|
30
28
|
def invoke(args)
|
31
29
|
set = @arg_sets.find{|item| item.matches?(args)} || ignore_arg
|
32
30
|
set.capture_args(args)
|
data/lib/fakes.rb
CHANGED
@@ -1,34 +1,17 @@
|
|
1
|
-
require '
|
1
|
+
require 'fakes/arg_matching/arg_match_factory'
|
2
|
+
require 'fakes/arg_matching/block_arg_matcher'
|
3
|
+
require 'fakes/arg_matching/combined_arg_matcher'
|
4
|
+
require 'fakes/arg_matching/matches'
|
5
|
+
require 'fakes/arg_matching/regular_arg_matcher'
|
6
|
+
require 'fakes/arg_behaviour'
|
7
|
+
require 'fakes/arg_set'
|
8
|
+
require 'fakes/class_swap'
|
9
|
+
require 'fakes/class_swaps'
|
10
|
+
require 'fakes/fake'
|
11
|
+
require 'fakes/ignore_set'
|
12
|
+
require 'fakes/method_stub'
|
13
|
+
require 'fakes/fakes'
|
2
14
|
|
3
|
-
require 'core/arg_matching/arg_match_factory'
|
4
|
-
require 'core/arg_matching/block_arg_matcher'
|
5
|
-
require 'core/arg_matching/combined_arg_matcher'
|
6
|
-
require 'core/arg_matching/matches'
|
7
|
-
require 'core/arg_matching/regular_arg_matcher'
|
8
|
-
require 'core/arg_behaviour'
|
9
|
-
require 'core/arg_set'
|
10
|
-
require 'core/class_swap'
|
11
|
-
require 'core/class_swaps'
|
12
|
-
require 'core/fake'
|
13
|
-
require 'core/ignore_set'
|
14
|
-
require 'core/method_stub'
|
15
15
|
require 'singleton'
|
16
16
|
|
17
|
-
|
18
|
-
def fake(invocations = {})
|
19
|
-
item = Fakes::Fake.new
|
20
|
-
invocations.each{|method,return_value| item.stub(method).and_return(return_value)}
|
21
|
-
item
|
22
|
-
end
|
23
|
-
def arg_match
|
24
|
-
return Fakes::Matches
|
25
|
-
end
|
26
|
-
def fake_class(klass,invocations = {})
|
27
|
-
item = fake(invocations)
|
28
|
-
Fakes::ClassSwaps.instance.add_fake_for(klass,item)
|
29
|
-
item
|
30
|
-
end
|
31
|
-
def reset_fake_classes
|
32
|
-
Fakes::ClassSwaps.instance.reset
|
33
|
-
end
|
34
|
-
end
|
17
|
+
include Fakes
|
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,22 +75,6 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: developwithpassion_arrays
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
86
|
-
type: :runtime
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
94
78
|
description: Faking library that allows inspection of received calls after they have
|
95
79
|
been made. Also supports tracking calls with multiple argument sets.
|
96
80
|
email:
|
@@ -100,27 +84,27 @@ extensions: []
|
|
100
84
|
extra_rdoc_files: []
|
101
85
|
files:
|
102
86
|
- .gitignore
|
103
|
-
- .rvmrc
|
104
87
|
- Gemfile
|
105
88
|
- Guardfile
|
106
89
|
- LICENSE
|
107
90
|
- README.md
|
108
91
|
- Rakefile
|
109
92
|
- fakes.gemspec
|
110
|
-
- lib/core/arg_behaviour.rb
|
111
|
-
- lib/core/arg_matching/arg_match_factory.rb
|
112
|
-
- lib/core/arg_matching/block_arg_matcher.rb
|
113
|
-
- lib/core/arg_matching/combined_arg_matcher.rb
|
114
|
-
- lib/core/arg_matching/matches.rb
|
115
|
-
- lib/core/arg_matching/regular_arg_matcher.rb
|
116
|
-
- lib/core/arg_set.rb
|
117
|
-
- lib/core/class_swap.rb
|
118
|
-
- lib/core/class_swaps.rb
|
119
|
-
- lib/core/fake.rb
|
120
|
-
- lib/core/ignore_set.rb
|
121
|
-
- lib/core/method_stub.rb
|
122
|
-
- lib/core/version.rb
|
123
93
|
- lib/fakes.rb
|
94
|
+
- lib/fakes/arg_behaviour.rb
|
95
|
+
- lib/fakes/arg_matching/arg_match_factory.rb
|
96
|
+
- lib/fakes/arg_matching/block_arg_matcher.rb
|
97
|
+
- lib/fakes/arg_matching/combined_arg_matcher.rb
|
98
|
+
- lib/fakes/arg_matching/matches.rb
|
99
|
+
- lib/fakes/arg_matching/regular_arg_matcher.rb
|
100
|
+
- lib/fakes/arg_set.rb
|
101
|
+
- lib/fakes/class_swap.rb
|
102
|
+
- lib/fakes/class_swaps.rb
|
103
|
+
- lib/fakes/fake.rb
|
104
|
+
- lib/fakes/fakes.rb
|
105
|
+
- lib/fakes/ignore_set.rb
|
106
|
+
- lib/fakes/method_stub.rb
|
107
|
+
- lib/fakes/version.rb
|
124
108
|
- spec/spec_helper.rb
|
125
109
|
- spec/specs/arg_behaviour_spec.rb
|
126
110
|
- spec/specs/arg_match_factory_spec.rb
|
@@ -148,12 +132,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
132
|
- - ! '>='
|
149
133
|
- !ruby/object:Gem::Version
|
150
134
|
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: 653969968274365850
|
151
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
139
|
none: false
|
153
140
|
requirements:
|
154
141
|
- - ! '>='
|
155
142
|
- !ruby/object:Gem::Version
|
156
143
|
version: '0'
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
hash: 653969968274365850
|
157
147
|
requirements: []
|
158
148
|
rubyforge_project: fakes
|
159
149
|
rubygems_version: 1.8.25
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm 1.9.3@fakes --create
|
data/lib/core/version.rb
DELETED