fakes 1.1.4 → 1.1.5
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.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/fakes.gemspec +1 -1
- data/lib/fakes/arg_behaviour.rb +11 -3
- data/lib/fakes/version.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- data/spec/specs/arg_behaviour_spec.rb +43 -22
- data/spec/specs/arg_match_factory_spec.rb +5 -4
- data/spec/specs/arg_matching_scenarios_spec.rb +9 -9
- data/spec/specs/arg_set_spec.rb +1 -1
- data/spec/specs/argument_matching_spec.rb +15 -15
- data/spec/specs/block_arg_matcher_spec.rb +1 -1
- data/spec/specs/class_swap_spec.rb +7 -7
- data/spec/specs/class_swaps_spec.rb +12 -12
- data/spec/specs/combined_arg_matcher_spec.rb +2 -2
- data/spec/specs/extensions_spec.rb +6 -6
- data/spec/specs/fake_spec.rb +39 -39
- data/spec/specs/ignore_set_spec.rb +5 -5
- data/spec/specs/method_stub_spec.rb +15 -15
- data/spec/specs/regular_arg_matcher_spec.rb +2 -2
- metadata +19 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f8441cd15f6f7f9ce06a62e3ea07f8be22bd185b
|
4
|
+
data.tar.gz: e62db5cbbb80694e4bc1f726ffb7ab8993081b7e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc46b7bc3f7a00f8cd364566f8459dce3f2c8d56cc1cadeb574cfe51d9c51bac648cd939902016349298ea36dc922bb38177c224d34e6b9e7036ad2e27c3e226
|
7
|
+
data.tar.gz: 8512462e38329c2dbafafdd9a15fbe8469642d424de49705e2c43480fac3b93f4391e48b3cb5275d3b0bce657a2ec495e0a8dfff3a3b086141d93d7226476637
|
data/Gemfile
CHANGED
data/fakes.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
s.
|
20
|
+
s.add_runtime_dependency('rspec', "~> 2.14.1")
|
21
21
|
s.add_development_dependency "rake"
|
22
22
|
s.add_development_dependency "guard"
|
23
23
|
s.add_development_dependency "guard-rspec"
|
data/lib/fakes/arg_behaviour.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Fakes
|
2
2
|
module ArgBehaviour
|
3
3
|
attr_accessor :return_value,:times_called,:arg_matcher
|
4
|
+
attr_reader :callback_block
|
4
5
|
|
5
6
|
def initialize_matcher_using(args)
|
6
7
|
@arg_matcher = ArgMatchFactory.create_arg_matcher_using(args)
|
@@ -15,10 +16,15 @@ module Fakes
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def capture_args(args)
|
19
|
+
@arguments_provided = true
|
18
20
|
@times_called += 1
|
19
21
|
@called_args = args
|
20
22
|
end
|
21
23
|
|
24
|
+
def run(&callback_block)
|
25
|
+
@callback_block = callback_block
|
26
|
+
end
|
27
|
+
|
22
28
|
def matches?(args)
|
23
29
|
return @arg_matcher.matches?(args)
|
24
30
|
end
|
@@ -28,9 +34,11 @@ module Fakes
|
|
28
34
|
end
|
29
35
|
|
30
36
|
def process
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
if callback_block
|
38
|
+
@arguments_provided ? callback_block.call(*@called_args) : callback_block.call
|
39
|
+
else
|
40
|
+
raise @exception if @exception
|
41
|
+
@return_value
|
34
42
|
end
|
35
43
|
end
|
36
44
|
end
|
data/lib/fakes/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -13,25 +13,46 @@ module Fakes
|
|
13
13
|
before (:each) do
|
14
14
|
sut.send(:extend,ArgBehaviour)
|
15
15
|
end
|
16
|
+
|
16
17
|
context "when continuing its execution" do
|
17
|
-
context
|
18
|
-
|
19
|
-
|
18
|
+
context 'and it has not been given a block to return' do
|
19
|
+
context "and no exception has been specified to be thrown" do
|
20
|
+
before (:each) do
|
21
|
+
sut.and_return(2)
|
22
|
+
end
|
23
|
+
it "should store the return value to be returned during invocation" do
|
24
|
+
expect(sut.process()).to eql(2)
|
25
|
+
end
|
20
26
|
end
|
21
|
-
|
22
|
-
|
27
|
+
context "and an exception has been specified to be thrown" do
|
28
|
+
let(:exception){Exception.new}
|
29
|
+
before (:each) do
|
30
|
+
sut.throws(exception)
|
31
|
+
end
|
32
|
+
it "should throw the exception" do
|
33
|
+
begin
|
34
|
+
sut.process()
|
35
|
+
rescue Exception => e
|
36
|
+
expect(e).to eql(exception)
|
37
|
+
end
|
38
|
+
end
|
23
39
|
end
|
24
40
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
sut.
|
33
|
-
|
34
|
-
|
41
|
+
|
42
|
+
context 'and it has been given a block to return' do
|
43
|
+
context "and no exception has been specified to be thrown" do
|
44
|
+
let(:name) { 'JP' }
|
45
|
+
|
46
|
+
before (:each) do
|
47
|
+
sut.capture_args([name])
|
48
|
+
sut.run do |the_name|
|
49
|
+
expect(the_name).to eql(name)
|
50
|
+
2
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should invoke the block with the arguments passed in, and return the value" do
|
55
|
+
expect(sut.process).to eql(2)
|
35
56
|
end
|
36
57
|
end
|
37
58
|
end
|
@@ -42,13 +63,13 @@ module Fakes
|
|
42
63
|
sut.capture_args(2)
|
43
64
|
end
|
44
65
|
it "should increment the number of times it was called" do
|
45
|
-
sut.times_called.
|
66
|
+
expect(sut.times_called).to eql(1)
|
46
67
|
end
|
47
68
|
it "should store the arguments it was called with" do
|
48
|
-
sut.called_args.
|
69
|
+
expect(sut.called_args).to eql(2)
|
49
70
|
end
|
50
71
|
end
|
51
|
-
|
72
|
+
|
52
73
|
context "when matching a set of arguments" do
|
53
74
|
let(:matcher){Object.new}
|
54
75
|
before (:each) do
|
@@ -58,8 +79,8 @@ module Fakes
|
|
58
79
|
matcher.stub(:matches?).with(3).and_return(false)
|
59
80
|
end
|
60
81
|
it "should match if its argument matcher matches the argument set" do
|
61
|
-
sut.matches?(2).
|
62
|
-
sut.matches?(3).
|
82
|
+
expect(sut.matches?(2)).to be_true
|
83
|
+
expect(sut.matches?(3)).to be_false
|
63
84
|
end
|
64
85
|
end
|
65
86
|
|
@@ -71,13 +92,13 @@ module Fakes
|
|
71
92
|
ArgMatchFactory.stub(:create_arg_matcher_using).with(2).and_return(the_matcher)
|
72
93
|
the_matcher.stub(:matches?).with(2).and_return(true)
|
73
94
|
end
|
74
|
-
|
95
|
+
|
75
96
|
before (:each) do
|
76
97
|
sut.called_args = 2
|
77
98
|
end
|
78
99
|
|
79
100
|
it "should make the decision by using the matcher created to match the arguments" do
|
80
|
-
sut.was_called_with?(2).
|
101
|
+
expect(sut.was_called_with?(2)).to be_true
|
81
102
|
end
|
82
103
|
end
|
83
104
|
end
|
@@ -9,9 +9,10 @@ module Fakes
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should create a combined matcher that is composed of regular matchers" do
|
12
|
-
@result.all_matchers.count.
|
12
|
+
expect(@result.all_matchers.count).to eql(3)
|
13
|
+
|
13
14
|
@result.all_matchers.each do|matcher|
|
14
|
-
matcher.class.
|
15
|
+
expect(matcher.class).to eql(RegularArgMatcher)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -26,8 +27,8 @@ module Fakes
|
|
26
27
|
end
|
27
28
|
|
28
29
|
it "should create a combined matcher that only using the matchers provided" do
|
29
|
-
@result.all_matchers.count.
|
30
|
-
@result.all_matchers[0].
|
30
|
+
expect(@result.all_matchers.count).to eql(1)
|
31
|
+
expect(@result.all_matchers[0]).to eql(matcher)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -7,7 +7,7 @@ module Fakes
|
|
7
7
|
|
8
8
|
fake.hello("World")
|
9
9
|
|
10
|
-
fake.received(:hello).called_with(ArgumentMatching.any).
|
10
|
+
expect(fake.received(:hello).called_with(ArgumentMatching.any)).to_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(ArgumentMatching.greater_than(2)).
|
18
|
+
expect(fake.received(:hello).called_with(ArgumentMatching.greater_than(2))).to_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(ArgumentMatching.regex(/is/)).
|
26
|
+
expect(fake.received(:hello).called_with(ArgumentMatching.regex(/is/))).to_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(ArgumentMatching.in_range(4..8)).
|
34
|
+
expect(fake.received(:hello).called_with(ArgumentMatching.in_range(4..8))).to_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(ArgumentMatching.condition{|item| item < 10}).
|
42
|
+
expect(fake.received(:hello).called_with(ArgumentMatching.condition{|item| item < 10})).to_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,ArgumentMatching.greater_than(2),ArgumentMatching.regex(/Y/)).
|
51
|
-
fake.received(:hello).called_with(7,ArgumentMatching.any,ArgumentMatching.regex(/Y/)).
|
52
|
-
fake.received(:hello).called_with(7,ArgumentMatching.any,"Yes").
|
53
|
-
fake.received(:hello).called_with(6,ArgumentMatching.any,"Yes").
|
50
|
+
expect(fake.received(:hello).called_with(7,ArgumentMatching.greater_than(2),ArgumentMatching.regex(/Y/))).to_not be_nil
|
51
|
+
expect(fake.received(:hello).called_with(7,ArgumentMatching.any,ArgumentMatching.regex(/Y/))).to_not be_nil
|
52
|
+
expect(fake.received(:hello).called_with(7,ArgumentMatching.any,"Yes")).to_not be_nil
|
53
|
+
expect(fake.received(:hello).called_with(6,ArgumentMatching.any,"Yes")).to be_nil
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
data/spec/specs/arg_set_spec.rb
CHANGED
@@ -2,41 +2,41 @@ module Fakes
|
|
2
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| ArgumentMatching.any.matches?(item).
|
5
|
+
(1..10).each{|item| expect(ArgumentMatching.any.matches?(item)).to be_true}
|
6
6
|
end
|
7
7
|
it "should be able to create a numeric greater than matcher" do
|
8
8
|
match = ArgumentMatching.greater_than(5)
|
9
|
-
match.matches?(4).
|
10
|
-
match.matches?(5).
|
11
|
-
match.matches?(6).
|
9
|
+
expect(match.matches?(4)).to be_false
|
10
|
+
expect(match.matches?(5)).to be_false
|
11
|
+
expect(match.matches?(6)).to be_true
|
12
12
|
|
13
13
|
end
|
14
14
|
it "should be able to create a range matcher" do
|
15
15
|
match = ArgumentMatching.in_range((1..10))
|
16
|
-
match.matches?(4).
|
17
|
-
match.matches?(10).
|
18
|
-
match.matches?(11).
|
16
|
+
expect(match.matches?(4)).to be_true
|
17
|
+
expect(match.matches?(10)).to be_true
|
18
|
+
expect(match.matches?(11)).to be_false
|
19
19
|
end
|
20
20
|
it "should be able to create a nil matcher" do
|
21
21
|
match = ArgumentMatching.nil
|
22
|
-
match.matches?(nil).
|
23
|
-
match.matches?(10).
|
22
|
+
expect(match.matches?(nil)).to be_true
|
23
|
+
expect(match.matches?(10)).to be_false
|
24
24
|
end
|
25
25
|
it "should be able to create a not nil matcher" do
|
26
26
|
match = ArgumentMatching.not_nil
|
27
|
-
match.matches?(10).
|
28
|
-
match.matches?(nil).
|
27
|
+
expect(match.matches?(10)).to be_true
|
28
|
+
expect(match.matches?(nil)).to be_false
|
29
29
|
end
|
30
30
|
it "should be able to create a regex string matcher" do
|
31
31
|
match = ArgumentMatching.regex(/a|e|i|o|u/)
|
32
|
-
match.matches?("awwef").
|
33
|
-
match.matches?("rwwgf").
|
32
|
+
expect(match.matches?("awwef")).to be_true
|
33
|
+
expect(match.matches?("rwwgf")).to be_false
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should be able to create a lambda based matcher" do
|
37
37
|
match = ArgumentMatching.condition{|item| item > 3}
|
38
|
-
match.matches?(2).
|
39
|
-
match.matches?(7).
|
38
|
+
expect(match.matches?(2)).to be_false
|
39
|
+
expect(match.matches?(7)).to be_true
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -8,7 +8,7 @@ module Fakes
|
|
8
8
|
let(:sut){ClassSwap.new(MyClass,Object.new)}
|
9
9
|
|
10
10
|
it "should store the symbol of the class it is going to replace" do
|
11
|
-
sut.klass.
|
11
|
+
expect(sut.klass).to eql(:MyClass)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
context "when initiated" do
|
@@ -30,11 +30,11 @@ module Fakes
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should remove the current value of the class constant and store it for reset at a later point" do
|
33
|
-
@klass_to_remove.
|
33
|
+
expect(@klass_to_remove).to eql(the_sym)
|
34
34
|
end
|
35
35
|
it "should replace the current value of the symbol with the replacement value" do
|
36
|
-
@klass_to_change.
|
37
|
-
@replacement_value.
|
36
|
+
expect(@klass_to_change).to eql(the_sym)
|
37
|
+
expect(@replacement_value).to eql(replacement)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
context "when reset" do
|
@@ -64,9 +64,9 @@ module Fakes
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should switch the value of the class back to its original value" do
|
67
|
-
@klass_to_remove.
|
68
|
-
@klass_to_change.
|
69
|
-
@replacement_value.
|
67
|
+
expect(@klass_to_remove).to eql(the_sym)
|
68
|
+
expect(@klass_to_change).to eql(the_sym)
|
69
|
+
expect(@replacement_value).to eql(MyClass)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -43,11 +43,11 @@ module Fakes
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should add a new class swap to the set of class swaps' do
|
46
|
-
ClassSwaps.instance.swaps[the_sym].
|
46
|
+
expect(ClassSwaps.instance.swaps[the_sym]).to eql(the_swap)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should initiate the swap" do
|
50
|
-
the_swap.inititated.
|
50
|
+
expect(the_swap.inititated).to be_true
|
51
51
|
end
|
52
52
|
|
53
53
|
|
@@ -67,7 +67,7 @@ module Fakes
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'should throw an error indicating that the swap is already present' do
|
70
|
-
@exception.message.
|
70
|
+
expect(@exception.message).to contain(MyClass.to_s)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -86,11 +86,11 @@ module Fakes
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should reset each of the swaps' do
|
89
|
-
first_swap.was_reset.
|
90
|
-
second_swap.was_reset.
|
89
|
+
expect(first_swap.was_reset).to be_true
|
90
|
+
expect(second_swap.was_reset).to be_true
|
91
91
|
end
|
92
92
|
it "should clear the swaps" do
|
93
|
-
sut.swaps.count.
|
93
|
+
expect(sut.swaps.count).to eql(0)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
context "Integration Test" do
|
@@ -98,21 +98,21 @@ module Fakes
|
|
98
98
|
|
99
99
|
it 'should be able to swap class values' do
|
100
100
|
ClassSwaps.instance.add_fake_for(Dir,replacement)
|
101
|
-
Dir.
|
101
|
+
expect(Dir).to eql(replacement)
|
102
102
|
ClassSwaps.instance.reset
|
103
|
-
Dir.
|
103
|
+
expect(Dir).to_not eql(replacement)
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'should be able to swap class values in another module' do
|
107
107
|
ClassSwaps.instance.add_fake_for(SomeModule::ClassInAModule,replacement)
|
108
|
-
SomeModule::ClassInAModule.
|
108
|
+
expect(SomeModule::ClassInAModule).to eql(replacement)
|
109
109
|
ClassSwaps.instance.reset
|
110
|
-
SomeModule::ClassInAModule.
|
110
|
+
expect(SomeModule::ClassInAModule).to_not eql(replacement)
|
111
111
|
|
112
112
|
ClassSwaps.instance.add_fake_for(SomeModule::NestedModule::AClassInANestedModule,replacement)
|
113
|
-
SomeModule::NestedModule::AClassInANestedModule.
|
113
|
+
expect(SomeModule::NestedModule::AClassInANestedModule).to eql(replacement)
|
114
114
|
ClassSwaps.instance.reset
|
115
|
-
SomeModule::NestedModule::AClassInANestedModule.
|
115
|
+
expect(SomeModule::NestedModule::AClassInANestedModule).to_not eql(replacement)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
@@ -21,7 +21,7 @@ module Fakes
|
|
21
21
|
|
22
22
|
|
23
23
|
it "should match if each of its argument matchers matches its respective argument" do
|
24
|
-
@result.
|
24
|
+
expect(@result).to be_true
|
25
25
|
end
|
26
26
|
end
|
27
27
|
context "when adding a matcher" do
|
@@ -36,7 +36,7 @@ module Fakes
|
|
36
36
|
|
37
37
|
|
38
38
|
it "should add the matcher to its set of matchers" do
|
39
|
-
matchers[0].
|
39
|
+
expect(matchers[0]).to eql(first_matcher)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Fakes do
|
4
4
|
it "should be able to create a new fake" do
|
5
|
-
fake.class.
|
5
|
+
expect(fake.class).to eql(Fakes::Fake )
|
6
6
|
end
|
7
7
|
it "should be able to create a new fake and specify return values for methods" do
|
8
8
|
item = fake :hello => 'World', :age => 33
|
9
|
-
item.hello.
|
10
|
-
item.age.
|
9
|
+
expect(item.hello).to eql('World')
|
10
|
+
expect(item.age).to eql(33)
|
11
11
|
end
|
12
12
|
|
13
13
|
context "when specifying a fake for a class" do
|
@@ -20,11 +20,11 @@ describe Fakes do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should register a new fake with the class swaps" do
|
23
|
-
swaps.received(:add_fake_for).called_with(Dir,arg_match.not_nil).
|
23
|
+
expect(swaps.received(:add_fake_for).called_with(Dir,arg_match.not_nil)).to_not be_nil
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should return the newly created fake" do
|
27
|
-
@result.
|
27
|
+
expect(@result).to_not be_nil
|
28
28
|
end
|
29
29
|
end
|
30
30
|
context "when faking a class and specifying return values" do
|
@@ -35,7 +35,7 @@ describe Fakes do
|
|
35
35
|
reset_fake_classes
|
36
36
|
end
|
37
37
|
it "should replace the class with the fake return to return the values specified" do
|
38
|
-
Dir.exist?('hello').
|
38
|
+
expect(Dir.exist?('hello')).to be_true
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
data/spec/specs/fake_spec.rb
CHANGED
@@ -16,10 +16,10 @@ module Fakes
|
|
16
16
|
@result = sut.stub(symbol)
|
17
17
|
end
|
18
18
|
it "should add a new method stub to the list of all invocations" do
|
19
|
-
invocations[symbol].
|
19
|
+
expect(invocations[symbol]).to eql(new_method)
|
20
20
|
end
|
21
21
|
it "should return the method invocation to continue specifying call behaviour" do
|
22
|
-
@result.
|
22
|
+
expect(@result).to eql(new_method )
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -32,11 +32,11 @@ module Fakes
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should not readd the method to the list of invocations" do
|
35
|
-
invocations.count.
|
35
|
+
expect(invocations.count).to eql(1)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should return the method invocation to continue specifying call behaviour" do
|
39
|
-
@result.
|
39
|
+
expect(@result).to eql(new_method )
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -53,7 +53,7 @@ module Fakes
|
|
53
53
|
@result = sut.received(symbol)
|
54
54
|
end
|
55
55
|
it "should return the method invocation for the called method" do
|
56
|
-
@result.
|
56
|
+
expect(@result).to eql(method_invocation )
|
57
57
|
end
|
58
58
|
end
|
59
59
|
context "when verifying whether a call was never received" do
|
@@ -70,7 +70,7 @@ module Fakes
|
|
70
70
|
|
71
71
|
it "should base its decision on the list of received invocations" do
|
72
72
|
[:other, existing].each do|item|
|
73
|
-
sut.never_received?(item).
|
73
|
+
expect(sut.never_received?(item)).to_not be_equal(invocations.has_key?(item))
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -104,10 +104,10 @@ module Fakes
|
|
104
104
|
@result = sut.hello(args)
|
105
105
|
end
|
106
106
|
it "should trigger the invocation with the arguments" do
|
107
|
-
invocation.args.
|
107
|
+
expect(invocation.args).to eql([args])
|
108
108
|
end
|
109
109
|
it "should return the result of triggering the invocation" do
|
110
|
-
@result.
|
110
|
+
expect(@result).to eql(invocation.return_value)
|
111
111
|
end
|
112
112
|
end
|
113
113
|
context "and the method is for an invocation that was not prepared" do
|
@@ -118,19 +118,19 @@ module Fakes
|
|
118
118
|
@result = sut.hello(args)
|
119
119
|
end
|
120
120
|
it "should add a new invocation which ignores arguments to the list of all invocations" do
|
121
|
-
invocations.has_key?(:hello).
|
121
|
+
expect(invocations.has_key?(:hello)).to be_true
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should configure the new invocation to ignore all arguments" do
|
125
|
-
invocation.ignores_args.
|
125
|
+
expect(invocation.ignores_args).to be_true
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should invoke the invocation with the arguments" do
|
129
|
-
invocation.args.
|
129
|
+
expect(invocation.args).to eql([args])
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should return the result of triggering the new invocation" do
|
133
|
-
@result.
|
133
|
+
expect(@result).to eql(invocation.return_value)
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
@@ -165,10 +165,10 @@ module Fakes
|
|
165
165
|
@result = sut.send(:hello,args)
|
166
166
|
end
|
167
167
|
it "should trigger the invocation with the arguments" do
|
168
|
-
invocation.args.
|
168
|
+
expect(invocation.args).to eql([args])
|
169
169
|
end
|
170
170
|
it "should return the result of triggering the invocation" do
|
171
|
-
@result.
|
171
|
+
expect(@result).to eql(invocation.return_value)
|
172
172
|
end
|
173
173
|
end
|
174
174
|
context "and the method is for an invocation that was not prepared" do
|
@@ -179,19 +179,19 @@ module Fakes
|
|
179
179
|
@result = sut.send(:hello,args)
|
180
180
|
end
|
181
181
|
it "should add a new invocation which ignores arguments to the list of all invocations" do
|
182
|
-
invocations.has_key?(:hello).
|
182
|
+
expect(invocations.has_key?(:hello)).to be_true
|
183
183
|
end
|
184
184
|
|
185
185
|
it "should configure the new invocation to ignore all arguments" do
|
186
|
-
invocation.ignores_args.
|
186
|
+
expect(invocation.ignores_args).to be_true
|
187
187
|
end
|
188
188
|
|
189
189
|
it "should invoke the invocation with the arguments" do
|
190
|
-
invocation.args.
|
190
|
+
expect(invocation.args).to eql([args])
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should return the result of triggering the new invocation" do
|
194
|
-
@result.
|
194
|
+
expect(@result).to eql(invocation.return_value)
|
195
195
|
end
|
196
196
|
end
|
197
197
|
end
|
@@ -202,103 +202,103 @@ module Fakes
|
|
202
202
|
fake = Fake.new
|
203
203
|
|
204
204
|
fake.stub(:hello).with(ArgumentMatching.regex(/W/)).and_return("Hello World")
|
205
|
-
fake.hello("World").
|
205
|
+
expect(fake.hello("World")).to eql("Hello World")
|
206
206
|
end
|
207
207
|
it "should be able to intercept on methods using combinations of explicit values and matchers" do
|
208
208
|
fake = Fake.new
|
209
209
|
|
210
210
|
fake.stub(:hello).with(ArgumentMatching.regex(/W/),ArgumentMatching.greater_than(3),10).and_return("Hello World")
|
211
211
|
|
212
|
-
fake.hello("World",4,10).
|
213
|
-
fake.hello("World",2,10).
|
212
|
+
expect(fake.hello("World",4,10)).to eql("Hello World")
|
213
|
+
expect(fake.hello("World",2,10)).to be_nil
|
214
214
|
end
|
215
215
|
end
|
216
216
|
context "setting up return values" do
|
217
217
|
it "should be able to intercept on methods that take a singular value" do
|
218
218
|
fake = Fake.new
|
219
219
|
fake.stub(:hello).with("World").and_return("Hello World")
|
220
|
-
fake.hello("World").
|
220
|
+
expect(fake.hello("World")).to eql("Hello World")
|
221
221
|
end
|
222
222
|
|
223
223
|
it "should be able to intercept on methods that take a hash" do
|
224
224
|
fake = Fake.new
|
225
225
|
fake.stub(:hello).with(:id => "JP",:age => 33).and_return("Hello World")
|
226
|
-
fake.hello(:id => "JP",:age => 33).
|
226
|
+
expect(fake.hello(:id => "JP",:age => 33)).to eql("Hello World")
|
227
227
|
end
|
228
228
|
|
229
229
|
it "should be able to intercept on methods that take a value and a hash" do
|
230
230
|
fake = Fake.new
|
231
231
|
fake.stub(:hello).with(1,:id => "JP",:age => 33).and_return("Hello World")
|
232
232
|
|
233
|
-
fake.hello(1,:id => "JP",:age => 33).
|
234
|
-
fake.hello(2,:id => "JP",:age => 33).
|
233
|
+
expect(fake.hello(1,:id => "JP",:age => 33)).to eql("Hello World")
|
234
|
+
expect(fake.hello(2,:id => "JP",:age => 33)).to be_nil
|
235
235
|
end
|
236
236
|
|
237
237
|
it "should be able to intercept on methods that take an array" do
|
238
238
|
fake = Fake.new
|
239
239
|
fake.stub(:hello).with([1,2,3,4]).and_return("Hello World")
|
240
240
|
|
241
|
-
fake.hello([1,2,3,4]).
|
241
|
+
expect(fake.hello([1,2,3,4])).to eql("Hello World")
|
242
242
|
end
|
243
243
|
|
244
244
|
it "should be able to intercept on methods that take an value, and an array" do
|
245
245
|
fake = Fake.new
|
246
246
|
fake.stub(:hello).with(1,[1,2,3,4]).and_return("Hello World")
|
247
247
|
|
248
|
-
fake.hello(1,[1,2,3,4]).
|
248
|
+
expect(fake.hello(1,[1,2,3,4])).to eql("Hello World")
|
249
249
|
end
|
250
250
|
end
|
251
251
|
context "verifying calls were made" do
|
252
252
|
it "should be able to intercept on methods that take a singular value" do
|
253
253
|
fake = Fake.new
|
254
254
|
fake.hello("World")
|
255
|
-
fake.received(:hello).called_with("World").
|
255
|
+
expect(fake.received(:hello).called_with("World")).to be_true
|
256
256
|
end
|
257
257
|
|
258
258
|
it "should be able to intercept on methods that have no arguments" do
|
259
259
|
fake = Fake.new
|
260
260
|
fake.hello
|
261
|
-
fake.received(:hello).
|
261
|
+
expect(fake.received(:hello)).to_not be_nil
|
262
262
|
end
|
263
263
|
|
264
264
|
|
265
265
|
it "should be able to intercept on methods that take a hash" do
|
266
266
|
fake = Fake.new
|
267
267
|
fake.hello(:id => "JP",:age => 33)
|
268
|
-
fake.received(:hello).called_with(:id => "JP",:age => 33).
|
269
|
-
fake.received(:hello).called_with(:id => "JS",:age => 33).
|
268
|
+
expect(fake.received(:hello).called_with(:id => "JP",:age => 33)).to_not be_nil
|
269
|
+
expect(fake.received(:hello).called_with(:id => "JS",:age => 33)).to be_nil
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should be able to intercept on methods that take a value and a hash" do
|
273
273
|
fake = Fake.new
|
274
274
|
|
275
275
|
fake.hello(1,:id => "JP",:age => 33)
|
276
|
-
fake.received(:hello).called_with(1,:id => "JP",:age => 33).
|
277
|
-
fake.received(:hello).called_with(1,:id => "JS",:age => 33).
|
276
|
+
expect(fake.received(:hello).called_with(1,:id => "JP",:age => 33)).to_not be_nil
|
277
|
+
expect(fake.received(:hello).called_with(1,:id => "JS",:age => 33)).to be_nil
|
278
278
|
end
|
279
279
|
|
280
280
|
it "should be able to intercept on methods that take an array" do
|
281
281
|
fake = Fake.new
|
282
282
|
|
283
283
|
fake.hello([1,2,3,4])
|
284
|
-
fake.received(:hello).called_with([1,2,3,4]).
|
285
|
-
fake.received(:hello).called_with([1,2,3,5]).
|
284
|
+
expect(fake.received(:hello).called_with([1,2,3,4])).to_not be_nil
|
285
|
+
expect(fake.received(:hello).called_with([1,2,3,5])).to be_nil
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should be able to intercept on methods that take an value, and an array" do
|
289
289
|
fake = Fake.new
|
290
290
|
fake.hello(1,[1,2,3,4])
|
291
291
|
|
292
|
-
fake.received(:hello).called_with(1,[1,2,3,4]).
|
293
|
-
fake.received(:hello).called_with(1,[1,2,3,5]).
|
292
|
+
expect(fake.received(:hello).called_with(1,[1,2,3,4])).to_not be_nil
|
293
|
+
expect(fake.received(:hello).called_with(1,[1,2,3,5])).to be_nil
|
294
294
|
end
|
295
295
|
|
296
296
|
it 'should be able to determine if it received a method call' do
|
297
297
|
fake = Fake.new
|
298
298
|
fake.hello(1,[1,2,3,4])
|
299
299
|
|
300
|
-
fake.received?(:hello,1,[1,2,3,4]).
|
301
|
-
fake.received?(:hello).
|
300
|
+
expect(fake.received?(:hello,1,[1,2,3,4])).to be_true
|
301
|
+
expect(fake.received?(:hello)).to be_true
|
302
302
|
end
|
303
303
|
|
304
304
|
|
@@ -6,14 +6,14 @@ module Fakes
|
|
6
6
|
|
7
7
|
context "when created" do
|
8
8
|
it "should initialize required members" do
|
9
|
-
sut.times_called.
|
9
|
+
expect(sut.times_called).to eql(0)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
context "when matching an argument set" do
|
14
14
|
it "should match any argument set" do
|
15
|
-
sut.matches?([1,2,3,4]).
|
16
|
-
sut.matches?([3,"hello",4,5]).
|
15
|
+
expect(sut.matches?([1,2,3,4])).to be_true
|
16
|
+
expect(sut.matches?([3,"hello",4,5])).to be_true
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -23,7 +23,7 @@ module Fakes
|
|
23
23
|
sut.capture_args(2)
|
24
24
|
end
|
25
25
|
it "should store a list for each set of arguments" do
|
26
|
-
sut.arg_sets.count.
|
26
|
+
expect(sut.arg_sets.count).to eql(2)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -42,7 +42,7 @@ module Fakes
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should make the decision by using the matcher created to match the argument sets that were stored" do
|
45
|
-
sut.was_called_with?(2).
|
45
|
+
expect(sut.was_called_with?(2)).to be_true
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -16,10 +16,10 @@ module Fakes
|
|
16
16
|
@result = sut.with(args)
|
17
17
|
end
|
18
18
|
it "should add a new argument set to its list of arguments" do
|
19
|
-
arg_sets[0].
|
19
|
+
expect(arg_sets[0]).to eql(argument_set)
|
20
20
|
end
|
21
21
|
it "should return the argument set to continue specifying behaviour" do
|
22
|
-
@result.
|
22
|
+
expect(@result).to eql(argument_set)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -35,10 +35,10 @@ module Fakes
|
|
35
35
|
@result = sut.ignore_arg
|
36
36
|
end
|
37
37
|
it "should add the ignored set to the list of argument sets" do
|
38
|
-
arg_sets[0].
|
38
|
+
expect(arg_sets[0]).to eql(ignored_set)
|
39
39
|
end
|
40
40
|
it "should return the ignored set to specify other behaviour" do
|
41
|
-
@result.
|
41
|
+
expect(@result).to eql(ignored_set)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -64,10 +64,10 @@ module Fakes
|
|
64
64
|
sut.throws(exception)
|
65
65
|
end
|
66
66
|
it "should add the ignored set to the set of args sets" do
|
67
|
-
arg_sets[0].
|
67
|
+
expect(arg_sets[0]).to eql(ignored_set)
|
68
68
|
end
|
69
69
|
it "should have stored the exception on the new argument set" do
|
70
|
-
ignored_set.exception.
|
70
|
+
expect(ignored_set.exception).to eql(exception)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
context "when invoked with a set of arguments" do
|
@@ -92,10 +92,10 @@ module Fakes
|
|
92
92
|
@result = sut.invoke(arguments)
|
93
93
|
end
|
94
94
|
it "should tell the argument set to capture the arguments it was called with" do
|
95
|
-
arg_set.args.
|
95
|
+
expect(arg_set.args).to eql([arguments])
|
96
96
|
end
|
97
97
|
it "should return using from the arg set" do
|
98
|
-
@result.
|
98
|
+
expect(@result).to eql(2)
|
99
99
|
end
|
100
100
|
|
101
101
|
end
|
@@ -110,10 +110,10 @@ module Fakes
|
|
110
110
|
@result = sut.invoke(arguments)
|
111
111
|
end
|
112
112
|
it "should tell the argument set to capture the arguments it was called with" do
|
113
|
-
arg_set.args.
|
113
|
+
expect(arg_set.args).to eql([arguments])
|
114
114
|
end
|
115
115
|
it "should return using from the missing arg set" do
|
116
|
-
@result.
|
116
|
+
expect(@result).to eql(2)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -142,7 +142,7 @@ module Fakes
|
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should return the argument set that was called with the arguments" do
|
145
|
-
@result.
|
145
|
+
expect(@result).to eql(arg_set)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
context "and none of its argument sets were called with the arguments" do
|
@@ -150,7 +150,7 @@ module Fakes
|
|
150
150
|
@result = sut.called_with(arguments)
|
151
151
|
end
|
152
152
|
it "should return nil" do
|
153
|
-
@result.
|
153
|
+
expect(@result).to be_nil
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
@@ -170,7 +170,7 @@ module Fakes
|
|
170
170
|
end
|
171
171
|
|
172
172
|
it "it should return the sum of the invocations of its argument sets" do
|
173
|
-
sut.total_times_called.
|
173
|
+
expect(sut.total_times_called).to eql(5)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
context "when verifying whether it was called a certain number of times" do
|
@@ -187,8 +187,8 @@ module Fakes
|
|
187
187
|
end
|
188
188
|
|
189
189
|
it "it should return whether the sum of its argset invocations is the same as the number of request made" do
|
190
|
-
sut.times?(5).
|
191
|
-
sut.times?(3).
|
190
|
+
expect(sut.times?(5)).to be_true
|
191
|
+
expect(sut.times?(3)).to be_false
|
192
192
|
end
|
193
193
|
end
|
194
194
|
end
|
@@ -6,8 +6,8 @@ module Fakes
|
|
6
6
|
let(:sut){RegularArgMatcher.new(2)}
|
7
7
|
|
8
8
|
it "should match if the incoming value matches the value it was created to match" do
|
9
|
-
sut.matches?(2).
|
10
|
-
sut.matches?(3).
|
9
|
+
expect(sut.matches?(2)).to be_true
|
10
|
+
expect(sut.matches?(3)).to be_false
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Develop With Passion®
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-11-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
type: :
|
19
|
+
version: 2.14.1
|
20
|
+
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 2.14.1
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: guard
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: guard-rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: Faking library that allows inspection of received calls after they have
|
@@ -83,7 +74,7 @@ executables: []
|
|
83
74
|
extensions: []
|
84
75
|
extra_rdoc_files: []
|
85
76
|
files:
|
86
|
-
- .gitignore
|
77
|
+
- ".gitignore"
|
87
78
|
- Gemfile
|
88
79
|
- Guardfile
|
89
80
|
- LICENSE
|
@@ -122,27 +113,26 @@ files:
|
|
122
113
|
- spec/specs/regular_arg_matcher_spec.rb
|
123
114
|
homepage: http://www.developwithpassion.com
|
124
115
|
licenses: []
|
116
|
+
metadata: {}
|
125
117
|
post_install_message:
|
126
118
|
rdoc_options: []
|
127
119
|
require_paths:
|
128
120
|
- lib
|
129
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
122
|
requirements:
|
132
|
-
- -
|
123
|
+
- - ">="
|
133
124
|
- !ruby/object:Gem::Version
|
134
125
|
version: '0'
|
135
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
127
|
requirements:
|
138
|
-
- -
|
128
|
+
- - ">="
|
139
129
|
- !ruby/object:Gem::Version
|
140
130
|
version: '0'
|
141
131
|
requirements: []
|
142
132
|
rubyforge_project: fakes
|
143
|
-
rubygems_version:
|
133
|
+
rubygems_version: 2.2.2
|
144
134
|
signing_key:
|
145
|
-
specification_version:
|
135
|
+
specification_version: 4
|
146
136
|
summary: Simple faking library
|
147
137
|
test_files:
|
148
138
|
- spec/spec_helper.rb
|