fakes-rspec 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fakes-rspec.gemspec +1 -1
- data/lib/fakes-rspec.rb +1 -1
- data/lib/fakes_rspec/matcher.rb +10 -3
- data/lib/fakes_rspec/version.rb +1 -1
- data/spec/specs/block_criteria_spec.rb +2 -2
- data/spec/specs/nullo_specification_spec.rb +3 -1
- data/spec/specs/occurrences_spec.rb +9 -9
- data/spec/specs/received_criteria_spec.rb +4 -4
- data/spec/specs/received_occurrences_criteria_spec.rb +8 -6
- data/spec/specs/usage_spec.rb +31 -27
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f15ab9ad7b838efacecdedd5a966423ddb09a82
|
4
|
+
data.tar.gz: a8d59a776ec88595fbb4f4cb448a724889f1718b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cae4c7c2d2c104289e5d920cf4ed790f0c2dac928d73b09494b4b18017e8ec70a3ec5d249bb18a19fe9f412aa6174f3ce7bdcd245194e82e14e5ef3b291ec66
|
7
|
+
data.tar.gz: 03f256c31540a8f82eccbe2a08b468ecd01958b00f10553ffb8e6c5a4f4dbd544ce8c1f1c7c64c883390359b4115dc877c66673b32a4b737f804768046487f3e
|
data/fakes-rspec.gemspec
CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency('guard', "~> 2.6.1")
|
23
23
|
s.add_development_dependency('guard-rspec', "~> 4.2.9")
|
24
24
|
s.add_runtime_dependency('fakes', "~> 1.1.4")
|
25
|
-
s.add_runtime_dependency('rspec', "~>
|
25
|
+
s.add_runtime_dependency('rspec', "~> 3.0")
|
26
26
|
end
|
data/lib/fakes-rspec.rb
CHANGED
@@ -3,11 +3,11 @@ require 'rspec'
|
|
3
3
|
require 'singleton'
|
4
4
|
|
5
5
|
require 'fakes_rspec/block_criteria'
|
6
|
-
require 'fakes_rspec/matcher'
|
7
6
|
require 'fakes_rspec/nullo_specification'
|
8
7
|
require 'fakes_rspec/occurrences'
|
9
8
|
require 'fakes_rspec/received_occurrences_criteria'
|
10
9
|
require 'fakes_rspec/received_criteria'
|
10
|
+
require 'fakes_rspec/matcher'
|
11
11
|
|
12
12
|
RSpec.configure do |config|
|
13
13
|
config.after(:each) do
|
data/lib/fakes_rspec/matcher.rb
CHANGED
@@ -2,10 +2,14 @@ module RSpec
|
|
2
2
|
def self.create_received_criteria_from(the_call)
|
3
3
|
return Fakes::RSpec::ReceivedCriteria.new(the_call)
|
4
4
|
end
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
def self.create_received_occurences_criteria_from(the_call, occurence)
|
7
|
+
occurence_spec = occurence.nil? ? Fakes::RSpec::NulloSpecification.instance : occurence
|
8
|
+
|
9
|
+
return Fakes::RSpec::ReceivedOccurrencesCriteria.new(create_received_criteria_from(the_call),the_call,occurence_spec)
|
7
10
|
end
|
8
11
|
|
12
|
+
|
9
13
|
Matchers.define :have_received_message do|symbol,*args|
|
10
14
|
@occurence_spec = Fakes::RSpec::NulloSpecification.instance
|
11
15
|
|
@@ -39,8 +43,11 @@ module RSpec
|
|
39
43
|
chain :occurs do|the_proc|
|
40
44
|
@occurence_spec = Fakes::RSpec::Occurrences.from_block(the_proc)
|
41
45
|
end
|
46
|
+
|
42
47
|
match do|the_fake|
|
43
|
-
RSpec.create_received_occurences_criteria_from(the_fake.received(symbol),@occurence_spec)
|
48
|
+
criteria = RSpec.create_received_occurences_criteria_from(the_fake.received(symbol),@occurence_spec)
|
49
|
+
|
50
|
+
criteria.is_satisfied_by(*args)
|
44
51
|
end
|
45
52
|
end
|
46
53
|
end
|
data/lib/fakes_rspec/version.rb
CHANGED
@@ -6,8 +6,8 @@ module Fakes
|
|
6
6
|
context "when matching" do
|
7
7
|
subject{BlockCriteria.new(lambda{|item| return item == 1})}
|
8
8
|
it "should match if its block returns true" do
|
9
|
-
subject.is_satisfied_by(1).
|
10
|
-
subject.is_satisfied_by(2).
|
9
|
+
expect(subject.is_satisfied_by(1)).to be_truthy
|
10
|
+
expect(subject.is_satisfied_by(2)).to be_falsy
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -6,7 +6,9 @@ module Fakes
|
|
6
6
|
subject{NulloSpecification.instance}
|
7
7
|
|
8
8
|
it "should be satisfied by anything" do
|
9
|
-
[1,10,"a",Object.new].each
|
9
|
+
[1,10,"a",Object.new].each do |item|
|
10
|
+
expect(subject.is_satisfied_by(item)).to be_truthy
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -7,8 +7,8 @@ module Fakes
|
|
7
7
|
subject{Occurrences.exact(1)}
|
8
8
|
|
9
9
|
it "should create a matcher that matches an exact number of occurrences" do
|
10
|
-
subject.is_satisfied_by(1).
|
11
|
-
subject.is_satisfied_by(2).
|
10
|
+
expect(subject.is_satisfied_by(1)).to be_truthy
|
11
|
+
expect(subject.is_satisfied_by(2)).to be_falsy
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -16,19 +16,19 @@ module Fakes
|
|
16
16
|
subject{Occurrences.at_least(3)}
|
17
17
|
|
18
18
|
it "should create a matcher that matches an exact number of occurrences" do
|
19
|
-
subject.is_satisfied_by(3).
|
20
|
-
subject.is_satisfied_by(4).
|
21
|
-
subject.is_satisfied_by(2).
|
19
|
+
expect(subject.is_satisfied_by(3)).to be_truthy
|
20
|
+
expect(subject.is_satisfied_by(4)).to be_truthy
|
21
|
+
expect(subject.is_satisfied_by(2)).to be_falsy
|
22
22
|
end
|
23
23
|
end
|
24
24
|
context "when creating an at most occurrence matcher" do
|
25
25
|
subject{Occurrences.at_most(3)}
|
26
26
|
|
27
27
|
it "should create a matcher that matches an exact number of occurrences" do
|
28
|
-
subject.is_satisfied_by(3).
|
29
|
-
subject.is_satisfied_by(2).
|
30
|
-
subject.is_satisfied_by(1).
|
31
|
-
subject.is_satisfied_by(4).
|
28
|
+
expect(subject.is_satisfied_by(3)).to be_truthy
|
29
|
+
expect(subject.is_satisfied_by(2)).to be_truthy
|
30
|
+
expect(subject.is_satisfied_by(1)).to be_truthy
|
31
|
+
expect(subject.is_satisfied_by(4)).to be_falsy
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -10,7 +10,7 @@ module Fakes
|
|
10
10
|
|
11
11
|
sut = ReceivedCriteria.new(item.received(:hello))
|
12
12
|
|
13
|
-
sut.is_satisfied_by.
|
13
|
+
expect(sut.is_satisfied_by).to be_truthy
|
14
14
|
end
|
15
15
|
end
|
16
16
|
context "when matching a call made with arguments" do
|
@@ -21,16 +21,16 @@ module Fakes
|
|
21
21
|
end
|
22
22
|
context "and we care about the arguments it was called with" do
|
23
23
|
it "should match if it received the correct call" do
|
24
|
-
@sut.is_satisfied_by("world").
|
24
|
+
expect(@sut.is_satisfied_by("world")).to be_truthy
|
25
25
|
end
|
26
26
|
it "should not match if the arguments provided are not in the call history" do
|
27
|
-
@sut.is_satisfied_by("yo").
|
27
|
+
expect(@sut.is_satisfied_by("yo")).to be_falsy
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
31
31
|
context "and we don't care about the arguments it was called with" do
|
32
32
|
it "should match if it received a call to the method" do
|
33
|
-
@sut.is_satisfied_by.
|
33
|
+
expect(@sut.is_satisfied_by).to be_truthy
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -8,18 +8,20 @@ module Fakes
|
|
8
8
|
let(:the_call){fake}
|
9
9
|
let(:arg_set){fake}
|
10
10
|
let(:the_arg){1}
|
11
|
+
|
11
12
|
subject{ReceivedOccurrencesCriteria.new(original,the_call,occurrence)}
|
13
|
+
|
12
14
|
context "when matching a call made" do
|
13
15
|
context "and the original criteria is not satisfied" do
|
14
16
|
before (:each) do
|
15
17
|
original.stub(:is_satisfied_by).with(the_arg).and_return(false)
|
16
18
|
end
|
17
19
|
it "should not match" do
|
18
|
-
subject.is_satisfied_by(the_arg).
|
20
|
+
expect(subject.is_satisfied_by(the_arg)).to be_falsy
|
19
21
|
end
|
20
22
|
it "should not use the occurrence or the call" do
|
21
|
-
occurrence.
|
22
|
-
the_call.
|
23
|
+
expect(occurrence.received?(:is_satisfied_by)).to be_falsy
|
24
|
+
expect(the_call.received?(:called_with)).to be_falsy
|
23
25
|
end
|
24
26
|
end
|
25
27
|
context "and the original criteria is satisfied" do
|
@@ -38,7 +40,7 @@ module Fakes
|
|
38
40
|
@result = subject.is_satisfied_by
|
39
41
|
end
|
40
42
|
it "should match if the occurrence matches the total number of invocations" do
|
41
|
-
@result.
|
43
|
+
expect(@result).to be_truthy
|
42
44
|
end
|
43
45
|
end
|
44
46
|
context "and its occurrence is satisfied" do
|
@@ -46,7 +48,7 @@ module Fakes
|
|
46
48
|
occurrence.stub(:is_satisfied_by).with(1).and_return(true)
|
47
49
|
end
|
48
50
|
it "should match" do
|
49
|
-
subject.is_satisfied_by(the_arg).
|
51
|
+
expect(subject.is_satisfied_by(the_arg)).to be_truthy
|
50
52
|
end
|
51
53
|
end
|
52
54
|
context "and its occurrence is not satisfied" do
|
@@ -54,7 +56,7 @@ module Fakes
|
|
54
56
|
occurrence.stub(:is_satisfied_by).with(1).and_return(false)
|
55
57
|
end
|
56
58
|
it "should not match" do
|
57
|
-
subject.is_satisfied_by(the_arg).
|
59
|
+
expect(subject.is_satisfied_by(the_arg)).to be_falsy
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
data/spec/specs/usage_spec.rb
CHANGED
@@ -6,11 +6,13 @@ describe "using the rspec extensions" do
|
|
6
6
|
item.hello
|
7
7
|
item.last("other")
|
8
8
|
|
9
|
-
item.
|
10
|
-
item.
|
11
|
-
item.
|
12
|
-
item.
|
13
|
-
item.
|
9
|
+
expect(item).to_not have_received_message(:hello, "world")
|
10
|
+
expect(item).to have_received_message(:hello)
|
11
|
+
expect(item).to_not have_received_message(:hello,"world")
|
12
|
+
expect(item).to have_received_message(:hello)
|
13
|
+
expect(item).to_not have_received_message(:once_more)
|
14
|
+
expect(item).to_not have_received_message(:last,"hello")
|
15
|
+
expect(item).to have_received_message(:last,"other")
|
14
16
|
end
|
15
17
|
|
16
18
|
it "should be able to determine if a call has been made a certain number of times" do
|
@@ -19,20 +21,22 @@ describe "using the rspec extensions" do
|
|
19
21
|
item.hello
|
20
22
|
item.last("other")
|
21
23
|
|
22
|
-
|
23
|
-
item.
|
24
|
-
item.
|
25
|
-
item.
|
26
|
-
item.
|
27
|
-
item.
|
28
|
-
item.
|
24
|
+
|
25
|
+
expect(item).to_not have_received_message(:hello,"world")
|
26
|
+
expect(item).to_not have_received_message(:hello,"world")
|
27
|
+
expect(item).to have_received_message(:hello).twice
|
28
|
+
expect(item).to have_received_message(:hello)
|
29
|
+
expect(item).to_not have_received_message(:once_more)
|
30
|
+
expect(item).to_not have_received_message(:last,"hello")
|
31
|
+
expect(item).to have_received_message(:last,"other").once
|
32
|
+
expect(item).to_not have_received_message(:last).twice
|
29
33
|
end
|
30
34
|
|
31
35
|
it "should be able to determine if a call was made once" do
|
32
36
|
item = fake
|
33
37
|
item.hello
|
34
38
|
|
35
|
-
item.
|
39
|
+
expect(item).to have_received_message(:hello).once
|
36
40
|
end
|
37
41
|
|
38
42
|
it "should be able to determine if a call was made twice" do
|
@@ -40,7 +44,7 @@ describe "using the rspec extensions" do
|
|
40
44
|
item.hello
|
41
45
|
item.hello
|
42
46
|
|
43
|
-
item.
|
47
|
+
expect(item).to have_received_message(:hello).twice
|
44
48
|
end
|
45
49
|
|
46
50
|
it "should be able to determine if a call was made at least once" do
|
@@ -48,7 +52,7 @@ describe "using the rspec extensions" do
|
|
48
52
|
item.hello
|
49
53
|
item.hello
|
50
54
|
|
51
|
-
item.
|
55
|
+
expect(item).to have_received_message(:hello).at_least_once
|
52
56
|
end
|
53
57
|
|
54
58
|
it "should be able to determine if a call was made at least twice" do
|
@@ -57,8 +61,8 @@ describe "using the rspec extensions" do
|
|
57
61
|
item.hello
|
58
62
|
item.hello
|
59
63
|
|
60
|
-
item.
|
61
|
-
item.
|
64
|
+
expect(item).to have_received_message(:hello).at_least_twice
|
65
|
+
expect(item).to have_received_message(:hello).at_least_twice
|
62
66
|
end
|
63
67
|
|
64
68
|
|
@@ -68,8 +72,8 @@ describe "using the rspec extensions" do
|
|
68
72
|
item.goodbye
|
69
73
|
item.goodbye
|
70
74
|
|
71
|
-
item.
|
72
|
-
item.
|
75
|
+
expect(item).to have_received_message(:hello).at_most_once
|
76
|
+
expect(item).to_not have_received_message(:goodbye).at_most_once
|
73
77
|
end
|
74
78
|
|
75
79
|
it "should be able to determine if a call was made at most twice" do
|
@@ -79,8 +83,8 @@ describe "using the rspec extensions" do
|
|
79
83
|
item.goodbye
|
80
84
|
item.goodbye
|
81
85
|
|
82
|
-
item.
|
83
|
-
item.
|
86
|
+
expect(item).to have_received_message(:hello).at_most_twice
|
87
|
+
expect(item).to_not have_received_message(:goodbye).at_most_twice
|
84
88
|
end
|
85
89
|
|
86
90
|
it "should be able to determine if a call was made at least a specified number of times" do
|
@@ -90,22 +94,22 @@ describe "using the rspec extensions" do
|
|
90
94
|
item.goodbye
|
91
95
|
item.goodbye
|
92
96
|
|
93
|
-
item.
|
94
|
-
item.
|
97
|
+
expect(item).to have_received_message(:hello).at_most(1)
|
98
|
+
expect(item).to_not have_received_message(:goodbye).at_most(1)
|
95
99
|
end
|
96
100
|
context "using the arg matching style" do
|
97
101
|
it "should be able to determing if a call was made using arg matchers" do
|
98
102
|
item = fake
|
99
103
|
item.hello("Yes")
|
100
104
|
|
101
|
-
item.
|
105
|
+
expect(item).to have_received_message(:hello,arg_match.any)
|
102
106
|
end
|
103
107
|
|
104
108
|
it "should be able to determing if a call was made using a combination of arg matchers and explicit values" do
|
105
109
|
item = fake
|
106
110
|
item.hello("Yes",2)
|
107
111
|
|
108
|
-
item.
|
112
|
+
expect(item).to have_received_message(:hello,arg_match.regex(/Y/),2)
|
109
113
|
end
|
110
114
|
end
|
111
115
|
context "using class swapping" do
|
@@ -114,14 +118,14 @@ describe "using the rspec extensions" do
|
|
114
118
|
|
115
119
|
Dir.stub(:exist?).and_return false
|
116
120
|
|
117
|
-
Dir.exist('/').
|
121
|
+
expect(Dir.exist('/')).to be_falsy
|
118
122
|
end
|
119
123
|
|
120
124
|
it "should be able to determing if a call was made using a combination of arg matchers and explicit values" do
|
121
125
|
item = fake
|
122
126
|
item.hello("Yes",2)
|
123
127
|
|
124
|
-
item.
|
128
|
+
expect(item).to have_received_message(:hello,arg_match.regex(/Y/),2)
|
125
129
|
end
|
126
130
|
end
|
127
131
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakes-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Develop With Passion®
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '3.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '3.0'
|
83
83
|
description: Faking library that allows inspection of received calls after they have
|
84
84
|
been made. Also supports tracking calls with multiple argument sets.
|
85
85
|
email:
|