rspec-spy_on 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e00f959800eae480bcf133cba5491e7605aa7810
4
+ data.tar.gz: 5b8708b21f181545e36d4c9bc2e9858a5fd64e54
5
+ SHA512:
6
+ metadata.gz: c8d61dca39e0f65511d5709951809ffff7ccff1ccb54606596e74293124bcfa7ea9b2bdd634132ccfdf4705658d460a135a30cefd81da6cbcb7a496ff73bbbba
7
+ data.tar.gz: d248fc9ec96dfa9fe08004e649dd8ad6305e5ff02c2feb44e872d0c84ccd87aec545c6d7c377cbd1a3568260ebffcc5cdc1240eadb975cb1d9f0a668da7f5efb
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ doc
7
+ tmp
8
+ rerun.txt
9
+ Gemfile.lock
10
+ .bundle
11
+ .idea
12
+ *.rbc
13
+ .yardoc
14
+ bin
15
+ Gemfile-custom
16
+ bundle
17
+ .rbx
18
+ .rspec-local
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ script: "bin/rake --trace 2>&1"
2
+ bundler_args: "--binstubs --without documentation"
3
+ before_install:
4
+ - gem update --system 2.1.11
5
+ - gem --version
6
+ - gem install bundler
7
+ rvm:
8
+ - 1.8.7
9
+ - 1.9.2
10
+ - 1.9.3
11
+ - 2.0.0
12
+ - 2.1.0
13
+ env:
14
+ - RSPEC_VERSION=2.14.1
15
+ - RSPEC_VERSION=2.99.0.beta1
16
+ - RSPEC_VERSION=3.0.0.beta1
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --no-private
2
+ --exclude features
3
+ --markup markdown
4
+ --template-path yard/template
5
+ -
6
+ README.md
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-spy_on.gemspec
4
+ gemspec
5
+
6
+ group :documentation do
7
+ gem 'yard', '0.8.7.3', :require => false
8
+ gem 'redcarpet', '2.3.0'
9
+ gem 'github-markup', '1.0.0'
10
+ end
11
+
12
+ case version = ENV['RSPEC_VERSION']
13
+ when nil, false, ''
14
+ gem 'rspec', '3.0.0.beta1'
15
+ else
16
+ gem 'rspec', version
17
+ end
18
+
19
+ # mime-types 2 is not compatible on ruby 1.8 so an old version is specified.
20
+ gem 'mime-types', '~> 1.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Thomas Holmes
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,45 @@
1
+ # Rspec::SpyOn [![Build Status](https://travis-ci.org/thomas-holmes/rspec-spy_on.png?branch=master)](https://travis-ci.org/thomas-holmes/rspec-spy_on)[![Coverage Status](https://coveralls.io/repos/thomas-holmes/rspec-spy_on/badge.png?branch=master)](https://coveralls.io/r/thomas-holmes/rspec-spy_on?branch=master)
2
+
3
+ RSpec::SpyOn allows easier setup of test spies through the use of the `spy_on` method
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rspec-spy_on'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rspec-spy_on
18
+
19
+ ## Usage
20
+
21
+ Instead of doing the following:
22
+
23
+ allow(dbl).to receive(:foo)
24
+ allow(dbl).to receive(:bar)
25
+
26
+ do_something_with(dbl)
27
+
28
+ expect(dbl).to have_received(:foo)
29
+ expect(dbl).to have_received(:bar)
30
+
31
+ You can instead do:
32
+
33
+ spy_on(dbl, :foo, :bar)
34
+
35
+ do_something_with(dbl)
36
+
37
+ expect(dbl).to have_received(:foo)
38
+ expect(dbl).to have_received(:bar)
39
+
40
+ Where this particularly comes in handy is when you need to spy with a real
41
+ instance of an object (what is known as a partial double).
42
+
43
+ When called on any ruby object that is not an `RSpec::Mocks::TestDouble` it
44
+ will automatically call `and_call_original` if the passed in object responds
45
+ to the desired message.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.ruby_opts = %w[-w]
8
+ t.rspec_opts = %w[--color]
9
+ end
10
+
11
+ task :default => [:spec]
@@ -0,0 +1,46 @@
1
+ module RSpec::SpyOn
2
+ module ExampleMethods
3
+ # Enables an RSpec::Mocks::TestDouble or any other object to act as
4
+ # a test spy. Delegates to RSpec::Mocks to configure the allowing of
5
+ # the messages
6
+ #
7
+ # In particular, `spy_on` makes this act of configuring real objects
8
+ # as spies easier by providing more concise syntax for configuring
9
+ # spying on multiple methods while forwarding the messages along
10
+ # to the original implementations.
11
+ #
12
+ # @example
13
+ # person = Person.new("Ally", 22)
14
+ # spy_on(person, :name, :age)
15
+ # # use `person` in a test
16
+ # expect(person).to have_received(:name)
17
+ # expect(person).to have_received(:age)
18
+ #
19
+ # @param target [Object/RSpec::Mocks::TestDouble] The object to be spied on
20
+ # @param messages [Array] Array of symbols for messages that should configured for spying
21
+ # @return (target)
22
+ def spy_on(target, *messages)
23
+ if target.is_a?(RSpec::Mocks::TestDouble)
24
+ messages.each { |m| RSpec::Mocks.allow_message(target, m) }
25
+ else
26
+ messages.each { |m| allow_partial(target, m) }
27
+ end
28
+ target
29
+ end
30
+
31
+ private
32
+ # If a non RSpec::Mocks::TestDouble is to be a spy then it any messags
33
+ # sent should be forwarded to the original object
34
+ #
35
+ # @private
36
+ def allow_partial(target, message)
37
+ if target.respond_to?(message)
38
+ RSpec::Mocks.allow_message(target, message).and_call_original
39
+ else
40
+ RSpec::Mocks.allow_message(target, message)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ RSpec.configuration.include RSpec::SpyOn::ExampleMethods
@@ -0,0 +1,5 @@
1
+ module Rspec
2
+ module SpyOn
3
+ VERSION = "0.0.1.pre"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec/core'
2
+ require 'rspec/mocks'
3
+
4
+ RSpec::configure do |c|
5
+ c.backtrace_exclusion_patterns << /lib\/rspec\/spy_on/
6
+ end
7
+
8
+ require 'rspec/spy_on/version'
9
+ require 'rspec/spy_on/example_methods'
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/spy_on/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-spy_on"
8
+ spec.version = Rspec::SpyOn::VERSION
9
+ spec.authors = ["Thomas Holmes"]
10
+ spec.email = ["thomas@holmes.io"]
11
+ spec.description = %q{Use test spies more easily with the `spy_on` method}
12
+ spec.summary = spec.description
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.files += %w[README.md LICENSE.txt .yardopts]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "rspec", ">= 2.14"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "simplecov"
26
+ spec.add_runtime_dependency "coveralls"
27
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe '#spy_on' do
4
+ context RSpec::Mocks::TestDouble do
5
+ let(:dbl) { double }
6
+
7
+ it 'creates an allowance' do
8
+ spy_on(dbl, :foo)
9
+ expect { dbl.foo }.to_not raise_error
10
+ end
11
+
12
+ it 'allows expectation of message to pass' do
13
+ spy_on(dbl, :foo)
14
+ dbl.foo
15
+ expect(dbl).to have_received(:foo)
16
+ end
17
+
18
+ it 'allows expectation of message to fail' do
19
+ spy_on(dbl, :foo)
20
+ expect do
21
+ expect(dbl).to have_received(:foo)
22
+ end.to raise_error(/received: 0/)
23
+ end
24
+ end
25
+
26
+ context RSpec::Mocks::Proxy do
27
+ let(:partial) { Widget.new('Floobit', :medium) }
28
+
29
+ it 'can create an allowance on non-existing method' do
30
+ spy_on(partial, :foo)
31
+ expect { partial.foo }.to_not raise_error
32
+ end
33
+
34
+ it 'calls original implementation if one exists' do
35
+ spy_on(partial, :name)
36
+ expect(partial.name).to eq 'Floobit'
37
+ end
38
+
39
+ it 'allows expectation on message to pass' do
40
+ spy_on(partial, :name)
41
+ partial.name
42
+ expect(partial).to have_received(:name)
43
+ end
44
+
45
+ it 'allows expectation on message to fail' do
46
+ spy_on(partial, :name)
47
+ expect do
48
+ expect(partial).to have_received(:name)
49
+ end.to raise_error(/received: 0/)
50
+ end
51
+
52
+ it 'does not observe calls to on methods not spied on' do
53
+ spy_on(partial, :name)
54
+ expect do
55
+ expect(partial).to have_received(:size)
56
+ end.to raise_error(/not been stubbed/)
57
+ end
58
+ end
59
+ end
60
+
61
+ class Widget
62
+ attr_accessor :name, :size
63
+ def initialize(name, size)
64
+ @name = name
65
+ @size = size
66
+ end
67
+ end
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ if ENV['CI']
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+ end
7
+
8
+ require 'rspec/spy_on'
@@ -0,0 +1,20 @@
1
+ .notetag {
2
+ background-color: #FFE5E5;
3
+ }
4
+
5
+ code {
6
+ background-color: #F0F0F0;
7
+ padding: 0 2px 0 2px;
8
+ }
9
+
10
+ .deprecated code {
11
+ background-color: #FFA8A8;
12
+ }
13
+
14
+ .summary_desc code {
15
+ background-color: #F0F0F0;
16
+ }
17
+
18
+ .notetag code {
19
+ background-color: #FFA8A8;
20
+ }
@@ -0,0 +1,6 @@
1
+ # Docs suggest I don't need this, but ...
2
+ YARD::Server::Commands::StaticFileCommand::STATIC_PATHS << File.expand_path("../../../fulldoc/html/", __FILE__)
3
+
4
+ def stylesheets
5
+ super + ['css/rspec.css']
6
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-spy_on
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Holmes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-05 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: '2.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '2.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Use test spies more easily with the `spy_on` method
84
+ email:
85
+ - thomas@holmes.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - .yardopts
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/rspec/spy_on.rb
99
+ - lib/rspec/spy_on/example_methods.rb
100
+ - lib/rspec/spy_on/version.rb
101
+ - rspec-spy_on.gemspec
102
+ - spec/rspec/spy_on/spy_on_spec.rb
103
+ - spec/spec_helper.rb
104
+ - yard/template/default/fulldoc/html/css/rspec.css
105
+ - yard/template/default/layout/html/setup.rb
106
+ homepage: ''
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>'
122
+ - !ruby/object:Gem::Version
123
+ version: 1.3.1
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.1.11
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Use test spies more easily with the `spy_on` method
130
+ test_files:
131
+ - spec/rspec/spy_on/spy_on_spec.rb
132
+ - spec/spec_helper.rb
133
+ has_rdoc: