rspec-spy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rvmrc.template +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/rspec-spy/version.rb +5 -0
- data/lib/rspec-spy.rb +88 -0
- data/rspec-spy.gemspec +20 -0
- data/spec/rspec_spy_spec.rb +44 -0
- data/spec/spec_helper.rb +7 -0
- metadata +81 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc.template
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3@rspec-spy --create
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Aaron Jensen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rspec::Spy
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rspec-spy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rspec-spy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/rspec-spy.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'rspec-spy/version'
|
2
|
+
|
3
|
+
require 'rspec/matchers'
|
4
|
+
require 'rspec/mocks'
|
5
|
+
|
6
|
+
RSpec::Mocks::Methods.class_eval do
|
7
|
+
def should_receive_with_spy_check(*args, &block)
|
8
|
+
should_receive!(*args, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
alias_method :should_receive!, :should_receive
|
12
|
+
alias_method :should_receive, :should_receive_with_spy_check
|
13
|
+
|
14
|
+
def should_not_receive_with_spy_check(*args, &block)
|
15
|
+
should_not_receive!(*args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :should_not_receive!, :should_not_receive
|
19
|
+
alias_method :should_not_receive, :should_not_receive_with_spy_check
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rspec/core/hooks'
|
23
|
+
module RSpec
|
24
|
+
module Spy
|
25
|
+
def self.included(mod)
|
26
|
+
mod.extend ExampleGroupMethods
|
27
|
+
end
|
28
|
+
|
29
|
+
class SpyProxy
|
30
|
+
def initialize(example_group)
|
31
|
+
@example_group = example_group
|
32
|
+
end
|
33
|
+
|
34
|
+
def example_method(method, description, *args, &block)
|
35
|
+
@example_group.context do
|
36
|
+
let(:__spy__, &block)
|
37
|
+
|
38
|
+
send(method, description, *args) do
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
[
|
44
|
+
:example,
|
45
|
+
:it,
|
46
|
+
:specify,
|
47
|
+
:focused,
|
48
|
+
:focus,
|
49
|
+
:pending,
|
50
|
+
:xexample,
|
51
|
+
:xit,
|
52
|
+
:xspecify
|
53
|
+
].each do |name|
|
54
|
+
module_eval(<<-END_RUBY, __FILE__, __LINE__)
|
55
|
+
def #{name}(desc=nil, *args, &block)
|
56
|
+
example_method(:#{name}, desc, *args, &block)
|
57
|
+
end
|
58
|
+
END_RUBY
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
module ExampleGroupMethods
|
63
|
+
def spy(&block)
|
64
|
+
setup_spy_hook
|
65
|
+
|
66
|
+
proxy = SpyProxy.new(self)
|
67
|
+
proxy.instance_eval(&block)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def setup_spy_hook
|
72
|
+
return if @spy_hook_setup
|
73
|
+
|
74
|
+
let(:__spy__) {}
|
75
|
+
hook = RSpec::Core::Hooks::BeforeHook.new({}) do
|
76
|
+
__spy__
|
77
|
+
end
|
78
|
+
|
79
|
+
hooks[:before][:each].unshift hook
|
80
|
+
@spy_hook_setup = true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
RSpec::Core::ExampleGroup.class_eval do
|
87
|
+
include RSpec::Spy
|
88
|
+
end
|
data/rspec-spy.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rspec-spy/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Aaron Jensen"]
|
6
|
+
gem.email = ["aaronjensen@gmail.com"]
|
7
|
+
gem.description = %q{Enables AAA testing for rspec-mock}
|
8
|
+
gem.summary = "rspec-spy-#{RSpec::Spy::VERSION}"
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "rspec-spy"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RSpec::Spy::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'rspec', '~> 2.0'
|
19
|
+
gem.add_dependency 'rspec-mocks', '~> 2.0'
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec-spy'
|
3
|
+
|
4
|
+
class Subject
|
5
|
+
def go(collaborator)
|
6
|
+
collaborator.message
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe RSpec::Spy do
|
11
|
+
let(:collaborator) { stub.as_null_object }
|
12
|
+
|
13
|
+
before do
|
14
|
+
Subject.new.go(collaborator)
|
15
|
+
end
|
16
|
+
|
17
|
+
spy do
|
18
|
+
it "should work with should_receive" do
|
19
|
+
collaborator.should_receive :message
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should work with multiple in one spy block" do
|
23
|
+
collaborator.should_receive :message
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should work with not" do
|
27
|
+
collaborator.should_not_receive :other_message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context do
|
32
|
+
spy do
|
33
|
+
it "should work in nested contexts" do
|
34
|
+
collaborator.should_receive :message
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
spy do
|
40
|
+
specify "should work with specify" do
|
41
|
+
collaborator.should_receive :message
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-spy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aaron Jensen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70108880012800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70108880012800
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec-mocks
|
27
|
+
requirement: &70108880012300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70108880012300
|
36
|
+
description: Enables AAA testing for rspec-mock
|
37
|
+
email:
|
38
|
+
- aaronjensen@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rspec
|
45
|
+
- .rvmrc.template
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- lib/rspec-spy.rb
|
51
|
+
- lib/rspec-spy/version.rb
|
52
|
+
- rspec-spy.gemspec
|
53
|
+
- spec/rspec_spy_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
homepage: ''
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.17
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: rspec-spy-0.0.1
|
79
|
+
test_files:
|
80
|
+
- spec/rspec_spy_spec.rb
|
81
|
+
- spec/spec_helper.rb
|