rspec-spies 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ before_script:
7
+ - bundle install
8
+ - bundle exec rake appraisal:install
9
+ script: bundle exec rake appraisal
data/Appraisals CHANGED
@@ -1,5 +1,13 @@
1
- appraise "rspec-2-8" do
2
- gem "rspec", "~> 2.8.0"
1
+ appraise "rspec-2-13" do
2
+ gem "rspec", "~> 2.13.0"
3
+ gem "rspec-spies"
4
+ gem "rake"
5
+ gem "appraisal"
6
+ gem "jeweler"
7
+ end
8
+
9
+ appraise "rspec-2-12" do
10
+ gem "rspec", "~> 2.12.0"
3
11
  gem "rspec-spies"
4
12
  gem "rake"
5
13
  gem "appraisal"
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rspec', '~> 2.0'
4
4
 
@@ -1,25 +1,28 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
- appraisal (0.4.1)
4
+ appraisal (0.5.1)
5
5
  bundler
6
6
  rake
7
7
  diff-lcs (1.1.3)
8
8
  git (1.2.5)
9
- jeweler (1.6.4)
9
+ jeweler (1.8.4)
10
10
  bundler (~> 1.0)
11
11
  git (>= 1.2.5)
12
12
  rake
13
- rake (0.9.2)
14
- rdoc (3.6.1)
15
- rspec (2.8.0)
16
- rspec-core (~> 2.8.0)
17
- rspec-expectations (~> 2.8.0)
18
- rspec-mocks (~> 2.8.0)
19
- rspec-core (2.8.0)
20
- rspec-expectations (2.8.0)
21
- diff-lcs (~> 1.1.2)
22
- rspec-mocks (2.8.0)
13
+ rdoc
14
+ json (1.7.7)
15
+ rake (10.0.3)
16
+ rdoc (3.12.1)
17
+ json (~> 1.4)
18
+ rspec (2.12.0)
19
+ rspec-core (~> 2.12.0)
20
+ rspec-expectations (~> 2.12.0)
21
+ rspec-mocks (~> 2.12.0)
22
+ rspec-core (2.12.2)
23
+ rspec-expectations (2.12.1)
24
+ diff-lcs (~> 1.1.3)
25
+ rspec-mocks (2.12.2)
23
26
 
24
27
  PLATFORMS
25
28
  ruby
@@ -1,5 +1,7 @@
1
1
  = rspec-spies
2
2
 
3
+ {<img src="https://travis-ci.org/technicalpickles/rspec-spies.png" />}[https://travis-ci.org/technicalpickles/rspec-spies]
4
+
3
5
  Behold, the Test Spies pattern! http://xunitpatterns.com/Test%20Spy.html
4
6
 
5
7
  Some other mocking frameworks support this. In particular, rr, notamock, and jferris's fork of mocha. It'd be great to see support for it in rspec's mocking library as well.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.3
1
+ 2.1.4
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "rspec", "~> 2.11.0"
6
6
  gem "rspec-spies"
@@ -1,7 +1,7 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
- appraisal (0.4.1)
4
+ appraisal (0.5.1)
5
5
  bundler
6
6
  rake
7
7
  diff-lcs (1.1.3)
@@ -11,21 +11,20 @@ GEM
11
11
  git (>= 1.2.5)
12
12
  rake
13
13
  rdoc
14
- json (1.7.5)
15
- rake (0.9.2.2)
16
- rdoc (3.12)
14
+ json (1.7.7)
15
+ rake (10.0.3)
16
+ rdoc (4.0.0)
17
17
  json (~> 1.4)
18
18
  rspec (2.11.0)
19
19
  rspec-core (~> 2.11.0)
20
20
  rspec-expectations (~> 2.11.0)
21
21
  rspec-mocks (~> 2.11.0)
22
22
  rspec-core (2.11.1)
23
- rspec-expectations (2.11.2)
23
+ rspec-expectations (2.11.3)
24
24
  diff-lcs (~> 1.1.3)
25
- rspec-mocks (2.11.2)
26
- rspec-spies (2.1.2)
25
+ rspec-mocks (2.11.3)
26
+ rspec-spies (2.1.3)
27
27
  rspec (~> 2.0)
28
- rspec-spies
29
28
 
30
29
  PLATFORMS
31
30
  ruby
@@ -1,8 +1,8 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
- gem "rspec", "~> 2.8.0"
5
+ gem "rspec", "~> 2.12.0"
6
6
  gem "rspec-spies"
7
7
  gem "rake"
8
8
  gem "appraisal"
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ appraisal (0.5.1)
5
+ bundler
6
+ rake
7
+ diff-lcs (1.1.3)
8
+ git (1.2.5)
9
+ jeweler (1.8.4)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rdoc
14
+ json (1.7.7)
15
+ rake (10.0.3)
16
+ rdoc (4.0.0)
17
+ json (~> 1.4)
18
+ rspec (2.12.0)
19
+ rspec-core (~> 2.12.0)
20
+ rspec-expectations (~> 2.12.0)
21
+ rspec-mocks (~> 2.12.0)
22
+ rspec-core (2.12.2)
23
+ rspec-expectations (2.12.1)
24
+ diff-lcs (~> 1.1.3)
25
+ rspec-mocks (2.12.2)
26
+ rspec-spies (2.1.3)
27
+ rspec (~> 2.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ appraisal
34
+ jeweler
35
+ rake
36
+ rspec (~> 2.12.0)
37
+ rspec-spies
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rspec", "~> 2.13.0"
6
+ gem "rspec-spies"
7
+ gem "rake"
8
+ gem "appraisal"
9
+ gem "jeweler"
10
+
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ appraisal (0.5.1)
5
+ bundler
6
+ rake
7
+ diff-lcs (1.2.1)
8
+ git (1.2.5)
9
+ jeweler (1.8.4)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rdoc
14
+ json (1.7.7)
15
+ rake (10.0.3)
16
+ rdoc (4.0.0)
17
+ json (~> 1.4)
18
+ rspec (2.13.0)
19
+ rspec-core (~> 2.13.0)
20
+ rspec-expectations (~> 2.13.0)
21
+ rspec-mocks (~> 2.13.0)
22
+ rspec-core (2.13.1)
23
+ rspec-expectations (2.13.0)
24
+ diff-lcs (>= 1.1.3, < 2.0)
25
+ rspec-mocks (2.13.0)
26
+ rspec-spies (2.1.3)
27
+ rspec (~> 2.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ appraisal
34
+ jeweler
35
+ rake
36
+ rspec (~> 2.13.0)
37
+ rspec-spies
@@ -1,22 +1,17 @@
1
- require 'rspec/mocks/method_double'
2
- RSpec::Mocks::MethodDouble.class_eval do
3
- # override defining stubs to record the message was called.
4
- # there's only one line difference from upstream rspec, but can't change it without fully overriding
5
- def define_proxy_method
6
- return if @method_is_proxied
1
+ require 'rspec/mocks/proxy'
7
2
 
8
- object_singleton_class.class_eval <<-EOF, __FILE__, __LINE__ + 1
9
- def #{@method_name}(*args, &block)
10
- __mock_proxy.record_message_received :#{@method_name}, *args, &block
11
- __mock_proxy.message_received :#{@method_name}, *args, &block
12
- end
13
- #{visibility_for_method}
14
- EOF
15
- @method_is_proxied = true
3
+ RSpec::Mocks::Proxy.class_eval do
4
+ alias_method :oldsp_message_received, :message_received
5
+ alias_method :oldsp_reset, :reset
6
+
7
+ def message_received(message, *args, &block)
8
+ record_message_received(message, *args, &block)
9
+ oldsp_message_received(message, *args, &block)
16
10
  end
17
11
 
18
- def visibility_for_method
19
- "#{visibility} :#{method_name}"
12
+ def reset
13
+ @messages_received = []
14
+ oldsp_reset
20
15
  end
21
16
  end
22
17
 
@@ -33,12 +28,17 @@ end
33
28
 
34
29
  RSpec::Matchers.define :have_received do |method_name, args, block|
35
30
  match do |actual|
36
- messages_received = actual.send(:__mock_proxy).instance_variable_get("@messages_received")
37
- messages_received.any? do |message|
31
+ @messages_received = actual.send(:__mock_proxy).instance_variable_get("@messages_received").dup
32
+ @messages_received.keep_if do |message|
38
33
  received_method_name, received_args, received_block = *message
39
34
  result = (received_method_name == method_name)
40
- result &&= argument_expectation_class.new(@args || any_args).args_match?(received_args)
41
- result &&= (received_block == block)
35
+ result &&= argument_expectation_class.new(*@args || any_args).args_match?(*received_args)
36
+ end
37
+
38
+ if @times
39
+ @messages_received.length == @expected_count
40
+ else
41
+ @messages_received.length > 0
42
42
  end
43
43
  end
44
44
 
@@ -46,8 +46,16 @@ RSpec::Matchers.define :have_received do |method_name, args, block|
46
46
  @args = args
47
47
  end
48
48
 
49
+ chain :exactly do |count|
50
+ @expected_count = count
51
+ end
52
+
53
+ chain :times do
54
+ @times = true
55
+ end
56
+
49
57
  failure_message_for_should do |actual|
50
- "expected #{actual.inspect} to have received #{method_name.inspect}#{args_message}"
58
+ "expected #{actual.inspect} to have received #{method_name.inspect}#{args_message}#{times_message}"
51
59
  end
52
60
 
53
61
  failure_message_for_should_not do |actual|
@@ -61,4 +69,8 @@ RSpec::Matchers.define :have_received do |method_name, args, block|
61
69
  def args_message
62
70
  @args ? " with #{@args.inspect}" : ""
63
71
  end
72
+
73
+ def times_message
74
+ @times ? " exactly #{@expected_count} times but was called #{@messages_received.count} times" : ""
75
+ end
64
76
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rspec-spies"
8
- s.version = "2.1.3"
8
+ s.version = "2.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joshua Nichols"]
12
- s.date = "2012-11-13"
12
+ s.date = "2013-03-22"
13
13
  s.description = "test spies, for rspec"
14
14
  s.email = "josh@technicalpickles.com"
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".travis.yml",
21
22
  "Appraisals",
22
23
  "Gemfile",
23
24
  "Gemfile.lock",
@@ -25,10 +26,12 @@ Gem::Specification.new do |s|
25
26
  "README.rdoc",
26
27
  "Rakefile",
27
28
  "VERSION",
28
- "gemfiles/rspec-2-11.gemfile",
29
- "gemfiles/rspec-2-11.gemfile.lock",
30
- "gemfiles/rspec-2-8.gemfile",
31
- "gemfiles/rspec-2-8.gemfile.lock",
29
+ "gemfiles/rspec_2_11.gemfile",
30
+ "gemfiles/rspec_2_11.gemfile.lock",
31
+ "gemfiles/rspec_2_12.gemfile",
32
+ "gemfiles/rspec_2_12.gemfile.lock",
33
+ "gemfiles/rspec_2_13.gemfile",
34
+ "gemfiles/rspec_2_13.gemfile.lock",
32
35
  "lib/rspec-spies.rb",
33
36
  "rspec-spies.gemspec",
34
37
  "spec/rspec-spies_spec.rb",
@@ -37,7 +40,7 @@ Gem::Specification.new do |s|
37
40
  ]
38
41
  s.homepage = "http://github.com/technicalpickles/rspec-spies"
39
42
  s.require_paths = ["lib"]
40
- s.rubygems_version = "1.8.10"
43
+ s.rubygems_version = "1.8.25"
41
44
  s.summary = "rspec has gone without tests spies. no more!"
42
45
 
43
46
  if s.respond_to? :specification_version then
@@ -37,6 +37,42 @@ module Spec
37
37
  have_received(:slice).with(hash_including({ :foo => :baz })).matches?(@object).should be_false
38
38
  end
39
39
 
40
+ it "matches if specifies exactly(x).times" do
41
+ @object.stub!(:slice)
42
+ @object.slice(5)
43
+ @object.slice(5)
44
+
45
+ have_received(:slice).exactly(1).times.matches?(@object).should be_false
46
+ have_received(:slice).exactly(2).times.matches?(@object).should be_true
47
+ have_received(:slice).exactly(3).times.matches?(@object).should be_false
48
+ end
49
+
50
+ it "matches if called multiple times with different arguments" do
51
+ @object.stub!(:slice)
52
+ @object.slice(1)
53
+ @object.slice(2)
54
+
55
+ have_received(:slice).with(1).matches?(@object).should be_true
56
+ have_received(:slice).with(2).matches?(@object).should be_true
57
+ have_received(:slice).with(3).matches?(@object).should be_false
58
+ end
59
+
60
+ it "matches if specifies regex, if method is called with matches arguments" do
61
+ @object.stub!(:slice)
62
+ @object.slice('foobar')
63
+
64
+ have_received(:slice).with(/foo/).matches?(@object).should be_true
65
+ have_received(:slice).with(/foox/).matches?(@object).should be_false
66
+ end
67
+
68
+ it "matches if third argument is a block" do
69
+ @object.stub!(:slice)
70
+ @object.slice(5) do; end
71
+
72
+ have_received(:slice).with(5).matches?(@object).should be_true
73
+ have_received(:slice).with(5,anything).matches?(@object).should be_false
74
+ end
75
+
40
76
  it "does not match if method is called with incorrect args" do
41
77
  @object.stub!(:slice)
42
78
  @object.slice(3)
@@ -79,5 +115,21 @@ module Spec
79
115
  end
80
116
  end
81
117
 
118
+ describe 'clearing out received messages' do
119
+ class Foo; end
120
+
121
+ before do
122
+ Foo.stub(:party)
123
+ end
124
+
125
+ it 'base case' do
126
+ Foo.party
127
+ have_received(:party).matches?(Foo).should be_true
128
+ end
129
+
130
+ it 'does not match even if the class method has been called in another spec' do
131
+ have_received(:party).matches?(Foo).should be_false
132
+ end
133
+ end
82
134
  end
83
135
  end
metadata CHANGED
@@ -1,71 +1,96 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-spies
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
5
4
  prerelease:
5
+ version: 2.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joshua Nichols
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-13 00:00:00.000000000 Z
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70355083921100 !ruby/object:Gem::Requirement
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '2.0'
17
21
  none: false
22
+ requirement: !ruby/object:Gem::Requirement
18
23
  requirements:
19
24
  - - ~>
20
25
  - !ruby/object:Gem::Version
21
26
  version: '2.0'
22
- type: :runtime
27
+ none: false
23
28
  prerelease: false
24
- version_requirements: *70355083921100
29
+ type: :runtime
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &70355083920560 !ruby/object:Gem::Requirement
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
28
37
  none: false
38
+ requirement: !ruby/object:Gem::Requirement
29
39
  requirements:
30
40
  - - ! '>='
31
41
  - !ruby/object:Gem::Version
32
42
  version: '0'
33
- type: :development
43
+ none: false
34
44
  prerelease: false
35
- version_requirements: *70355083920560
45
+ type: :development
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: jeweler
38
- requirement: &70355083920040 !ruby/object:Gem::Requirement
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
39
53
  none: false
54
+ requirement: !ruby/object:Gem::Requirement
40
55
  requirements:
41
56
  - - ! '>='
42
57
  - !ruby/object:Gem::Version
43
58
  version: '0'
44
- type: :development
59
+ none: false
45
60
  prerelease: false
46
- version_requirements: *70355083920040
61
+ type: :development
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rdoc
49
- requirement: &70355083919380 !ruby/object:Gem::Requirement
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
50
69
  none: false
70
+ requirement: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - ! '>='
53
73
  - !ruby/object:Gem::Version
54
74
  version: '0'
55
- type: :development
75
+ none: false
56
76
  prerelease: false
57
- version_requirements: *70355083919380
77
+ type: :development
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: appraisal
60
- requirement: &70355083918660 !ruby/object:Gem::Requirement
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
61
85
  none: false
86
+ requirement: !ruby/object:Gem::Requirement
62
87
  requirements:
63
88
  - - ! '>='
64
89
  - !ruby/object:Gem::Version
65
90
  version: '0'
66
- type: :development
91
+ none: false
67
92
  prerelease: false
68
- version_requirements: *70355083918660
93
+ type: :development
69
94
  description: test spies, for rspec
70
95
  email: josh@technicalpickles.com
71
96
  executables: []
@@ -75,6 +100,7 @@ extra_rdoc_files:
75
100
  - README.rdoc
76
101
  files:
77
102
  - .document
103
+ - .travis.yml
78
104
  - Appraisals
79
105
  - Gemfile
80
106
  - Gemfile.lock
@@ -82,10 +108,12 @@ files:
82
108
  - README.rdoc
83
109
  - Rakefile
84
110
  - VERSION
85
- - gemfiles/rspec-2-11.gemfile
86
- - gemfiles/rspec-2-11.gemfile.lock
87
- - gemfiles/rspec-2-8.gemfile
88
- - gemfiles/rspec-2-8.gemfile.lock
111
+ - gemfiles/rspec_2_11.gemfile
112
+ - gemfiles/rspec_2_11.gemfile.lock
113
+ - gemfiles/rspec_2_12.gemfile
114
+ - gemfiles/rspec_2_12.gemfile.lock
115
+ - gemfiles/rspec_2_13.gemfile
116
+ - gemfiles/rspec_2_13.gemfile.lock
89
117
  - lib/rspec-spies.rb
90
118
  - rspec-spies.gemspec
91
119
  - spec/rspec-spies_spec.rb
@@ -98,20 +126,23 @@ rdoc_options: []
98
126
  require_paths:
99
127
  - lib
100
128
  required_ruby_version: !ruby/object:Gem::Requirement
101
- none: false
102
129
  requirements:
103
130
  - - ! '>='
104
131
  - !ruby/object:Gem::Version
132
+ hash: 2747625147983931777
133
+ segments:
134
+ - 0
105
135
  version: '0'
106
- required_rubygems_version: !ruby/object:Gem::Requirement
107
136
  none: false
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
138
  requirements:
109
139
  - - ! '>='
110
140
  - !ruby/object:Gem::Version
111
141
  version: '0'
142
+ none: false
112
143
  requirements: []
113
144
  rubyforge_project:
114
- rubygems_version: 1.8.10
145
+ rubygems_version: 1.8.25
115
146
  signing_key:
116
147
  specification_version: 3
117
148
  summary: rspec has gone without tests spies. no more!
@@ -1,38 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- appraisal (0.4.1)
5
- bundler
6
- rake
7
- diff-lcs (1.1.3)
8
- git (1.2.5)
9
- jeweler (1.8.4)
10
- bundler (~> 1.0)
11
- git (>= 1.2.5)
12
- rake
13
- rdoc
14
- json (1.7.5)
15
- rake (0.9.2.2)
16
- rdoc (3.12)
17
- json (~> 1.4)
18
- rspec (2.8.0)
19
- rspec-core (~> 2.8.0)
20
- rspec-expectations (~> 2.8.0)
21
- rspec-mocks (~> 2.8.0)
22
- rspec-core (2.8.0)
23
- rspec-expectations (2.8.0)
24
- diff-lcs (~> 1.1.2)
25
- rspec-mocks (2.8.0)
26
- rspec-spies (2.1.2)
27
- rspec (~> 2.0)
28
- rspec-spies
29
-
30
- PLATFORMS
31
- ruby
32
-
33
- DEPENDENCIES
34
- appraisal
35
- jeweler
36
- rake
37
- rspec (~> 2.8.0)
38
- rspec-spies