return_spy 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: 30781a7ab4622693b72cf18f9f71a125748862fe
4
+ data.tar.gz: 3692342b62f446147591541570253010154112de
5
+ SHA512:
6
+ metadata.gz: 26616bc20a78d2f4d1f1166b9ce18eb02172fc95b7395db5db6cd90377526d1423ff1ab4c05c2f1214223ae7e58e772f7f108d02942c016a8c567186b307b03c
7
+ data.tar.gz: 7c9de60797b501d60fad306e1c6f5971ce01af783b38531ca8d42bc48e7b40a780f78422615db8c9edeaf31a8ebc5f59dfcb801099f67a14b07c0e2135d465b1
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in return_spy.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Alexey Fedorov
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,31 @@
1
+ # ReturnSpy
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'return_spy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install return_spy
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/return_spy/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,12 @@
1
+ require 'return_spy/object'
2
+ require 'return_spy/module'
3
+
4
+ class Y
5
+ def greet(name) "hello, #{name}!" end
6
+
7
+ def self.greet(name) "hallo, #{name}!" end
8
+
9
+ class << self
10
+ def eigen_greet(name) "eigen hello, #{name}!" end
11
+ end
12
+ end
@@ -0,0 +1,65 @@
1
+ require "return_spy/version"
2
+
3
+ require "securerandom"
4
+
5
+ require "return_spy/support"
6
+ require "return_spy/decorator"
7
+
8
+ module ReturnSpy
9
+ class << self
10
+ def active?
11
+ @active
12
+ end
13
+
14
+ def activate!
15
+ @active = true
16
+ end
17
+
18
+ def deactivate!
19
+ @active = false
20
+ end
21
+
22
+ def without_return_spy
23
+ active = active?
24
+ deactivate!
25
+ yield
26
+ activate! if active
27
+ end
28
+
29
+ def expectations
30
+ @_expectations ||= []
31
+ end
32
+ end
33
+
34
+ activate!
35
+
36
+ def method_added(name)
37
+ common_method_added(name, Decorator::InstanceMethod)
38
+ end
39
+
40
+ def singleton_method_added(name)
41
+ common_method_added(name, Decorator::SingletonMethod)
42
+ end
43
+
44
+ private
45
+
46
+ def common_method_added(name, decorate_strategy)
47
+ return unless ReturnSpy.active?
48
+ new_name = Support.unique_name(name)
49
+
50
+ ReturnSpy.without_return_spy do
51
+ decorate_strategy.decorate(self, name, new_name) do |*args, &blk|
52
+ result = send(new_name, *args, &blk)
53
+
54
+ ReturnSpy.expectations.each do |expectation|
55
+ next unless expectation === result
56
+ puts "RETURN_SPY: #{self}::#{name} with #{args + [blk]} :: #{result.inspect}"
57
+ break
58
+ end
59
+
60
+ result
61
+ end
62
+ end
63
+ end
64
+ end
65
+
@@ -0,0 +1,24 @@
1
+ module ReturnSpy
2
+ module Decorator
3
+ module InstanceMethod
4
+ def self.decorate(target, name, new_name, &blk)
5
+ target.class_eval do
6
+ alias_method(new_name, name)
7
+ define_method(name, &blk)
8
+ end
9
+ end
10
+ end
11
+
12
+ module SingletonMethod
13
+ def self.decorate(target, name, new_name, &blk)
14
+ target.class_eval do
15
+ eigen = class << self; self end
16
+ eigen.class_eval do
17
+ alias_method(new_name, name)
18
+ define_method(name, &blk)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ class Module
2
+ extend ReturnSpy
3
+ end
@@ -0,0 +1,5 @@
1
+ require "return_spy"
2
+
3
+ class Object
4
+ extend ReturnSpy
5
+ end
@@ -0,0 +1,9 @@
1
+ module ReturnSpy
2
+ module Support
3
+ class << self
4
+ def unique_name(name)
5
+ :"__return_spy_#{name}_#{SecureRandom.hex(8)}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ReturnSpy
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'return_spy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "return_spy"
8
+ spec.version = ReturnSpy::VERSION
9
+ spec.authors = ["Alexey Fedorov"]
10
+ spec.email = ["waterlink000@gmail.com"]
11
+ spec.summary = %q{Spies all return values from functions, allows to set up expectations on them}
12
+ spec.description = %q{Spies all return values from functions, allows to set up expectations on them. Used majorly for debugging and code-finding.}
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: return_spy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexey Fedorov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-26 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Spies all return values from functions, allows to set up expectations
42
+ on them. Used majorly for debugging and code-finding.
43
+ email:
44
+ - waterlink000@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - example.rb
55
+ - lib/return_spy.rb
56
+ - lib/return_spy/decorator.rb
57
+ - lib/return_spy/module.rb
58
+ - lib/return_spy/object.rb
59
+ - lib/return_spy/support.rb
60
+ - lib/return_spy/version.rb
61
+ - return_spy.gemspec
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Spies all return values from functions, allows to set up expectations on
86
+ them
87
+ test_files: []