jrsplenda 0.1.0
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.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +46 -0
- data/PostInstall.txt +7 -0
- data/README.txt +23 -0
- data/Rakefile +27 -0
- data/build.xml +15 -0
- data/config/hoe.rb +75 -0
- data/config/requirements.rb +15 -0
- data/lib/jrsplenda.rb +36 -0
- data/lib/jrsplenda/jrsplenda_field_helper.rb +43 -0
- data/lib/jrsplenda/jrsplenda_method_helper.rb +35 -0
- data/lib/jrsplenda/jrsplenda_mock_helper.rb +34 -0
- data/lib/jrsplenda/mocha/jrsplenda_mocha_support.rb +108 -0
- data/lib/jrsplenda/version.rb +9 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/spec/field_helper_spec.rb +96 -0
- data/spec/fixtures/PackageField.java +12 -0
- data/spec/fixtures/PackageInstanceMethod.java +7 -0
- data/spec/fixtures/PackageStaticMethod.java +7 -0
- data/spec/fixtures/PrivateField.java +12 -0
- data/spec/fixtures/PrivateInstanceMethod.java +7 -0
- data/spec/fixtures/PrivateStaticMethod.java +7 -0
- data/spec/fixtures/ProtectedField.java +12 -0
- data/spec/fixtures/ProtectedInstanceMethod.java +7 -0
- data/spec/fixtures/ProtectedStaticMethod.java +7 -0
- data/spec/fixtures/PublicField.java +9 -0
- data/spec/method_helper_spec.rb +45 -0
- data/spec/mock_helper_spec.rb +42 -0
- data/spec/spec_helper.rb +5 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +11 -0
- data/website/index.txt +83 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +107 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Evan David Light
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
build.xml
|
2
|
+
config/hoe.rb
|
3
|
+
config/requirements.rb
|
4
|
+
History.txt
|
5
|
+
lib/jrsplenda
|
6
|
+
lib/jrsplenda/jrsplenda_field_helper.rb
|
7
|
+
lib/jrsplenda/jrsplenda_method_helper.rb
|
8
|
+
lib/jrsplenda/jrsplenda_mock_helper.rb
|
9
|
+
lib/jrsplenda/mocha
|
10
|
+
lib/jrsplenda/mocha/jrsplenda_mocha_support.rb
|
11
|
+
lib/jrsplenda/version.rb
|
12
|
+
lib/jrsplenda.rb
|
13
|
+
License.txt
|
14
|
+
Manifest.txt
|
15
|
+
PostInstall.txt
|
16
|
+
Rakefile
|
17
|
+
README.txt
|
18
|
+
script/console
|
19
|
+
script/destroy
|
20
|
+
script/generate
|
21
|
+
script/txt2html
|
22
|
+
setup.rb
|
23
|
+
spec/field_helper_spec.rb
|
24
|
+
spec/fixtures/PackageField.java
|
25
|
+
spec/fixtures/PackageInstanceMethod.java
|
26
|
+
spec/fixtures/PackageStaticMethod.java
|
27
|
+
spec/fixtures/PrivateField.java
|
28
|
+
spec/fixtures/PrivateInstanceMethod.java
|
29
|
+
spec/fixtures/PrivateStaticMethod.java
|
30
|
+
spec/fixtures/ProtectedField.java
|
31
|
+
spec/fixtures/ProtectedInstanceMethod.java
|
32
|
+
spec/fixtures/ProtectedStaticMethod.java
|
33
|
+
spec/fixtures/PublicField.java
|
34
|
+
spec/method_helper_spec.rb
|
35
|
+
spec/mock_helper_spec.rb
|
36
|
+
spec/spec_helper.rb
|
37
|
+
tasks/deployment.rake
|
38
|
+
tasks/environment.rake
|
39
|
+
tasks/website.rake
|
40
|
+
website/index.html
|
41
|
+
website/index.txt
|
42
|
+
website/javascripts
|
43
|
+
website/javascripts/rounded_corners_lite.inc.js
|
44
|
+
website/stylesheets
|
45
|
+
website/stylesheets/screen.css
|
46
|
+
website/template.html.erb
|
data/PostInstall.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
= jrsplenda
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Sweetens up Mocha under JRuby to simplify the testing of Java code from JRuby
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* TBD
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
* TBD
|
16
|
+
|
17
|
+
== INSTALL:
|
18
|
+
|
19
|
+
* sudo gem install jrsplenda
|
20
|
+
|
21
|
+
== LICENSE:
|
22
|
+
|
23
|
+
* See LICENSE file for details
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'config/requirements'
|
2
|
+
require 'config/hoe' # setup Hoe + all gem configuration
|
3
|
+
require 'spec'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
7
|
+
|
8
|
+
def ant(*args)
|
9
|
+
system "ant -logger org.apache.tools.ant.NoBannerLogger #{args.join(' ')}"
|
10
|
+
end
|
11
|
+
|
12
|
+
task :build_fixtures do
|
13
|
+
puts "Building fixtures..."
|
14
|
+
ant "build_fixtures"
|
15
|
+
system "jar cf build/jrsplenda-fixtures.jar -C build/classes ."
|
16
|
+
end
|
17
|
+
|
18
|
+
Spec::Rake::SpecTask.new :spec => [:build_fixtures] do |t|
|
19
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
20
|
+
end
|
21
|
+
|
22
|
+
Spec::Rake::SpecTask.new :specdoc => [:build_fixtures] do |t|
|
23
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
24
|
+
t.spec_opts = ['--format=specdoc']
|
25
|
+
end
|
26
|
+
|
27
|
+
|
data/build.xml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<project>
|
2
|
+
<property name="src" location="spec/fixtures" />
|
3
|
+
<property name="jar_path" location="build/jrsplenda-fixtures.jar" />
|
4
|
+
|
5
|
+
<target name="build_fixtures">
|
6
|
+
<mkdir dir="build" />
|
7
|
+
<mkdir dir="build/classes" />
|
8
|
+
<javac srcdir="${src}" destdir="build/classes"/>
|
9
|
+
</target>
|
10
|
+
|
11
|
+
<target name="clean">
|
12
|
+
<delete dir="build" />
|
13
|
+
<delete file ="${jar_path}" />
|
14
|
+
</target>
|
15
|
+
</project>
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'jrsplenda/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Evan David Light'
|
4
|
+
EMAIL = "evan@tiggerpalace.com"
|
5
|
+
DESCRIPTION = "Sweetens up Moch under JRuby to simplify the testing of Java code from JRuby"
|
6
|
+
GEM_NAME = 'jrsplenda'
|
7
|
+
RUBYFORGE_PROJECT = 'jrsplenda'
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
['active_support', '>= 2.0.2'],
|
12
|
+
['mocha', '>= 0.5.6'],
|
13
|
+
['rspec', '>= 1.1.3']
|
14
|
+
] # An array of rubygem dependencies [name, version]
|
15
|
+
|
16
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
17
|
+
@config = nil
|
18
|
+
RUBYFORGE_USERNAME = "sleight42"
|
19
|
+
def rubyforge_username
|
20
|
+
unless @config
|
21
|
+
begin
|
22
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
23
|
+
rescue
|
24
|
+
puts <<-EOS
|
25
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
26
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
27
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
28
|
+
EOS
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
end
|
32
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
REV = nil
|
37
|
+
# UNCOMMENT IF REQUIRED:
|
38
|
+
# REV = YAML.load(`svn info`)['Revision']
|
39
|
+
VERS = JRSplenda::VERSION::STRING + (REV ? ".#{REV}" : "")
|
40
|
+
RDOC_OPTS = ['--quiet', '--title', 'jrsplenda documentation',
|
41
|
+
"--opname", "index.html",
|
42
|
+
"--line-numbers",
|
43
|
+
"--main", "README.txt",
|
44
|
+
"--inline-source"]
|
45
|
+
|
46
|
+
class Hoe
|
47
|
+
def extra_deps
|
48
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
49
|
+
@extra_deps
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Generate all the Rake tasks
|
54
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
55
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
56
|
+
p.developer(AUTHOR, EMAIL)
|
57
|
+
p.description = DESCRIPTION
|
58
|
+
p.summary = DESCRIPTION
|
59
|
+
p.url = HOMEPATH
|
60
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
61
|
+
# p.test_globs = ["test/**/test_*.rb"]
|
62
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
63
|
+
|
64
|
+
# == Optional
|
65
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
66
|
+
#p.extra_deps = EXTRA_DEPENDENCIES
|
67
|
+
|
68
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
69
|
+
end
|
70
|
+
|
71
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
72
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
73
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
74
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
75
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/lib/jrsplenda.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
def load_gem(gem_name, main_src = gem_name)
|
5
|
+
begin
|
6
|
+
require main_src
|
7
|
+
rescue LoadError
|
8
|
+
require 'rubygems'
|
9
|
+
gem gem_name
|
10
|
+
require main_src
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def using_jtestr?
|
15
|
+
begin
|
16
|
+
@jtestr = Object.const_get 'JtestR'
|
17
|
+
rescue
|
18
|
+
@jtestr = false
|
19
|
+
end
|
20
|
+
@jtestr
|
21
|
+
end
|
22
|
+
|
23
|
+
load_gem 'activesupport', 'active_support'
|
24
|
+
load_gem 'mocha'
|
25
|
+
|
26
|
+
|
27
|
+
# Ola's JRuby Mocha Monkey Patch (now say that 20 times quickly)
|
28
|
+
unless using_jtestr?
|
29
|
+
require File.dirname(__FILE__) + "/jrsplenda/mocha/jrsplenda_mocha_support.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
# The sweetener
|
33
|
+
$LOAD_PATH << (File.dirname(__FILE__) + "/jrsplenda")
|
34
|
+
require 'jrsplenda_mock_helper'
|
35
|
+
require 'jrsplenda_field_helper'
|
36
|
+
require 'jrsplenda_method_helper'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
import 'java.lang.reflect.Modifier'
|
4
|
+
|
5
|
+
module JRSplenda
|
6
|
+
module FieldHelper
|
7
|
+
def wrap_java_fields(object)
|
8
|
+
if object.is_a?(Class)
|
9
|
+
klass = object
|
10
|
+
message = :java_class
|
11
|
+
else
|
12
|
+
klass = object.class
|
13
|
+
message = :java_object
|
14
|
+
end
|
15
|
+
klass.java_class.declared_fields.each do |field|
|
16
|
+
next if field.modifiers & (Modifier::PUBLIC | Modifier::FINAL) != 0
|
17
|
+
method_name = "#{field.name.underscore}="
|
18
|
+
object.singleton_class.send :define_method, method_name do |val|
|
19
|
+
field.accessible = true
|
20
|
+
field.set_value(send(message), val.java_object)
|
21
|
+
field.accessible = false
|
22
|
+
end
|
23
|
+
object.singleton_class.send :alias_method, field.name + "=", method_name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
[String, NilClass].each do |klass|
|
30
|
+
klass.class_eval do
|
31
|
+
unless method_defined? :java_object
|
32
|
+
define_method(:java_object) do
|
33
|
+
Java.ruby_to_java(self)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Object
|
40
|
+
def singleton_class
|
41
|
+
class << self; self; end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
import 'java.lang.reflect.Modifier'
|
4
|
+
|
5
|
+
module JRSplenda
|
6
|
+
module MethodHelper
|
7
|
+
def wrap_java_methods(object)
|
8
|
+
if object.is_a?(Class)
|
9
|
+
klass = object
|
10
|
+
message = :java_class
|
11
|
+
method_type = :declared_class_methods
|
12
|
+
else
|
13
|
+
klass = object.class
|
14
|
+
message = :java_object
|
15
|
+
method_type = :declared_instance_methods
|
16
|
+
end
|
17
|
+
uniq_method_names = klass.java_class.send(method_type).collect(&:name)
|
18
|
+
uniq_method_names.each do |method_name|
|
19
|
+
method = klass.java_class.declared_method_smart(method_name)
|
20
|
+
next if method.modifiers & (Modifier::PUBLIC | Modifier::FINAL) != 0
|
21
|
+
ruby_method_name = "#{method.name.underscore}"
|
22
|
+
object.singleton_class.send :define_method, ruby_method_name do |*args|
|
23
|
+
method.accessible = true
|
24
|
+
if method.modifiers & Modifier::STATIC != 0
|
25
|
+
method.invoke_static(*args)
|
26
|
+
else
|
27
|
+
method.invoke(send(message), *args)
|
28
|
+
end
|
29
|
+
method.accessible = false
|
30
|
+
end
|
31
|
+
object.singleton_class.send(:alias_method, method_name, ruby_method_name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module JRSplenda
|
4
|
+
module MockHelper
|
5
|
+
def splenda_mock(arg)
|
6
|
+
arg = java_class_as_string(arg)
|
7
|
+
# Consider whether we really want to import; may want to avoid overlap. Import by default?
|
8
|
+
import arg
|
9
|
+
vendor_mock Module.const_get(arg.split('.').last)
|
10
|
+
end
|
11
|
+
|
12
|
+
def splenda_mock_attr(arg, options = {})
|
13
|
+
default_field_name = java_class_as_string(arg).split('.').last.underscore
|
14
|
+
attr_name = "@" + options.fetch(:store_in, default_field_name).to_s
|
15
|
+
should_preserve_attr = options[:preserve_existing_attr]
|
16
|
+
current_attr_val = instance_variable_get(attr_name)
|
17
|
+
unless current_attr_val && should_preserve_attr
|
18
|
+
instance_variable_set(attr_name, splenda_mock(arg))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
# default is Mocha but monkey-patch this to support other mock types
|
24
|
+
def vendor_mock(arg)
|
25
|
+
mock arg.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def java_class_as_string(arg)
|
29
|
+
arg = arg.java_class if arg.respond_to? :java_class
|
30
|
+
arg.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# Borrowed from Ola Bini's "JtestR" -- under MIT license
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'mocha', 'lib')
|
4
|
+
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
module JtestR
|
8
|
+
module Mocha
|
9
|
+
METHODS_TO_LEAVE_ALONE = [
|
10
|
+
# Things for internal Ruby
|
11
|
+
'__id__', '__send__', '__metaclass__', '==', 'inspect',
|
12
|
+
'__is_a__', 'equals', 'respond_to?', 'class', 'methods',
|
13
|
+
'send', 'equal?', 'eql?', 'to_s',
|
14
|
+
# Things for Java Integration
|
15
|
+
'__jcreate!', '__jsend!', 'java_object=', 'java_object',
|
16
|
+
'to_java_object',
|
17
|
+
# Things for Mocha
|
18
|
+
'mocha', 'reset_mocha', 'stubba_method',
|
19
|
+
'stubba_object', 'expects', 'stubs', 'verify',
|
20
|
+
# Things for RSpec
|
21
|
+
'should', 'should_not'
|
22
|
+
]
|
23
|
+
def self.revert_mocking(clazz)
|
24
|
+
clazz.instance_variable_set :@mocking_classes, nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.create_mocking(clazz, preserved_methods = JtestR::Mocha::METHODS_TO_LEAVE_ALONE)
|
28
|
+
preserved_methods = preserved_methods.is_a?(Symbol) ? preserved_methods : preserved_methods.sort.uniq
|
29
|
+
case clazz
|
30
|
+
when Class
|
31
|
+
c = clazz.instance_variable_get :@mocking_classes
|
32
|
+
unless c
|
33
|
+
c = { }
|
34
|
+
clazz.instance_variable_set :@mocking_classes, c
|
35
|
+
end
|
36
|
+
unless c[preserved_methods]
|
37
|
+
clz = Class.new(clazz)
|
38
|
+
clz.class_eval do
|
39
|
+
undef_method *(public_instance_methods - preserved_methods)
|
40
|
+
end unless preserved_methods == :preserve_all
|
41
|
+
c[preserved_methods] = clz
|
42
|
+
end
|
43
|
+
when Module
|
44
|
+
# Maybe actually implement methods for modules here, at some point? Hmm
|
45
|
+
|
46
|
+
c = clazz.instance_variable_get :@mocking_classes
|
47
|
+
unless c
|
48
|
+
c = { }
|
49
|
+
clazz.instance_variable_set :@mocking_classes, c
|
50
|
+
end
|
51
|
+
unless c[preserved_methods]
|
52
|
+
clz = Class.new
|
53
|
+
clz.send :include, clazz
|
54
|
+
clz.class_eval do
|
55
|
+
undef_method *(public_instance_methods - preserved_methods)
|
56
|
+
end unless preserved_methods == :preserve_all
|
57
|
+
c[preserved_methods] = clz
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.mocking_class(clazz, preserved_methods = JtestR::Mocha::METHODS_TO_LEAVE_ALONE)
|
63
|
+
preserved_methods = preserved_methods.is_a?(Symbol) ? preserved_methods : preserved_methods.sort.uniq
|
64
|
+
create_mocking(clazz, preserved_methods)
|
65
|
+
clazz.instance_variable_get(:@mocking_classes)[preserved_methods]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Module
|
71
|
+
def any_instance
|
72
|
+
if self.name =~ /^Java::/
|
73
|
+
JtestR::Mocha::mocking_class(self).any_instance
|
74
|
+
else
|
75
|
+
raise NotImplementedError, "any_instance only works for Modules that are Java interfaces"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Class
|
81
|
+
alias mocha_any_instance any_instance
|
82
|
+
|
83
|
+
def any_instance
|
84
|
+
if self.name =~ /^Java::/
|
85
|
+
JtestR::Mocha::mocking_class(self).mocha_any_instance
|
86
|
+
else
|
87
|
+
mocha_any_instance
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
module Mocha
|
93
|
+
module AutoVerify
|
94
|
+
alias old_mock mock
|
95
|
+
|
96
|
+
def mock(*args)
|
97
|
+
if args.first.is_a?(Module)
|
98
|
+
JtestR::Mocha::mocking_class(*args).new
|
99
|
+
else
|
100
|
+
old_mock(*args)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def mock_class(*args)
|
105
|
+
JtestR::Mocha::mocking_class(*args)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|