active_mocker 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ca865ce8b72156b2e63b97bc17e7e3b46680812
4
- data.tar.gz: 1c18749e4ecd00a17be85f50a7f7c474f3663d57
3
+ metadata.gz: 21a518671785c535883e4fa2f3fe1aeb95538c07
4
+ data.tar.gz: b3fef1e6496ce8e5fcbe686d8c75441481a378ea
5
5
  SHA512:
6
- metadata.gz: fa3dbe4b14f5bff23610ac09c81390bc402e75dc1689b93b8a1500d48fdf80c65b3dfdd085edafcc86f38db1a6c535434dc3a6cac7d762b1f698f7e9dcd8196d
7
- data.tar.gz: c0844f0b7d454cbc2a4d81965c8f7625cf428a3faaf66cf17fb77dca11a244b10ad15969f583c3fe4008fb5644700156b869b19a36cb23baa9c0be179823461e
6
+ metadata.gz: e4d11855ab91ea06085f8eb42b4af4ff9d1926b1ca1e732846200cc610ba9dd6bab82fcf1939cedd9b268e00e1737363a881b6d1a12c8570f2d3bfa7132713c4
7
+ data.tar.gz: 23e84bfeaaaf244364ab54e1219a2c2d5483e847739a7a613a9c233004ff259532ab8240f2cccc65e1551a3c4ff509bed18c08e566ea17590bbab1a7edacf0e4
@@ -0,0 +1,35 @@
1
+ module ActiveMocker
2
+
3
+ class LoadedMocks
4
+ def self.add(mocks_to_add)
5
+ mocks.merge!({mocks_to_add.name => mocks_to_add})
6
+ end
7
+
8
+ def self.all
9
+ mocks
10
+ end
11
+
12
+ def self.clear_all
13
+ mocks.each { |n, m| m.clear_mock }
14
+ end
15
+
16
+ def self.delete_all
17
+ mocks.each { |n, m| m.delete_all }
18
+ end
19
+
20
+ def self.reload_all
21
+ mocks.each { |n, m| m.reload }
22
+ end
23
+
24
+ def self.mocks
25
+ @@mocks ||= {}
26
+ end
27
+
28
+ def self.undefine_all
29
+ mocks.each do |n, m|
30
+ Object.send(:remove_const, n) if Object.const_defined?(:n)
31
+ end
32
+ end
33
+ end
34
+
35
+ end
@@ -3,6 +3,7 @@ require 'active_mocker/collection/base'
3
3
  require 'active_mocker/collection/association'
4
4
  require 'active_mocker/mock_class_methods'
5
5
  require 'active_mocker/mock_instance_methods'
6
+ require 'active_mocker/loaded_mocks'
6
7
  require 'active_hash'
7
8
  require 'active_hash/ar_api'
8
9
  require 'active_mocker/class_exists'
@@ -91,4 +91,10 @@ class <%= class_name %> < ::ActiveHash::Base
91
91
  end
92
92
  <% end -%>
93
93
 
94
+ def self.reload
95
+ load __FILE__
96
+ end
97
+
94
98
  end
99
+
100
+ ActiveMocker::LoadedMocks.add(<%= class_name %>)
@@ -1,3 +1,3 @@
1
1
  module ActiveMocker
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -118,4 +118,10 @@ class MicropostMock < ::ActiveHash::Base
118
118
  instance_exec(*[user], &block)
119
119
  end
120
120
 
121
+ def self.reload
122
+ load __FILE__
123
+ end
124
+
121
125
  end
126
+
127
+ ActiveMocker::LoadedMocks.add(MicropostMock)
@@ -111,4 +111,10 @@ class RelationshipMock < ::ActiveHash::Base
111
111
  delete_all
112
112
  end
113
113
 
114
+ def self.reload
115
+ load __FILE__
116
+ end
117
+
114
118
  end
119
+
120
+ ActiveMocker::LoadedMocks.add(RelationshipMock)
@@ -207,4 +207,10 @@ class UserMock < ::ActiveHash::Base
207
207
  instance_exec(*[token], &block)
208
208
  end
209
209
 
210
+ def self.reload
211
+ load __FILE__
212
+ end
213
+
210
214
  end
215
+
216
+ ActiveMocker::LoadedMocks.add(UserMock)
@@ -0,0 +1,45 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.after(:all) do
5
+ ActiveMocker::LoadedMocks.clear_all
6
+ end
7
+
8
+ config.before(:all) do
9
+ ActiveMocker::LoadedMocks.clear_all
10
+ end
11
+ end
12
+
13
+ $:.unshift File.expand_path('../../', __FILE__)
14
+ APP_ROOT = File.expand_path('../../', __FILE__)
15
+ require 'config/initializers/active_mocker.rb'
16
+ load 'mocks/user_mock.rb'
17
+
18
+ describe 'Should change state of mock'do
19
+
20
+ before(:each) do
21
+ UserMock.create
22
+
23
+ UserMock.mock_class_method(:digest) do |token|
24
+ token
25
+ end
26
+ end
27
+
28
+ it 'should change record count and digest should be implemented' do
29
+ expect(UserMock.count).to eq 1
30
+ expect(UserMock.digest('token')).to eq 'token'
31
+ end
32
+
33
+ end
34
+
35
+ describe 'should have fresh mock' do
36
+
37
+ it 'should have record count of zero' do
38
+ expect(UserMock.count).to eq 0
39
+ end
40
+
41
+ it 'should raise error when calling digest' do
42
+ expect{UserMock.digest(nil)}.to raise_error(RuntimeError, '::digest is not Implemented for Class: UserMock')
43
+ end
44
+
45
+ end
@@ -1,11 +1,11 @@
1
1
  require 'rspec'
2
2
  $:.unshift File.expand_path('../../', __FILE__)
3
+ load 'spec/mocks/user_mock.rb'
3
4
  APP_ROOT = File.expand_path('../../', __FILE__)
4
-
5
5
  require 'config/initializers/active_mocker.rb'
6
- load 'spec/mocks/user_mock.rb'
7
6
 
8
- describe UserMock do
7
+
8
+ describe 'UserMock' do
9
9
 
10
10
  before(:each){
11
11
  ActiveMocker::Generate.new
@@ -169,6 +169,7 @@ describe UserMock do
169
169
  expect(person.persisted?).to eq true
170
170
  end
171
171
 
172
+
172
173
  after(:each) do
173
174
  UserMock.delete_all
174
175
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_mocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-31 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -189,6 +189,7 @@ files:
189
189
  - lib/active_mocker/const_sets.rb
190
190
  - lib/active_mocker/field.rb
191
191
  - lib/active_mocker/generate.rb
192
+ - lib/active_mocker/loaded_mocks.rb
192
193
  - lib/active_mocker/logger.rb
193
194
  - lib/active_mocker/mock_class_methods.rb
194
195
  - lib/active_mocker/mock_instance_methods.rb
@@ -350,6 +351,7 @@ files:
350
351
  - sample_app_rails_4/spec/mocks/micropost_mock.rb
351
352
  - sample_app_rails_4/spec/mocks/relationship_mock.rb
352
353
  - sample_app_rails_4/spec/mocks/user_mock.rb
354
+ - sample_app_rails_4/spec/reload_spec.rb
353
355
  - sample_app_rails_4/spec/spec_helper.rb
354
356
  - sample_app_rails_4/spec/user_mock_spec.rb
355
357
  - sample_app_rails_4/vendor/assets/javascripts/.keep