rspec_stubout 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/README.md +22 -0
- data/Rakefile +7 -0
- data/lib/rspec_stubout/prevent_stubout.rb +17 -0
- data/lib/rspec_stubout/version.rb +5 -0
- data/rspec_stubout.gemspec +21 -0
- data/spec/rspec_stubout_spec.rb +67 -0
- data/spec/spec_helper.rb +7 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjI3NTRlZjE4YzAzMzNjMjllMzc3N2I3ODE4OWNlMGYwZGVmMDY0OA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjQ4NDZmMGEyZjcwZjE2ZDEzZWE5ZmYzNmYzNjhiZjEwZjE5MmVjNA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzcyMmRhMWJiYTRmN2E5ZTJiODI2ZWFhMTkxYzE5MDE1ZjJiNjkzNjZkZjll
|
10
|
+
NDY0NTgyZTk4NDdjYzAyOGYwOTU1YmEyNDMxNDc2NjI5YTlhMGU2OTY0ZDE4
|
11
|
+
ODQ4Y2QzODBkMmRhMjYxZjNiYmJkNjZlNWRlZTY5YjE1MzE2ZWI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGFiYmJmYmFhYWE5OGMxNzM0NDQyMmJiNGQ5YzRmNTVjYjBjNDdmYTU4N2Ri
|
14
|
+
MzQ0NjA3ZThlNzVmNGU5ZDdjYzUzMGJjNWVmYWQ0MWYyN2ExZDYzMGE4NDRi
|
15
|
+
ZDNmMzNiOGNkYTUzYTEyOTM5NDBjZWExYTc1ODc0ZTIyZDk0MWM=
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/mmb/rspec_stubout.png)](https://travis-ci.org/mmb/rspec_stubout) [![Code Climate](https://codeclimate.com/github/mmb/rspec_stubout.png)](https://codeclimate.com/github/mmb/rspec_stubout)
|
2
|
+
|
3
|
+
Make your RSpec specs fail when you stub the object under test (subject) because it is bad practice.
|
4
|
+
|
5
|
+
In your spec_helper.rb:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'rspec_stubout/prevent_stubout'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
RspecStubout.prevent_stubout(config)
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
To turn it off for some examples, allowing them to stub subject:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
|
19
|
+
it 'stubs subject', allow_stubout: true do
|
20
|
+
subject.stub(method1: 'foo')
|
21
|
+
end
|
22
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module RspecStubout
|
4
|
+
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def prevent_stubout(rspec_config)
|
8
|
+
rspec_config.before(:each) do
|
9
|
+
unless example.metadata[:allow_stubout]
|
10
|
+
subject.stub(:stub) do
|
11
|
+
raise "#{subject.inspect} is the object under test and should not be stubbed"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
4
|
+
|
5
|
+
require 'rspec_stubout/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'rspec_stubout'
|
9
|
+
s.version = RspecStubout::VERSION
|
10
|
+
s.summary = 'Fail RSpec specs that stub the object under test.'
|
11
|
+
s.description = s.summary
|
12
|
+
s.homepage = 'https://github.com/mmb/rspec_stubout'
|
13
|
+
s.authors = ['Matthew M. Boedicker']
|
14
|
+
s.email = %w{matthewm@boedicker.org}
|
15
|
+
|
16
|
+
s.add_dependency 'rspec'
|
17
|
+
|
18
|
+
s.add_development_dependency 'rake'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RspecStubout do
|
6
|
+
|
7
|
+
subject { 'subject' }
|
8
|
+
|
9
|
+
context 'sending stub to subject' do
|
10
|
+
|
11
|
+
it 'raises an error' do
|
12
|
+
expect {
|
13
|
+
subject.stub(method1: 'foo')
|
14
|
+
}.to raise_error(
|
15
|
+
'"subject" is the object under test and should not be stubbed')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'sending stub_chain to subject' do
|
21
|
+
|
22
|
+
it 'raises an error' do
|
23
|
+
expect {
|
24
|
+
subject.stub_chain(:method1, :method2) { 'foo' }
|
25
|
+
}.to raise_error(
|
26
|
+
'"subject" is the object under test and should not be stubbed')
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when subject is not stubbed directly' do
|
32
|
+
|
33
|
+
let(:object) { 'subject' }
|
34
|
+
subject { object }
|
35
|
+
|
36
|
+
it 'raises an error' do
|
37
|
+
expect {
|
38
|
+
object.stub(method1: 'foo')
|
39
|
+
}.to raise_error(
|
40
|
+
'"subject" is the object under test and should not be stubbed')
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when using a named subject' do
|
46
|
+
|
47
|
+
subject(:object) { 'subject' }
|
48
|
+
|
49
|
+
it 'raises an error' do
|
50
|
+
expect {
|
51
|
+
object.stub(method1: 'foo')
|
52
|
+
}.to raise_error(
|
53
|
+
'"subject" is the object under test and should not be stubbed')
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when the spec is tagged with allow_stubout' do
|
59
|
+
|
60
|
+
it 'does not raise an error when subject is stubbed',
|
61
|
+
allow_stubout: true do
|
62
|
+
subject.stub(method1: 'foo')
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_stubout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew M. Boedicker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Fail RSpec specs that stub the object under test.
|
42
|
+
email:
|
43
|
+
- matthewm@boedicker.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .travis.yml
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/rspec_stubout/prevent_stubout.rb
|
53
|
+
- lib/rspec_stubout/version.rb
|
54
|
+
- rspec_stubout.gemspec
|
55
|
+
- spec/rspec_stubout_spec.rb
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
homepage: https://github.com/mmb/rspec_stubout
|
58
|
+
licenses: []
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.0.4
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Fail RSpec specs that stub the object under test.
|
80
|
+
test_files: []
|
81
|
+
has_rdoc:
|