rspec-spy 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # RSpec::Spy
2
2
 
3
3
  This gem allows you to write mock expectations in an AAA (Arrange-Act-Assert) fashion
4
- with RSpec::Mocks. It does this by allowing you to declare examples within a `spy` block,
5
- which is effectively executed before everything else. Here's a simple example:
4
+ with RSpec::Mocks. It does this by allowing you to declare examples with `:spy => true`
5
+ or `:spy` (if you use `config.treat_symbols_as_metadata_keys_with_true_values = true`)
6
+ so that they are effectively executed before everything else. Here's a simple example:
6
7
 
7
8
  ``` ruby
8
9
  describe "Example" do
@@ -12,14 +13,12 @@ describe "Example" do
12
13
  collaborator.message
13
14
  end
14
15
 
15
- spy do
16
- it "should receive a message" do
17
- collaborator.should_receive :message
18
- end
16
+ it "should receive a message", :spy => true do
17
+ collaborator.should_receive :message
18
+ end
19
19
 
20
- it "should not receive other_message" do
21
- collaborator.should_not_receive :other_message
22
- end
20
+ it "should not receive other_message", :spy => true do
21
+ collaborator.should_not_receive :other_message
23
22
  end
24
23
  end
25
24
  ```
@@ -55,19 +54,18 @@ RSpec::Spy.strict_mode = true
55
54
 
56
55
  ## Usage
57
56
 
58
- Just put your spy expectations within `spy` blocks in your specs instead of in `before` blocks.
57
+ Just tag your examples with `:spy => true` or `:spy` (if you use
58
+ `config.treat_symbols_as_metadata_keys_with_true_values = true`)
59
59
  You should be able to use all of the functionality from rspec-mocks that you're
60
60
  used to, including spying on class methods.
61
61
 
62
62
  ``` ruby
63
- spy do
64
- it "should receive message" do
65
- collaborator.should_receive :message
66
- end
63
+ it "should receive message", :spy => true do
64
+ collaborator.should_receive :message
67
65
  end
68
66
 
69
- # Shorthand:
70
- spy.it "should receive message" do
67
+ # with config.treat_symbols_as_metadata_keys_with_true_values = true
68
+ it "should receive message", :spy do
71
69
  collaborator.should_receive :message
72
70
  end
73
71
  ```
@@ -89,14 +87,12 @@ describe "what not to do" do
89
87
 
90
88
  # These will fail because @collaborator is nil because this happens
91
89
  # before the above before block
92
- spy do
93
- it "should receive a message" do
94
- @collaborator.should_receive :message
95
- end
96
-
97
- it "should not receive other_message" do
98
- @collaborator.should_not_receive :other_message
99
- end
90
+ it "should receive a message", :spy => true do
91
+ @collaborator.should_receive :message
92
+ end
93
+
94
+ it "should not receive other_message", :spy => true do
95
+ @collaborator.should_not_receive :other_message
100
96
  end
101
97
  end
102
98
  ```
@@ -121,10 +117,8 @@ describe "stubbing and mocking at the same time" do
121
117
  @result.should == 5
122
118
  end
123
119
 
124
- spy do
125
- it "should receive a message" do
126
- collaborator.should_receive(:message).and_return(5)
127
- end
120
+ it "should receive a message", :spy => true do
121
+ collaborator.should_receive(:message).and_return(5)
128
122
  end
129
123
  end
130
124
  ```
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Spy
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
data/lib/rspec/spy.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  module RSpec
2
2
  module Spy
3
3
  class << self
4
- attr_accessor :in_spy_setup
4
+ attr_accessor :in_run_spy
5
5
  attr_accessor :strict_mode
6
- alias_method :in_spy_setup?, :in_spy_setup
6
+ alias_method :in_run_spy?, :in_run_spy
7
7
  alias_method :strict_mode?, :strict_mode
8
8
 
9
9
  def ok_to_spy?
10
10
  return true unless strict_mode?
11
- in_spy_setup?
11
+ in_run_spy?
12
12
  end
13
13
  end
14
14
  end
data/lib/rspec-spy.rb CHANGED
@@ -1,11 +1,19 @@
1
1
  require 'rspec/spy/version'
2
2
  require 'rspec/spy'
3
3
  require 'rspec/spy/mock_methods'
4
- require 'rspec/spy/example_group_methods'
4
+
5
+ RSpec::Core::Example.class_eval do
6
+ def run_spy
7
+ RSpec::Spy.in_run_spy = true
8
+ @example_group_instance.instance_eval &@example_block
9
+ RSpec::Spy.in_run_spy = false
10
+ @example_block = proc {}
11
+ end
12
+ end
5
13
 
6
14
  RSpec.configure do |config|
7
- config.before(:each) do |example|
8
- example.spy_setup if example.respond_to? :spy_setup
15
+ config.before(:each, :spy => true) do |example|
16
+ example.example.run_spy
9
17
  end
10
18
  end
11
19
 
data/rspec-spy.gemspec CHANGED
@@ -17,4 +17,6 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'rspec', '~> 2.0'
19
19
  gem.add_dependency 'rspec-mocks', '~> 2.0'
20
+
21
+ gem.add_development_dependency 'pry'
20
22
  end
@@ -16,24 +16,20 @@ describe RSpec::Spy do
16
16
  Subject.new.go(collaborator)
17
17
  end
18
18
 
19
- spy do
20
- it "should work with should_receive" do
21
- collaborator.should_receive :message
22
- end
19
+ it "should work with should_receive", :spy do
20
+ collaborator.should_receive :message
21
+ end
23
22
 
24
- it "should work with multiple in one spy block" do
25
- collaborator.should_receive :message
26
- end
23
+ it "should work with multiple in one spy block", :spy do
24
+ collaborator.should_receive :message
25
+ end
27
26
 
28
- it "should work with not" do
29
- collaborator.should_not_receive :other_message
30
- end
27
+ it "should work with not", :spy do
28
+ collaborator.should_not_receive :other_message
31
29
  end
32
30
 
33
- spy do
34
- specify "should work with specify" do
35
- collaborator.should_receive :message
36
- end
31
+ specify "should work with specify", :spy do
32
+ collaborator.should_receive :message
37
33
  end
38
34
  end
39
35
 
@@ -45,10 +41,8 @@ describe RSpec::Spy do
45
41
  end
46
42
 
47
43
  context do
48
- spy do
49
- it "should work in nested contexts" do
50
- collaborator.should_receive :message
51
- end
44
+ it "should work in nested contexts", :spy do
45
+ collaborator.should_receive :message
52
46
  end
53
47
  end
54
48
  end
@@ -75,25 +69,27 @@ describe RSpec::Spy, "should_receive outside of spy block" do
75
69
  end
76
70
  end
77
71
 
78
- describe RSpec::Spy, "shorthand" do
72
+ describe RSpec::Spy, "setting on context" do
79
73
  let(:collaborator) { stub.as_null_object }
80
74
 
81
75
  before do
82
76
  Subject.new.go(collaborator)
83
77
  end
84
78
 
85
- spy.it "should work in nested contexts" do
86
- collaborator.should_receive :message
79
+ context "spies", :spy do
80
+ it "should work" do
81
+ collaborator.should_receive :message
82
+ end
87
83
  end
88
84
  end
89
85
 
90
86
  describe RSpec::Spy, "nil warning" do
91
- spy.it "should warn me if I try to should_receive on nil" do
87
+ it "should warn me if I try to should_receive on nil", :spy do
92
88
  lambda { @unknown.should_receive :message }.should raise_error
93
89
  lambda { @unknown.should_not_receive :message }.should raise_error
94
90
  end
95
91
 
96
- spy.it "should not warn me if I allow message expectations on nil" do
92
+ it "should not warn me if I allow message expectations on nil", :spy do
97
93
  RSpec::Mocks::Proxy.allow_message_expectations_on_nil
98
94
  lambda { @unknown.should_not_receive :message }.should_not raise_error
99
95
  end
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.0.3
4
+ version: 0.1.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-03 00:00:00.000000000 Z
12
+ date: 2012-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70355483304080 !ruby/object:Gem::Requirement
16
+ requirement: &70191611940020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70355483304080
24
+ version_requirements: *70191611940020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-mocks
27
- requirement: &70355483303580 !ruby/object:Gem::Requirement
27
+ requirement: &70191611939520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,18 @@ dependencies:
32
32
  version: '2.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70355483303580
35
+ version_requirements: *70191611939520
36
+ - !ruby/object:Gem::Dependency
37
+ name: pry
38
+ requirement: &70191611939140 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70191611939140
36
47
  description: Enables AAA testing for rspec-mock
37
48
  email:
38
49
  - aaronjensen@gmail.com
@@ -48,9 +59,7 @@ files:
48
59
  - README.md
49
60
  - Rakefile
50
61
  - lib/rspec-spy.rb
51
- - lib/rspec/core/spy_proxy.rb
52
62
  - lib/rspec/spy.rb
53
- - lib/rspec/spy/example_group_methods.rb
54
63
  - lib/rspec/spy/mock_methods.rb
55
64
  - lib/rspec/spy/version.rb
56
65
  - rspec-spy.gemspec
@@ -79,7 +88,7 @@ rubyforge_project:
79
88
  rubygems_version: 1.8.17
80
89
  signing_key:
81
90
  specification_version: 3
82
- summary: rspec-spy-0.0.3
91
+ summary: rspec-spy-0.1.0
83
92
  test_files:
84
93
  - spec/rspec_spy_spec.rb
85
94
  - spec/spec_helper.rb
@@ -1,43 +0,0 @@
1
- # By putting this in lib/rspec/core it gets removed from the example file/line
2
- # search so it can find a matching line from the backtrace
3
- module RSpec
4
- module Core
5
- class SpyProxy
6
- def initialize(example_group)
7
- @example_group = example_group
8
- end
9
-
10
- def example_method(method, description, *args, &block)
11
- @example_group.context do
12
- let(:spy_setup) do
13
- RSpec::Spy.in_spy_setup = true
14
- instance_eval &block
15
- RSpec::Spy.in_spy_setup = false
16
- end
17
-
18
- send(method, description, *args) do
19
- end
20
- end
21
- end
22
-
23
- [
24
- :example,
25
- :it,
26
- :specify,
27
- :focused,
28
- :focus,
29
- :pending,
30
- :xexample,
31
- :xit,
32
- :xspecify
33
- ].each do |name|
34
- module_eval(<<-END_RUBY, __FILE__, __LINE__)
35
- def #{name}(desc=nil, *args, &block)
36
- example_method(:#{name}, desc, *args, &block)
37
- end
38
- END_RUBY
39
- end
40
- end
41
- end
42
- end
43
-
@@ -1,20 +0,0 @@
1
- require 'rspec/core/spy_proxy'
2
-
3
- module RSpec
4
- module Spy
5
- module ExampleGroupMethods
6
- def spy(&block)
7
- proxy = RSpec::Core::SpyProxy.new(self)
8
-
9
- if block
10
- proxy.instance_eval(&block)
11
- else
12
- proxy
13
- end
14
- end
15
- end
16
- end
17
- end
18
-
19
- RSpec::Core::ExampleGroup.extend RSpec::Spy::ExampleGroupMethods
20
-