rspec-context-doubles 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1dcc4291274a35b3f51cc82af3ffd0f810f10b7d
4
+ data.tar.gz: 2bb1b92616ad889463749faac87d252180c897fa
5
+ SHA512:
6
+ metadata.gz: b06e348775ee067c0cb719b2b9adfe20f842de9df116a0a906bb3d9d2cb9c53169e109ac3e0259e926235bcc377963fde7f7b585556be632f1921f02cb144b15
7
+ data.tar.gz: f05d9d5d8f9391a7da713b80ed2005d75cd77b37a372dd00dd295fa5c69ce035353b3553496f06876142a8586573aa57561dd94eb4881c22dba55efa50983e61
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-context-doubles.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sean Devine
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.
@@ -0,0 +1,75 @@
1
+ ## rspec-context-doubles
2
+
3
+ Temporarily configure `RSpec` to use a different type of doubles.
4
+
5
+ ### Why would you want to do that?
6
+
7
+ Here is the one that resulted in this library:
8
+
9
+ If you use `Rails` and add a helper method from a controller (or use a gem like `canable` that does), `RSpec` will raise an error when one of those helper methods is stubbed in a view spec if it is configured to use verifying doubles.
10
+
11
+ ### How do you use it?
12
+
13
+ Just pass `:normal_doubles` or `:verifying_doubles` as metadata to a `describe` block and you'll temporarily set the behavior for the examples in that block.
14
+
15
+ ```ruby
16
+ # spec_helper.rb
17
+ # ...
18
+ config.mock_with :rspec do |mocks|
19
+ mocks.verify_partial_doubles = true
20
+ end
21
+ # ...
22
+ ```
23
+
24
+ ```ruby
25
+ # Gemfile
26
+ group :test do
27
+ gem "rspec-context-doubles"
28
+ end
29
+ ```
30
+
31
+ ```ruby
32
+ # example.rb
33
+ class Example
34
+ def foo; end
35
+ end
36
+ ```
37
+
38
+ ```ruby
39
+ # example_spec.rb
40
+ describe Example do
41
+ context "configured to use verifying doubles" do
42
+ before(:all) { RSpec::Mocks.configuration.verify_partial_doubles = true }
43
+
44
+ describe "temporarily using normal doubles", :normal_doubles do
45
+ it "does not raise an error when a non-existent method is stubbed" do
46
+ expect{allow(subject).to receive(:fo)}.to_not raise_error
47
+ end
48
+ end
49
+ it "raises an error when a non-existent method is stubbed" do
50
+ expect{allow(subject).to receive(:fo)}.to raise_error(RSpec::Mocks::MockExpectationError)
51
+ end
52
+ end
53
+
54
+ context "configured to use normal doubles" do
55
+ before(:all) { RSpec::Mocks.configuration.verify_partial_doubles = false }
56
+
57
+ describe "temporarily using verifying doubles", :verifying_doubles do
58
+ it "raises an error if a non-existent method is stubbed" do
59
+ expect{allow(subject).to receive(:fo)}.to raise_error(RSpec::Mocks::MockExpectationError)
60
+ end
61
+ end
62
+ it "does not raise an error when a non-existent method is stubbed" do
63
+ expect{allow(subject).to receive(:fo)}.to_not raise_error
64
+ end
65
+ end
66
+ end
67
+ ```
68
+
69
+ ### Credits
70
+
71
+ Written by [@barelyknown](http://twitter.com/barelyknown).
72
+
73
+ This gem uses [RSpec's shared context feature](https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-context).
74
+
75
+ The idea for the gem came from [this rspec-mocks issue](https://github.com/rspec/rspec-mocks/issues/633).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
1
+ require "rspec/core"
2
+
3
+ require_relative "doubles/version"
4
+ require_relative "doubles/doubles"
5
+
6
+ module Rspec
7
+ module Context
8
+ module Doubles
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ RSpec.shared_context 'normal doubles', normal_doubles: true do
2
+
3
+ before :all do
4
+ @partial_doubles_configuration = RSpec::Mocks.configuration.verify_partial_doubles?
5
+ RSpec::Mocks.configuration.verify_partial_doubles = false
6
+ end
7
+
8
+ after :all do
9
+ RSpec::Mocks.configuration.verify_partial_doubles = @partial_doubles_configuration
10
+ end
11
+
12
+ end
13
+
14
+ RSpec.shared_context "verifying doubles", verifying_doubles: true do
15
+
16
+ before :all do
17
+ @partial_doubles_configuration = RSpec::Mocks.configuration.verify_partial_doubles?
18
+ RSpec::Mocks.configuration.verify_partial_doubles = true
19
+ end
20
+
21
+ after :all do
22
+ RSpec::Mocks.configuration.verify_partial_doubles = @partial_doubles_configuration
23
+ end
24
+
25
+ end
@@ -0,0 +1,7 @@
1
+ module Rspec
2
+ module Context
3
+ module Doubles
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/context/doubles/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-context-doubles"
8
+ spec.version = Rspec::Context::Doubles::VERSION
9
+ spec.authors = ["Sean Devine"]
10
+ spec.email = ["barelyknown@icloud.com"]
11
+ spec.summary = %q{Temporarily toggle the behavior of doubles for an RSpec example group.}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", ">=3.0.0"
24
+ end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ class Example
4
+ def foo; end
5
+ end
6
+
7
+ describe Example do
8
+ context "configured to use verifying doubles" do
9
+ before(:all) { RSpec::Mocks.configuration.verify_partial_doubles = true }
10
+
11
+ describe "temporarily using normal doubles", :normal_doubles do
12
+ it "does not raise an error when a non-existent method is stubbed" do
13
+ expect{allow(subject).to receive(:fo)}.to_not raise_error
14
+ end
15
+ end
16
+ it "raises an error when a non-existent method is stubbed" do
17
+ expect{allow(subject).to receive(:fo)}.to raise_error(RSpec::Mocks::MockExpectationError)
18
+ end
19
+ end
20
+
21
+ context "configured to use normal doubles" do
22
+ before(:all) { RSpec::Mocks.configuration.verify_partial_doubles = false }
23
+
24
+ describe "temporarily using verifying doubles", :verifying_doubles do
25
+ it "raises an error if a non-existent method is stubbed" do
26
+ expect{allow(subject).to receive(:fo)}.to raise_error(RSpec::Mocks::MockExpectationError)
27
+ end
28
+ end
29
+ it "does not raise an error when a non-existent method is stubbed" do
30
+ expect{allow(subject).to receive(:fo)}.to_not raise_error
31
+ end
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ require 'rspec/context/doubles'
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-context-doubles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Devine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ description: Temporarily toggle the behavior of doubles for an RSpec example group.
56
+ email:
57
+ - barelyknown@icloud.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/rspec/context/doubles.rb
68
+ - lib/rspec/context/doubles/doubles.rb
69
+ - lib/rspec/context/doubles/version.rb
70
+ - rspec-context-doubles.gemspec
71
+ - spec/lib/rspec/context/doubles/doubles_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Temporarily toggle the behavior of doubles for an RSpec example group.
97
+ test_files:
98
+ - spec/lib/rspec/context/doubles/doubles_spec.rb
99
+ - spec/spec_helper.rb
100
+ has_rdoc: