override 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -3
- data/Rakefile +0 -27
- data/lib/override.rb +19 -4
- metadata +11 -18
data/README.markdown
CHANGED
@@ -44,7 +44,7 @@ And then, in your tests:
|
|
44
44
|
|
45
45
|
assert_equal "Foobar", User.find(1).name
|
46
46
|
|
47
|
-
In case you don't know what spawn means, check my library [
|
47
|
+
In case you don't know what spawn means, check my library [Spawn](http://github.com/soveran/spawn).
|
48
48
|
|
49
49
|
It is a common pattern to set expectations for method calls. You can do
|
50
50
|
it with the `expect` function:
|
@@ -75,8 +75,7 @@ examples.
|
|
75
75
|
Installation
|
76
76
|
------------
|
77
77
|
|
78
|
-
$ gem
|
79
|
-
$ sudo gem install soveran-override
|
78
|
+
$ sudo gem install override
|
80
79
|
|
81
80
|
Thanks
|
82
81
|
------
|
data/Rakefile
CHANGED
@@ -1,11 +1,4 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'rake/gempackagetask'
|
3
1
|
require 'rake/testtask'
|
4
|
-
require 'rake/clean'
|
5
|
-
|
6
|
-
gem_spec_file = 'override.gemspec'
|
7
|
-
|
8
|
-
gem_spec = eval(File.read(gem_spec_file)) rescue nil
|
9
2
|
|
10
3
|
task :default => :test
|
11
4
|
|
@@ -13,23 +6,3 @@ Rake::TestTask.new(:test) do |t|
|
|
13
6
|
t.pattern = 'test/**/*_test.rb'
|
14
7
|
t.verbose = false
|
15
8
|
end
|
16
|
-
|
17
|
-
Rake::GemPackageTask.new(gem_spec) do |pkg|
|
18
|
-
pkg.need_zip = false
|
19
|
-
pkg.need_tar = false
|
20
|
-
rm_f FileList['pkg/**/*.*']
|
21
|
-
end if gem_spec
|
22
|
-
|
23
|
-
desc "Generate the gemspec file."
|
24
|
-
task :gemspec do
|
25
|
-
require 'erb'
|
26
|
-
|
27
|
-
File.open(gem_spec_file, 'w') do |f|
|
28
|
-
f.write ERB.new(File.read("#{gem_spec_file}.erb")).result(binding)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "Builds and installs the gem."
|
33
|
-
task :install => :repackage do
|
34
|
-
`sudo gem install pkg/#{gem_spec.name}-#{gem_spec.version}.gem`
|
35
|
-
end
|
data/lib/override.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "metaid"
|
3
|
-
|
4
1
|
module Override
|
5
2
|
def override object, methods
|
6
3
|
methods.each do |method, result|
|
7
4
|
result.respond_to?(:to_proc) ?
|
8
|
-
object.meta_def(method, &result
|
5
|
+
object.meta_def(method, &result) :
|
9
6
|
object.meta_def(method) { |*_| result }
|
10
7
|
end
|
11
8
|
object
|
@@ -27,3 +24,21 @@ module Override
|
|
27
24
|
end
|
28
25
|
end
|
29
26
|
end
|
27
|
+
|
28
|
+
# Metaid == a few simple metaclass helper
|
29
|
+
# (See http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html.)
|
30
|
+
class Object
|
31
|
+
# The hidden singleton lurks behind everyone
|
32
|
+
def metaclass; class << self; self; end; end
|
33
|
+
def meta_eval &blk; metaclass.instance_eval &blk; end
|
34
|
+
|
35
|
+
# Adds methods to a metaclass
|
36
|
+
def meta_def name, &blk
|
37
|
+
meta_eval { define_method name, &blk }
|
38
|
+
end
|
39
|
+
|
40
|
+
# Defines an instance method within a class
|
41
|
+
def class_def name, &blk
|
42
|
+
class_eval { define_method name, &blk }
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: override
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
@@ -9,20 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-29 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "1.0"
|
24
|
-
version:
|
25
|
-
description:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: "Override is the essence of the stubbing concept: it takes an object, a hash of methods/results, and proceeds to rewrite each method in the object. It can be used as a stubbing strategy in most cases"
|
26
17
|
email: michel@soveran.com
|
27
18
|
executables: []
|
28
19
|
|
@@ -36,8 +27,10 @@ files:
|
|
36
27
|
- LICENSE
|
37
28
|
- Rakefile
|
38
29
|
- test/all_test.rb
|
39
|
-
has_rdoc:
|
30
|
+
has_rdoc: true
|
40
31
|
homepage: http://github.com/soveran/override
|
32
|
+
licenses: []
|
33
|
+
|
41
34
|
post_install_message:
|
42
35
|
rdoc_options: []
|
43
36
|
|
@@ -57,10 +50,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
50
|
version:
|
58
51
|
requirements: []
|
59
52
|
|
60
|
-
rubyforge_project:
|
61
|
-
rubygems_version: 1.3.
|
53
|
+
rubyforge_project: override
|
54
|
+
rubygems_version: 1.3.4
|
62
55
|
signing_key:
|
63
|
-
specification_version:
|
56
|
+
specification_version: 3
|
64
57
|
summary: The as-simple-as-possible-but-not-simpler stubbing library.
|
65
58
|
test_files: []
|
66
59
|
|