rspec-multi-mock 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.rdoc +43 -0
- data/lib/adapter.rb +23 -0
- data/lib/adapters/mocha.rb +15 -0
- data/lib/adapters/not_a_mock.rb +10 -0
- data/lib/adapters/rr.rb +13 -0
- data/lib/adapters/rspec.rb +9 -0
- data/lib/adapters/unknown.rb +9 -0
- data/lib/multi_mock.rb +38 -0
- data/lib/rspec-multi-mock.rb +2 -0
- metadata +141 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Deepak N
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
== Description
|
2
|
+
|
3
|
+
Allows multiple mock frameworks to be in action in RSpec. Currently works only for rspec 1.3.1.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install rspec-multi-mock
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
Add dependency in gem file
|
12
|
+
|
13
|
+
gem 'rspec-multi-mock', :group => :test
|
14
|
+
|
15
|
+
Configure multi-mock for spec runner (Usually done in spec_helper)
|
16
|
+
|
17
|
+
Spec::Runner.configure do |config|
|
18
|
+
config.mock_with MultiMock::Adapter.for(:rspec, :mocha, :rr, :not_a_mock, ::NewMockFramework::RSpecAdapter)
|
19
|
+
end
|
20
|
+
|
21
|
+
As shown above you can use a symbol for frameworks listed above. The usage of adapter module directly may not work completely if the adapter module contains any extensions methods to be used in specs. For instance RR rspec adapter includes both the adapter methods and the extension methods.
|
22
|
+
|
23
|
+
== Why should I use this?
|
24
|
+
|
25
|
+
It is always good to use a single mocking framework. There can be a time you come across a new framework with cleaner syntax and new features. But RSpec does not support multiple mocking frameworks. We may hesitate to start using the new framework because
|
26
|
+
|
27
|
+
* There is some effort required to convert all the specs to use new framework for mocking.
|
28
|
+
* The new mocking framework may not provide all the features available in the current mocking framework.
|
29
|
+
|
30
|
+
Using this gem you can
|
31
|
+
|
32
|
+
* Start moving specs incrementally to new framework
|
33
|
+
* Start using new framework for new specs. This will reduce the number of specs need to be converted at the end.
|
34
|
+
* Use both mocking frameworks till the new one provides all the required features.
|
35
|
+
|
36
|
+
If you are already using multiple mock frameworks with just one mock framework configured in spec runner, the mocks may not be working completely as you expected.
|
37
|
+
|
38
|
+
* The expectations set using the un-configured mocking framework will not be verified.
|
39
|
+
* The methods mocked or stubbed using the un-configured mocking framework will not be cleaned up after the spec run is completed. This becomes a serious issue if it is a class method.
|
40
|
+
|
41
|
+
== Limitations
|
42
|
+
|
43
|
+
* RR ad Not-A-Mock can not be used together since both frameworks have different implementation of 'have_received' matcher. This is true for any two frameworks with similar interface and different implementations.
|
data/lib/adapter.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'multi_mock'
|
2
|
+
|
3
|
+
module MultiMock
|
4
|
+
module Adapter
|
5
|
+
def self.for(*frameworks)
|
6
|
+
self.tap do
|
7
|
+
MultiMock.frameworks = frameworks.flatten
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup_mocks_for_rspec
|
12
|
+
MultiMock.frameworks.each(&:setup_mocks_for_rspec)
|
13
|
+
end
|
14
|
+
|
15
|
+
def verify_mocks_for_rspec
|
16
|
+
MultiMock.frameworks.each(&:verify_mocks_for_rspec)
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown_mocks_for_rspec
|
20
|
+
MultiMock.frameworks.each(&:teardown_mocks_for_rspec)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mocha/object'
|
3
|
+
require 'mocha/api'
|
4
|
+
|
5
|
+
module MultiMock
|
6
|
+
module Adapters
|
7
|
+
class Mocha
|
8
|
+
include ::Mocha::API
|
9
|
+
|
10
|
+
alias :setup_mocks_for_rspec :mocha_setup
|
11
|
+
alias :verify_mocks_for_rspec :mocha_verify
|
12
|
+
alias :teardown_mocks_for_rspec :mocha_teardown
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/adapters/rr.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rr'
|
3
|
+
|
4
|
+
module MultiMock
|
5
|
+
module Adapters
|
6
|
+
class RR
|
7
|
+
include ::RR::Adapters::Rspec
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
#This will add mock(Entity), stub(Entity) etc rr methods to spec methods
|
13
|
+
MultiMock::Adapter.send(:include, RR::Extensions::InstanceMethods)
|
data/lib/multi_mock.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'adapters/unknown'
|
2
|
+
|
3
|
+
module MultiMock
|
4
|
+
def self.frameworks=(frameworks)
|
5
|
+
@frameworks = frameworks.collect { |f| framework(f) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.frameworks
|
9
|
+
@frameworks ||= []
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def self.framework(framework)
|
14
|
+
case framework
|
15
|
+
when Symbol, String
|
16
|
+
adapter(framework.to_s).new
|
17
|
+
when Module
|
18
|
+
MultiMock::Adapters::Unknown.new(framework)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.adapter(framework)
|
23
|
+
case framework
|
24
|
+
when /rspec/
|
25
|
+
require 'adapters/rspec'
|
26
|
+
MultiMock::Adapters::RSpec
|
27
|
+
when /mocha/
|
28
|
+
require 'adapters/mocha'
|
29
|
+
MultiMock::Adapters::Mocha
|
30
|
+
when /not_a_mock/
|
31
|
+
require 'adapters/not_a_mock'
|
32
|
+
MultiMock::Adapters::NotAMock
|
33
|
+
when /rr/
|
34
|
+
require 'adapters/rr'
|
35
|
+
MultiMock::Adapters::RR
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-multi-mock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Deepak N
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-28 00:00:00 +05:30
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
- 1
|
34
|
+
version: 1.3.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mocha
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 43
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 9
|
49
|
+
- 8
|
50
|
+
version: 0.9.8
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: not_a_mock
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - "="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 21
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 0
|
65
|
+
- 1
|
66
|
+
version: 1.0.1
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rr
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - "="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 19
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 0
|
81
|
+
- 2
|
82
|
+
version: 1.0.2
|
83
|
+
type: :development
|
84
|
+
version_requirements: *id004
|
85
|
+
description: Allows multiple mock frameworks to be in action in RSpec
|
86
|
+
email: endeep123@gmail.com
|
87
|
+
executables: []
|
88
|
+
|
89
|
+
extensions: []
|
90
|
+
|
91
|
+
extra_rdoc_files:
|
92
|
+
- README.rdoc
|
93
|
+
- LICENSE
|
94
|
+
files:
|
95
|
+
- README.rdoc
|
96
|
+
- lib/adapter.rb
|
97
|
+
- lib/adapters/mocha.rb
|
98
|
+
- lib/adapters/not_a_mock.rb
|
99
|
+
- lib/adapters/rr.rb
|
100
|
+
- lib/adapters/rspec.rb
|
101
|
+
- lib/adapters/unknown.rb
|
102
|
+
- lib/multi_mock.rb
|
103
|
+
- lib/rspec-multi-mock.rb
|
104
|
+
- LICENSE
|
105
|
+
has_rdoc: true
|
106
|
+
homepage: http://github.com/endeepak/rspec-multi-mock
|
107
|
+
licenses: []
|
108
|
+
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options:
|
111
|
+
- --main
|
112
|
+
- README.rdoc
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.4.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Multiple mock frameworks support for RSpec
|
140
|
+
test_files: []
|
141
|
+
|