soveran-override 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +2 -3
  2. data/Rakefile +0 -27
  3. data/lib/override.rb +19 -4
  4. metadata +8 -16
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 [Spawner](http://github.com/soveran/spawner).
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 sources -a http://gems.github.com (you only have to do this once)
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.to_proc) :
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: soveran-override
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
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-03-13 00:00:00 -07:00
12
+ date: 2009-05-16 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: metaid
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
 
@@ -38,6 +29,7 @@ files:
38
29
  - test/all_test.rb
39
30
  has_rdoc: false
40
31
  homepage: http://github.com/soveran/override
32
+ licenses:
41
33
  post_install_message:
42
34
  rdoc_options: []
43
35
 
@@ -57,8 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
49
  version:
58
50
  requirements: []
59
51
 
60
- rubyforge_project:
61
- rubygems_version: 1.2.0
52
+ rubyforge_project: override
53
+ rubygems_version: 1.3.5
62
54
  signing_key:
63
55
  specification_version: 2
64
56
  summary: The as-simple-as-possible-but-not-simpler stubbing library.