active_mocker 1.3.1 → 1.3.2
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.
- checksums.yaml +4 -4
- data/lib/active_mocker/loaded_mocks.rb +35 -0
- data/lib/active_mocker/mock_requires.rb +1 -0
- data/lib/active_mocker/mock_template.erb +6 -0
- data/lib/active_mocker/version.rb +1 -1
- data/sample_app_rails_4/spec/mocks/micropost_mock.rb +6 -0
- data/sample_app_rails_4/spec/mocks/relationship_mock.rb +6 -0
- data/sample_app_rails_4/spec/mocks/user_mock.rb +6 -0
- data/sample_app_rails_4/spec/reload_spec.rb +45 -0
- data/sample_app_rails_4/spec/user_mock_spec.rb +4 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21a518671785c535883e4fa2f3fe1aeb95538c07
|
4
|
+
data.tar.gz: b3fef1e6496ce8e5fcbe686d8c75441481a378ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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'
|
@@ -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
|
-
|
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.
|
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-
|
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
|