rspec-spy 0.1.0 → 1.0.0

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.
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## Version 1.0.0
2
+
3
+ * Removed `strict_mode` and use `should_have_received` and `should_have_not_received` instead
4
+ of overriding the original RSpec::Mocks methods. `should_receive` and `should_not_receive` will
5
+ still work, but aren't recommended.
data/README.md CHANGED
@@ -14,11 +14,11 @@ describe "Example" do
14
14
  end
15
15
 
16
16
  it "should receive a message", :spy => true do
17
- collaborator.should_receive :message
17
+ collaborator.should_have_received :message
18
18
  end
19
19
 
20
20
  it "should not receive other_message", :spy => true do
21
- collaborator.should_not_receive :other_message
21
+ collaborator.should_not_have_received :other_message
22
22
  end
23
23
  end
24
24
  ```
@@ -43,15 +43,6 @@ Add to your spec_helper.rb:
43
43
  require 'rspec-spy'
44
44
  ```
45
45
 
46
- If you want to be warned when using `should_receive` outside of `spy` blocks (recommended)
47
- add this to your `spec_helper.rb`:
48
-
49
- ``` ruby
50
- # Require should_receive and should_not_receive to be inside spy blocks
51
- # Use should_receive! and should_not_receive! outside spy blocks
52
- RSpec::Spy.strict_mode = true
53
- ```
54
-
55
46
  ## Usage
56
47
 
57
48
  Just tag your examples with `:spy => true` or `:spy` (if you use
@@ -61,12 +52,12 @@ used to, including spying on class methods.
61
52
 
62
53
  ``` ruby
63
54
  it "should receive message", :spy => true do
64
- collaborator.should_receive :message
55
+ collaborator.should_have_received :message
65
56
  end
66
57
 
67
58
  # with config.treat_symbols_as_metadata_keys_with_true_values = true
68
59
  it "should receive message", :spy do
69
- collaborator.should_receive :message
60
+ collaborator.should_have_received :message
70
61
  end
71
62
  ```
72
63
 
@@ -88,11 +79,11 @@ describe "what not to do" do
88
79
  # These will fail because @collaborator is nil because this happens
89
80
  # before the above before block
90
81
  it "should receive a message", :spy => true do
91
- @collaborator.should_receive :message
82
+ @collaborator.should_have_received :message
92
83
  end
93
84
 
94
85
  it "should not receive other_message", :spy => true do
95
- @collaborator.should_not_receive :other_message
86
+ @collaborator.should_not_have_received :other_message
96
87
  end
97
88
  end
98
89
  ```
@@ -118,7 +109,7 @@ describe "stubbing and mocking at the same time" do
118
109
  end
119
110
 
120
111
  it "should receive a message", :spy => true do
121
- collaborator.should_receive(:message).and_return(5)
112
+ collaborator.should_have_received(:message).and_return(5)
122
113
  end
123
114
  end
124
115
  ```
@@ -129,6 +120,7 @@ end
129
120
  * [bourne](https://github.com/thoughtbot/bourne)
130
121
  * [rspec-spies](https://github.com/technicalpickles/rspec-spies)
131
122
  * [gimme](https://github.com/searls/gimme)
123
+ * [fakes-rspec](https://github.com/developwithpassion/fakes-rspec)
132
124
 
133
125
  ## Contributing
134
126
 
@@ -1,26 +1,23 @@
1
1
  require 'rspec/mocks'
2
2
 
3
3
  RSpec::Mocks::Methods.class_eval do
4
- def should_receive_with_spy_check(message, opts={}, &block)
5
- spy_check(:should_receive)
6
- nil_check(:should_receive)
4
+ def should_have_received(message, opts={}, &block)
5
+ check(:should_have_received)
7
6
  __mock_proxy.add_message_expectation(opts[:expected_from] || caller(1)[0], message.to_sym, opts, &block)
8
7
  end
9
8
 
10
- def should_not_receive_with_spy_check(message, &block)
11
- spy_check(:should_not_receive)
12
- nil_check(:should_not_receive)
9
+ def should_not_have_received(message, &block)
10
+ check(:should_not_have_received)
13
11
  __mock_proxy.add_negative_message_expectation(caller(1)[0], message.to_sym, &block)
14
12
  end
15
13
 
16
- alias_method :should_receive!, :should_receive
17
- alias_method :should_receive, :should_receive_with_spy_check
18
-
19
- alias_method :should_not_receive!, :should_not_receive
20
- alias_method :should_not_receive, :should_not_receive_with_spy_check
21
-
22
14
  private
23
15
 
16
+ def check(method)
17
+ spy_check(method)
18
+ nil_check(method)
19
+ end
20
+
24
21
  def spy_check(method)
25
22
  return if RSpec::Spy.ok_to_spy?
26
23
  raise "#{method} should not be used outside of a spy block. Please put it in a spy block or use #{method}!."
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Spy
3
- VERSION = "0.1.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
data/lib/rspec/spy.rb CHANGED
@@ -2,12 +2,9 @@ module RSpec
2
2
  module Spy
3
3
  class << self
4
4
  attr_accessor :in_run_spy
5
- attr_accessor :strict_mode
6
5
  alias_method :in_run_spy?, :in_run_spy
7
- alias_method :strict_mode?, :strict_mode
8
6
 
9
7
  def ok_to_spy?
10
- return true unless strict_mode?
11
8
  in_run_spy?
12
9
  end
13
10
  end
@@ -7,8 +7,6 @@ class Subject
7
7
  end
8
8
  end
9
9
 
10
- RSpec::Spy.strict_mode = true
11
-
12
10
  describe RSpec::Spy do
13
11
  let(:collaborator) { stub.as_null_object }
14
12
 
@@ -16,20 +14,20 @@ describe RSpec::Spy do
16
14
  Subject.new.go(collaborator)
17
15
  end
18
16
 
19
- it "should work with should_receive", :spy do
20
- collaborator.should_receive :message
17
+ it "should work with should_have_received", :spy do
18
+ collaborator.should_have_received :message
21
19
  end
22
20
 
23
21
  it "should work with multiple in one spy block", :spy do
24
- collaborator.should_receive :message
22
+ collaborator.should_have_received :message
25
23
  end
26
24
 
27
25
  it "should work with not", :spy do
28
- collaborator.should_not_receive :other_message
26
+ collaborator.should_not_have_received :other_message
29
27
  end
30
28
 
31
29
  specify "should work with specify", :spy do
32
- collaborator.should_receive :message
30
+ collaborator.should_have_received :message
33
31
  end
34
32
  end
35
33
 
@@ -42,7 +40,7 @@ describe RSpec::Spy do
42
40
 
43
41
  context do
44
42
  it "should work in nested contexts", :spy do
45
- collaborator.should_receive :message
43
+ collaborator.should_have_received :message
46
44
  end
47
45
  end
48
46
  end
@@ -51,8 +49,8 @@ describe RSpec::Spy, "the old way" do
51
49
  let(:collaborator) { stub.as_null_object }
52
50
 
53
51
  before do
54
- collaborator.should_receive! :message
55
- collaborator.should_not_receive! :message2
52
+ collaborator.should_have_received! :message
53
+ collaborator.should_not_have_received! :message2
56
54
  Subject.new.go(collaborator)
57
55
  end
58
56
 
@@ -60,12 +58,12 @@ describe RSpec::Spy, "the old way" do
60
58
  end
61
59
  end
62
60
 
63
- describe RSpec::Spy, "should_receive outside of spy block" do
61
+ describe RSpec::Spy, "should_have_received outside of spy block" do
64
62
  let(:collaborator) { stub.as_null_object }
65
63
 
66
64
  it "should warn" do
67
- lambda { collaborator.should_receive :message }.should raise_error
68
- lambda { collaborator.should_not_receive :message }.should raise_error
65
+ lambda { collaborator.should_have_received :message }.should raise_error
66
+ lambda { collaborator.should_not_have_received :message }.should raise_error
69
67
  end
70
68
  end
71
69
 
@@ -78,20 +76,20 @@ describe RSpec::Spy, "setting on context" do
78
76
 
79
77
  context "spies", :spy do
80
78
  it "should work" do
81
- collaborator.should_receive :message
79
+ collaborator.should_have_received :message
82
80
  end
83
81
  end
84
82
  end
85
83
 
86
84
  describe RSpec::Spy, "nil warning" do
87
- it "should warn me if I try to should_receive on nil", :spy do
88
- lambda { @unknown.should_receive :message }.should raise_error
89
- lambda { @unknown.should_not_receive :message }.should raise_error
85
+ it "should warn me if I try to should_have_received on nil", :spy do
86
+ lambda { @unknown.should_have_received :message }.should raise_error
87
+ lambda { @unknown.should_not_have_received :message }.should raise_error
90
88
  end
91
89
 
92
90
  it "should not warn me if I allow message expectations on nil", :spy do
93
91
  RSpec::Mocks::Proxy.allow_message_expectations_on_nil
94
- lambda { @unknown.should_not_receive :message }.should_not raise_error
92
+ lambda { @unknown.should_not_have_received :message }.should_not raise_error
95
93
  end
96
94
  end
97
95
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-spy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-04 00:00:00.000000000 Z
12
+ date: 2012-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70191611940020 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70191611940020
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec-mocks
27
- requirement: &70191611939520 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '2.0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70191611939520
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: pry
38
- requirement: &70191611939140 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70191611939140
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: Enables AAA testing for rspec-mock
48
63
  email:
49
64
  - aaronjensen@gmail.com
@@ -54,6 +69,7 @@ files:
54
69
  - .gitignore
55
70
  - .rspec
56
71
  - .rvmrc.template
72
+ - CHANGELOG.md
57
73
  - Gemfile
58
74
  - LICENSE
59
75
  - README.md
@@ -63,7 +79,7 @@ files:
63
79
  - lib/rspec/spy/mock_methods.rb
64
80
  - lib/rspec/spy/version.rb
65
81
  - rspec-spy.gemspec
66
- - spec/rspec_spy_spec.rb
82
+ - spec/rspec-spy_spec.rb
67
83
  - spec/spec_helper.rb
68
84
  homepage: ''
69
85
  licenses: []
@@ -85,10 +101,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
101
  version: '0'
86
102
  requirements: []
87
103
  rubyforge_project:
88
- rubygems_version: 1.8.17
104
+ rubygems_version: 1.8.21
89
105
  signing_key:
90
106
  specification_version: 3
91
- summary: rspec-spy-0.1.0
107
+ summary: rspec-spy-1.0.0
92
108
  test_files:
93
- - spec/rspec_spy_spec.rb
109
+ - spec/rspec-spy_spec.rb
94
110
  - spec/spec_helper.rb