imitate 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -10,4 +10,5 @@ group :development do
10
10
  gem "rdoc", "~> 3.12"
11
11
  gem "bundler", "~> 1.0.0"
12
12
  gem "jeweler", "~> 1.8.3"
13
+ gem 'mocha'
13
14
  end
data/Gemfile.lock CHANGED
@@ -9,6 +9,9 @@ GEM
9
9
  rake
10
10
  rdoc
11
11
  json (1.7.0)
12
+ metaclass (0.0.1)
13
+ mocha (0.11.3)
14
+ metaclass (~> 0.0.1)
12
15
  rake (0.9.2.2)
13
16
  rdoc (3.12)
14
17
  json (~> 1.4)
@@ -27,5 +30,6 @@ PLATFORMS
27
30
  DEPENDENCIES
28
31
  bundler (~> 1.0.0)
29
32
  jeweler (~> 1.8.3)
33
+ mocha
30
34
  rdoc (~> 3.12)
31
35
  rspec (~> 2.8.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/imitate.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "imitate"
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Petr Janda"]
@@ -44,17 +44,20 @@ Gem::Specification.new do |s|
44
44
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
45
45
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
46
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
47
+ s.add_development_dependency(%q<mocha>, [">= 0"])
47
48
  else
48
49
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
49
50
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
50
51
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
52
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
53
+ s.add_dependency(%q<mocha>, [">= 0"])
52
54
  end
53
55
  else
54
56
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
55
57
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
56
58
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
59
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
60
+ s.add_dependency(%q<mocha>, [">= 0"])
58
61
  end
59
62
  end
60
63
 
data/lib/imitate.rb CHANGED
@@ -36,7 +36,7 @@ module Imitate
36
36
  #
37
37
  def unmock(name)
38
38
  process_name(name) {|parent, token|
39
- self.send(was_mocked?(parent, token) ? :remove_const : :get_const, parent, token)
39
+ self.send(was_mocked?(parent, token) ? :remove_mock : :get_const, parent, token)
40
40
  }
41
41
  end
42
42
 
@@ -45,7 +45,9 @@ module Imitate
45
45
  # way then using Imitate.
46
46
  #
47
47
  def unmock_all
48
- MOCKED.each {|mock| remove_const(mock[:parent], mock[:name])}
48
+ while mock = MOCKED.shift
49
+ remove_mock(mock[:parent], mock[:name])
50
+ end
49
51
  end
50
52
 
51
53
  private
@@ -63,12 +65,19 @@ module Imitate
63
65
  MOCKED.index({:parent => parent, :name => name})
64
66
  end
65
67
 
68
+ def remove_mock(parent, name)
69
+ MOCKED.delete({:parent => parent, :name => name})
70
+ remove_const(parent, name)
71
+ end
72
+
66
73
  def remove_const(parent, name)
67
74
  parent.instance_eval { remove_const name }
68
75
  end
69
76
 
70
77
  def get_const(parent, name)
71
- parent.const_get(name)
78
+ parent.const_get(name)
79
+ rescue
80
+ nil
72
81
  end
73
82
 
74
83
  def create_const(clazz, parent, name, &block)
data/spec/imitate_spec.rb CHANGED
@@ -18,8 +18,8 @@ describe "Imitate" do
18
18
  end
19
19
 
20
20
  describe '.unmock' do
21
- context 'if const exists' do
22
- context 'if const was mocked by imitate' do
21
+ context 'const exists' do
22
+ context 'const was mocked by imitate' do
23
23
  it 'should remove the class' do
24
24
  Imitate.mock_class('Foo')
25
25
  Imitate.unmock('Foo')
@@ -34,6 +34,15 @@ describe "Imitate" do
34
34
  lambda { Foo::Bar }.should raise_error
35
35
  lambda { Foo }.should raise_error
36
36
  end
37
+
38
+ it 'should remove record from MOCKED' do
39
+ Imitate.mock_class('Foo')
40
+ Imitate.unmock('Foo')
41
+
42
+ Imitate.expects(:remove_const).never
43
+
44
+ Imitate.unmock('Foo')
45
+ end
37
46
  end
38
47
 
39
48
  context 'if const was not mocked' do
@@ -68,6 +77,14 @@ describe "Imitate" do
68
77
  end
69
78
  end
70
79
  end
80
+
81
+ context 'class doesnt exist' do
82
+ it 'should do nothing' do
83
+ Imitate.unmock('Foo1')
84
+
85
+ Imitate.expects(:remove_const).never
86
+ end
87
+ end
71
88
  end
72
89
 
73
90
  describe '.mock_class' do
data/spec/spec_helper.rb CHANGED
@@ -8,5 +8,5 @@ require 'imitate'
8
8
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
10
  RSpec.configure do |config|
11
-
11
+ config.mock_with :mocha
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imitate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-03 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2157547400 !ruby/object:Gem::Requirement
16
+ requirement: &2160205840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2157547400
24
+ version_requirements: *2160205840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &2157546900 !ruby/object:Gem::Requirement
27
+ requirement: &2160203080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.12'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2157546900
35
+ version_requirements: *2160203080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2157546420 !ruby/object:Gem::Requirement
38
+ requirement: &2160200860 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2157546420
46
+ version_requirements: *2160200860
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &2157545920 !ruby/object:Gem::Requirement
49
+ requirement: &2160198100 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,18 @@ dependencies:
54
54
  version: 1.8.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2157545920
57
+ version_requirements: *2160198100
58
+ - !ruby/object:Gem::Dependency
59
+ name: mocha
60
+ requirement: &2160194700 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2160194700
58
69
  description: Simple class mock
59
70
  email: petrjanda@me.com
60
71
  executables: []
@@ -90,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
101
  version: '0'
91
102
  segments:
92
103
  - 0
93
- hash: 3941489243692019198
104
+ hash: 2598245985460209889
94
105
  required_rubygems_version: !ruby/object:Gem::Requirement
95
106
  none: false
96
107
  requirements: