developwithpassion_fakes-rspec 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/core/block_criteria.rb +14 -0
- data/lib/core/example_group.rb +33 -0
- data/lib/core/occurances.rb +22 -0
- data/lib/core/received_criteria.rb +1 -1
- data/lib/core/received_occurances_criteria.rb +18 -0
- data/lib/core/rspec_utils.rb +14 -1
- data/lib/core/version.rb +1 -1
- data/spec/specs/block_criteria_spec.rb +17 -0
- data/spec/specs/example_group_specs.rb +33 -0
- data/spec/specs/occurances_spec.rb +38 -0
- data/spec/specs/received_criteria_spec.rb +4 -4
- data/spec/specs/received_occurences_criteria_spec.rb +66 -0
- data/spec/specs/usage_spec.rb +15 -0
- metadata +25 -13
@@ -0,0 +1,14 @@
|
|
1
|
+
module DevelopWithPassion
|
2
|
+
module Fakes
|
3
|
+
module RSpec
|
4
|
+
class BlockCriteria
|
5
|
+
def initialize(condition_block)
|
6
|
+
@condition_block = condition_block
|
7
|
+
end
|
8
|
+
def is_satisfied_by(item)
|
9
|
+
return @condition_block.call(item)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
class ExampleGroup
|
4
|
+
def once
|
5
|
+
return DevelopWithPassion::Fakes::RSpec::Occurances.exact(1)
|
6
|
+
end
|
7
|
+
def twice
|
8
|
+
return DevelopWithPassion::Fakes::RSpec::Occurances.exact(2)
|
9
|
+
end
|
10
|
+
def at_least_once
|
11
|
+
return DevelopWithPassion::Fakes::RSpec::Occurances.at_least(1)
|
12
|
+
end
|
13
|
+
def at_least_twice
|
14
|
+
return DevelopWithPassion::Fakes::RSpec::Occurances.at_least(2)
|
15
|
+
end
|
16
|
+
def at_most_once
|
17
|
+
return DevelopWithPassion::Fakes::RSpec::Occurances.at_most(1)
|
18
|
+
end
|
19
|
+
def at_most_twice
|
20
|
+
return DevelopWithPassion::Fakes::RSpec::Occurances.at_most(2)
|
21
|
+
end
|
22
|
+
def at_least(times)
|
23
|
+
return DevelopWithPassion::Fakes::RSpec::Occurances.at_least(times)
|
24
|
+
end
|
25
|
+
def at_most(times)
|
26
|
+
return DevelopWithPassion::Fakes::RSpec::Occurances.at_most(times)
|
27
|
+
end
|
28
|
+
def exactly(times)
|
29
|
+
return DevelopWithPassion::Fakes::RSpec::Occurances.exact(times)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module DevelopWithPassion
|
2
|
+
module Fakes
|
3
|
+
module RSpec
|
4
|
+
class Occurances
|
5
|
+
class << self
|
6
|
+
def from_block(the_block)
|
7
|
+
return BlockCriteria.new(the_block)
|
8
|
+
end
|
9
|
+
def exact(times)
|
10
|
+
return from_block(lambda{|occurances| return occurances == times})
|
11
|
+
end
|
12
|
+
def at_least(times)
|
13
|
+
return from_block(lambda { |occurences| return occurences >= times})
|
14
|
+
end
|
15
|
+
def at_most(times)
|
16
|
+
return from_block(lambda { |occurences| return occurences <= times})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module DevelopWithPassion
|
2
|
+
module Fakes
|
3
|
+
module RSpec
|
4
|
+
class ReceivedOccurencesCriteria
|
5
|
+
def initialize(received_criteria,the_call,occurence)
|
6
|
+
@received_criteria = received_criteria
|
7
|
+
@the_call = the_call
|
8
|
+
@occurence = occurence
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_satisfied_by(*args)
|
12
|
+
return @received_criteria.is_satisfied_by(*args) &&
|
13
|
+
@occurence.is_satisfied_by((args.count == 0 ? @the_call.total_times_called : @the_call.called_with(*args).times_called))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/core/rspec_utils.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
module RSpec
|
2
|
+
def self.create_received_criteria_from(the_call)
|
3
|
+
return DevelopWithPassion::Fakes::RSpec::ReceivedCriteria.new(the_call)
|
4
|
+
end
|
5
|
+
def self.create_received_occurences_criteria_from(the_call,occurence)
|
6
|
+
return DevelopWithPassion::Fakes::RSpec::ReceivedOccurencesCriteria.new(create_received_criteria_from(the_call),the_call,occurence)
|
7
|
+
end
|
8
|
+
|
2
9
|
Matchers.define :have_received do|symbol,*args|
|
3
10
|
match do|the_fake|
|
4
|
-
|
11
|
+
RSpec.create_received_criteria_from(the_fake.received(symbol)).is_satisfied_by(*args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
Matchers.define :have_received_occurences do|occurence,symbol,*args|
|
15
|
+
match do|the_fake|
|
16
|
+
RSpec.create_received_occurences_criteria_from(the_fake.received(symbol),occurence).is_satisfied_by(*args)
|
5
17
|
end
|
6
18
|
end
|
19
|
+
|
7
20
|
end
|
data/lib/core/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DevelopWithPassion
|
4
|
+
module Fakes
|
5
|
+
module RSpec
|
6
|
+
describe BlockCriteria do
|
7
|
+
context "when matching" do
|
8
|
+
subject{BlockCriteria.new(lambda{|item| return item == 1})}
|
9
|
+
it "should match if its block returns true" do
|
10
|
+
subject.is_satisfied_by(1).should be_true
|
11
|
+
subject.is_satisfied_by(2).should be_false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Core
|
5
|
+
describe ExampleGroup do
|
6
|
+
context "when creating occurence matchers" do
|
7
|
+
it "should be able to create matchers correctly" do
|
8
|
+
once.is_satisfied_by(1).should be_true
|
9
|
+
once.is_satisfied_by(2).should be_false
|
10
|
+
|
11
|
+
twice.is_satisfied_by(2).should be_true
|
12
|
+
twice.is_satisfied_by(1).should be_false
|
13
|
+
|
14
|
+
at_least_once.is_satisfied_by(1).should be_true
|
15
|
+
at_least_once.is_satisfied_by(2).should be_true
|
16
|
+
at_least_once.is_satisfied_by(0).should be_false
|
17
|
+
|
18
|
+
at_least_twice.is_satisfied_by(2).should be_true
|
19
|
+
at_least_twice.is_satisfied_by(3).should be_true
|
20
|
+
at_least_twice.is_satisfied_by(0).should be_false
|
21
|
+
|
22
|
+
at_most_once.is_satisfied_by(1).should be_true
|
23
|
+
at_most_once.is_satisfied_by(2).should be_false
|
24
|
+
at_most_once.is_satisfied_by(0).should be_true
|
25
|
+
|
26
|
+
at_most_twice.is_satisfied_by(2).should be_true
|
27
|
+
at_most_twice.is_satisfied_by(3).should be_false
|
28
|
+
at_most_twice.is_satisfied_by(0).should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DevelopWithPassion
|
4
|
+
module Fakes
|
5
|
+
module RSpec
|
6
|
+
describe Occurances do
|
7
|
+
context "when creating an exact occurance matcher" do
|
8
|
+
subject{Occurances.exact(1)}
|
9
|
+
|
10
|
+
it "should create a matcher that matches an exact number of occurances" do
|
11
|
+
subject.is_satisfied_by(1).should be_true
|
12
|
+
subject.is_satisfied_by(2).should be_false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when creating an at least occurance matcher" do
|
17
|
+
subject{Occurances.at_least(3)}
|
18
|
+
|
19
|
+
it "should create a matcher that matches an exact number of occurances" do
|
20
|
+
subject.is_satisfied_by(3).should be_true
|
21
|
+
subject.is_satisfied_by(4).should be_true
|
22
|
+
subject.is_satisfied_by(2).should be_false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context "when creating an at most occurance matcher" do
|
26
|
+
subject{Occurances.at_most(3)}
|
27
|
+
|
28
|
+
it "should create a matcher that matches an exact number of occurances" do
|
29
|
+
subject.is_satisfied_by(3).should be_true
|
30
|
+
subject.is_satisfied_by(2).should be_true
|
31
|
+
subject.is_satisfied_by(1).should be_true
|
32
|
+
subject.is_satisfied_by(4).should be_false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -11,7 +11,7 @@ module DevelopWithPassion
|
|
11
11
|
|
12
12
|
sut = ReceivedCriteria.new(item.received(:hello))
|
13
13
|
|
14
|
-
sut.
|
14
|
+
sut.is_satisfied_by.should be_true
|
15
15
|
end
|
16
16
|
end
|
17
17
|
context "when matching a call made with arguments" do
|
@@ -22,16 +22,16 @@ module DevelopWithPassion
|
|
22
22
|
end
|
23
23
|
context "and we care about the arguments it was called with" do
|
24
24
|
it "should match if it received the correct call" do
|
25
|
-
@sut.
|
25
|
+
@sut.is_satisfied_by("world").should be_true
|
26
26
|
end
|
27
27
|
it "should not match if the arguments provided are not in the call history" do
|
28
|
-
@sut.
|
28
|
+
@sut.is_satisfied_by("yo").should be_false
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
32
32
|
context "and we don't care about the arguments it was called with" do
|
33
33
|
it "should match if it received a call to the method" do
|
34
|
-
@sut.
|
34
|
+
@sut.is_satisfied_by.should be_true
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DevelopWithPassion
|
4
|
+
module Fakes
|
5
|
+
module RSpec
|
6
|
+
describe ReceivedOccurencesCriteria do
|
7
|
+
let(:original){fake}
|
8
|
+
let(:occurence){fake}
|
9
|
+
let(:the_call){fake}
|
10
|
+
let(:arg_set){fake}
|
11
|
+
let(:the_arg){1}
|
12
|
+
subject{ReceivedOccurencesCriteria.new(original,the_call,occurence)}
|
13
|
+
context "when matching a call made" do
|
14
|
+
context "and the original criteria is not satisfied" do
|
15
|
+
before (:each) do
|
16
|
+
original.stub(:is_satisfied_by).with(the_arg).and_return(false)
|
17
|
+
end
|
18
|
+
it "should not match" do
|
19
|
+
subject.is_satisfied_by(the_arg).should be_false
|
20
|
+
end
|
21
|
+
it "should not use the occurence or the call" do
|
22
|
+
occurence.should_not have_received(:is_satified_by)
|
23
|
+
the_call.should_not have_received(:called_with)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context "and the original criteria is satisfied" do
|
27
|
+
before (:each) do
|
28
|
+
original.stub(:is_satisfied_by).with(the_arg).and_return(true)
|
29
|
+
the_call.stub(:called_with).with(the_arg).and_return(arg_set)
|
30
|
+
arg_set.stub(:times_called).and_return(1)
|
31
|
+
end
|
32
|
+
context "and no arguments were provided to the call" do
|
33
|
+
before (:each) do
|
34
|
+
original.stub(:is_satisfied_by).and_return(true)
|
35
|
+
the_call.stub(:total_times_called).and_return(1)
|
36
|
+
occurence.stub(:is_satisfied_by).with(1).and_return(true)
|
37
|
+
end
|
38
|
+
before (:each) do
|
39
|
+
@result = subject.is_satisfied_by
|
40
|
+
end
|
41
|
+
it "should match if the occurence matches the total number of invocations" do
|
42
|
+
@result.should be_true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context "and its occurence is satisfied" do
|
46
|
+
before (:each) do
|
47
|
+
occurence.stub(:is_satisfied_by).with(1).and_return(true)
|
48
|
+
end
|
49
|
+
it "should match" do
|
50
|
+
subject.is_satisfied_by(the_arg).should be_true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
context "and its occurence is not satisfied" do
|
54
|
+
before (:each) do
|
55
|
+
occurence.stub(:is_satisfied_by).with(1).and_return(false)
|
56
|
+
end
|
57
|
+
it "should not match" do
|
58
|
+
subject.is_satisfied_by(the_arg).should be_false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/specs/usage_spec.rb
CHANGED
@@ -12,5 +12,20 @@ describe "using the rspec extensions" do
|
|
12
12
|
item.should_not have_received(:last,"hello")
|
13
13
|
item.should have_received(:last,"other")
|
14
14
|
end
|
15
|
+
|
16
|
+
it "should be able to determine if a call has been made a certain number of times" do
|
17
|
+
item = fake
|
18
|
+
item.hello
|
19
|
+
item.hello
|
20
|
+
item.last("other")
|
21
|
+
|
22
|
+
item.should_not have_received(:hello,"world")
|
23
|
+
item.should have_received_occurences(twice,:hello)
|
24
|
+
item.should have_received(:hello)
|
25
|
+
item.should_not have_received(:once_more)
|
26
|
+
item.should_not have_received(:last,"hello")
|
27
|
+
item.should have_received_occurences(once,:last,"other")
|
28
|
+
item.should_not have_received_occurences(twice,:last)
|
29
|
+
end
|
15
30
|
end
|
16
31
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: developwithpassion_fakes-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-27 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70243008316300 !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: *70243008316300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: guard
|
27
|
-
requirement: &
|
27
|
+
requirement: &70243008315720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70243008315720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: guard-rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70243008315200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70243008315200
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70243008314500 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70243008314500
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: developwithpassion_fakes
|
60
|
-
requirement: &
|
60
|
+
requirement: &70243008313700 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70243008313700
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70243008313120 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70243008313120
|
80
80
|
description: Faking library that allows inspection of received calls after they have
|
81
81
|
been made. Also supports tracking calls with multiple argument sets.
|
82
82
|
email:
|
@@ -86,12 +86,20 @@ extensions: []
|
|
86
86
|
extra_rdoc_files: []
|
87
87
|
files:
|
88
88
|
- developwithpassion_fakes-rspec.gemspec
|
89
|
+
- lib/core/block_criteria.rb
|
90
|
+
- lib/core/example_group.rb
|
91
|
+
- lib/core/occurances.rb
|
89
92
|
- lib/core/received_criteria.rb
|
93
|
+
- lib/core/received_occurances_criteria.rb
|
90
94
|
- lib/core/rspec_utils.rb
|
91
95
|
- lib/core/version.rb
|
92
96
|
- lib/developwithpassion_fakes-rspec.rb
|
93
97
|
- spec/spec_helper.rb
|
98
|
+
- spec/specs/block_criteria_spec.rb
|
99
|
+
- spec/specs/example_group_specs.rb
|
100
|
+
- spec/specs/occurances_spec.rb
|
94
101
|
- spec/specs/received_criteria_spec.rb
|
102
|
+
- spec/specs/received_occurences_criteria_spec.rb
|
95
103
|
- spec/specs/usage_spec.rb
|
96
104
|
homepage: http://www.developwithpassion.com
|
97
105
|
licenses: []
|
@@ -119,5 +127,9 @@ specification_version: 3
|
|
119
127
|
summary: Utility functions for develowithpassion_fakes when working with rSpec
|
120
128
|
test_files:
|
121
129
|
- spec/spec_helper.rb
|
130
|
+
- spec/specs/block_criteria_spec.rb
|
131
|
+
- spec/specs/example_group_specs.rb
|
132
|
+
- spec/specs/occurances_spec.rb
|
122
133
|
- spec/specs/received_criteria_spec.rb
|
134
|
+
- spec/specs/received_occurences_criteria_spec.rb
|
123
135
|
- spec/specs/usage_spec.rb
|