active_mocker 1.2.pre.11 → 1.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: af6dc3ef47eac14967fac5cc58c248eaaff7f27b
4
- data.tar.gz: d5d09b834cb7974ee1f39d002809c9400cbcc654
3
+ metadata.gz: 439e04b0f76f49bdf4e00ec5e2b89e7e4956b355
4
+ data.tar.gz: fbac11173deec5cc2bd514e60d8969b4bed1def6
5
5
  SHA512:
6
- metadata.gz: 44910634e7dc665043968e8ee58bc6b83e82e8ae7c4efcc103e328282f4800ef4e89a661c9441c5a4b5f201b86cf0bdaf3690543fd2aef65997b4ea399fcc2a5
7
- data.tar.gz: b00603af88b32cd5aecbc5e0ece7b030030ae022e107d3ddc7a545ba4623087df6eebdd39778dffe0473899c670f74e1945013450bf9aceb827df83405ed8ca9
6
+ metadata.gz: fda21c454f146b0f71ab12534c6e9b002a9ade2f55a94580ed1bc2aef1939906450d37e93895a7642d75337049e39961599caf30b664fcbf0d5c215b69011593
7
+ data.tar.gz: e383efe824051292bd4215db6c824d59b8186c0b4e4605f751e434c54d1e942e0afa82aa3b95bc5e564008d7650acd80d4ac69a1d9389762f75c7b1fad931b93
data/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
 
4
4
  Create static mocks from active record models without loading rails or running a database.
5
5
 
6
+ Example from a real app
7
+ Finished in 0.54599 seconds
8
+ 190 examples, 0 failures
9
+
6
10
  ## Installation
7
11
 
8
12
  Add this line to your application's Gemfile:
@@ -69,6 +69,10 @@ class <%= class_name %> < ::ActiveHash::Base
69
69
  @model_class_methods
70
70
  end
71
71
 
72
+ def self.clear_mock
73
+ @model_class_methods, @model_instance_methods = nil, nil
74
+ delete_all
75
+ end
72
76
  <% instance_methods.each do |method| %>
73
77
  def <%= method.method %>(<%= method.params %>)
74
78
  block = model_instance_methods[<%= method.method.inspect %>]
@@ -1,3 +1,3 @@
1
1
  module ActiveMocker
2
- VERSION = "1.2.pre.11"
2
+ VERSION = "1.2"
3
3
  end
@@ -92,6 +92,10 @@ class MicropostMock < ::ActiveHash::Base
92
92
  @model_class_methods
93
93
  end
94
94
 
95
+ def self.clear_mock
96
+ @model_class_methods, @model_instance_methods = nil, nil
97
+ delete_all
98
+ end
95
99
 
96
100
 
97
101
  def self.from_users_followed_by(user)
@@ -99,6 +99,10 @@ class RelationshipMock < ::ActiveHash::Base
99
99
  @model_class_methods
100
100
  end
101
101
 
102
+ def self.clear_mock
103
+ @model_class_methods, @model_instance_methods = nil, nil
104
+ delete_all
105
+ end
102
106
 
103
107
 
104
108
 
data/mocks/user_mock.rb CHANGED
@@ -153,6 +153,10 @@ class UserMock < ::ActiveHash::Base
153
153
  @model_class_methods
154
154
  end
155
155
 
156
+ def self.clear_mock
157
+ @model_class_methods, @model_instance_methods = nil, nil
158
+ delete_all
159
+ end
156
160
 
157
161
  def feed()
158
162
  block = model_instance_methods[:feed]
@@ -9,4 +9,5 @@ end
9
9
 
10
10
  group :test do
11
11
  gem 'active_mocker', :path => "../../active_mocker"
12
+ gem 'fuubar'
12
13
  end
@@ -92,6 +92,10 @@ class MicropostMock < ::ActiveHash::Base
92
92
  @model_class_methods
93
93
  end
94
94
 
95
+ def self.clear_mock
96
+ @model_class_methods, @model_instance_methods = nil, nil
97
+ delete_all
98
+ end
95
99
 
96
100
 
97
101
  def self.from_users_followed_by(user)
@@ -99,6 +99,10 @@ class RelationshipMock < ::ActiveHash::Base
99
99
  @model_class_methods
100
100
  end
101
101
 
102
+ def self.clear_mock
103
+ @model_class_methods, @model_instance_methods = nil, nil
104
+ delete_all
105
+ end
102
106
 
103
107
 
104
108
 
@@ -153,6 +153,10 @@ class UserMock < ::ActiveHash::Base
153
153
  @model_class_methods
154
154
  end
155
155
 
156
+ def self.clear_mock
157
+ @model_class_methods, @model_instance_methods = nil, nil
158
+ delete_all
159
+ end
156
160
 
157
161
  def feed()
158
162
  block = model_instance_methods[:feed]
@@ -4,12 +4,12 @@ load 'mocks/user_mock.rb'
4
4
 
5
5
  describe UserMock do
6
6
 
7
- let(:mock_class){described_class}
7
+ before(:each){ UserMock.clear_mock }
8
8
 
9
9
  describe '::column_names' do
10
10
 
11
11
  it 'returns an array of column names found from the schema.rb file' do
12
- expect(mock_class.column_names).to eq(["id", "name", "email", "created_at", "updated_at", "password_digest", "remember_token", "admin"])
12
+ expect(UserMock.column_names).to eq(["id", "name", "email", "created_at", "updated_at", "password_digest", "remember_token", "admin"])
13
13
  end
14
14
 
15
15
  end
@@ -17,13 +17,13 @@ describe UserMock do
17
17
  describe 'mass_assignment' do
18
18
 
19
19
  it "can pass any or all attributes from schema in initializer" do
20
- result = mock_class.new(name: "Sam", email: 'Walton')
20
+ result = UserMock.new(name: "Sam", email: 'Walton')
21
21
  expect(result.name).to eq 'Sam'
22
22
  expect(result.email).to eq 'Walton'
23
23
  end
24
24
 
25
25
  it 'will raise error if not an attribute or association' do
26
- expect{mock_class.new(baz: "Hello")}.to raise_error('Rejected params: {"baz"=>"Hello"} for UserMock')
26
+ expect{UserMock.new(baz: "Hello")}.to raise_error('Rejected params: {"baz"=>"Hello"} for UserMock')
27
27
  end
28
28
 
29
29
  end
@@ -31,15 +31,15 @@ describe UserMock do
31
31
  describe 'relationships' do
32
32
 
33
33
  it 'add instance methods from model relationships' do
34
- result = mock_class.new(followers: [1])
34
+ result = UserMock.new(followers: [1])
35
35
  expect(result.followers).to eq [1]
36
36
  end
37
37
 
38
38
  it 'add has_many relationship' do
39
39
 
40
- expect(mock_class.new.microposts.class).to eq ActiveMocker::CollectionAssociation
41
- expect(mock_class.new.microposts.count).to eq 0
42
- mock_inst = mock_class.new
40
+ expect(UserMock.new.microposts.class).to eq ActiveMocker::CollectionAssociation
41
+ expect(UserMock.new.microposts.count).to eq 0
42
+ mock_inst = UserMock.new
43
43
  mock_inst.microposts << 1
44
44
  expect(mock_inst.microposts.count).to eq 1
45
45
 
@@ -50,17 +50,17 @@ describe UserMock do
50
50
  describe 'instance methods' do
51
51
 
52
52
  it 'will raise exception for unimplemented methods' do
53
- expect(mock_class.new.method(:following?).parameters).to eq [[:req, :other_user]]
54
- expect{mock_class.new.following?}.to raise_error ArgumentError
55
- expect{mock_class.new.following?('foo')}.to raise_error(RuntimeError, '#following? is not Implemented for Class: UserMock')
53
+ expect(UserMock.new.method(:following?).parameters).to eq [[:req, :other_user]]
54
+ expect{UserMock.new.following?}.to raise_error ArgumentError
55
+ expect{UserMock.new.following?('foo')}.to raise_error(RuntimeError, '#following? is not Implemented for Class: UserMock')
56
56
  end
57
57
 
58
58
  it 'can be implemented dynamically' do
59
59
 
60
- mock_class.mock_instance_method(:follow!) do |other_user|
60
+ UserMock.mock_instance_method(:follow!) do |other_user|
61
61
  "Now implemented with #{other_user}"
62
62
  end
63
- result = mock_class.new
63
+ result = UserMock.new
64
64
  result = result.follow!('foo')
65
65
  expect(result).to eq "Now implemented with foo"
66
66
 
@@ -68,16 +68,16 @@ describe UserMock do
68
68
 
69
69
  it 'can reference another mock' do
70
70
 
71
- mock_class.mock_instance_method(:following?) do |person|
71
+ UserMock.mock_instance_method(:following?) do |person|
72
72
  true
73
73
  end
74
74
 
75
- mock_class.mock_instance_method(:follow!) do |person|
75
+ UserMock.mock_instance_method(:follow!) do |person|
76
76
  following?(person)
77
77
  end
78
78
 
79
- expect(mock_class.new.follow!("name")).to eq true
80
- expect(mock_class.new.following?(1)).to eq true
79
+ expect(UserMock.new.follow!("name")).to eq true
80
+ expect(UserMock.new.following?(1)).to eq true
81
81
  end
82
82
 
83
83
  end
@@ -85,16 +85,16 @@ describe UserMock do
85
85
  describe 'class methods' do
86
86
 
87
87
  it 'will raise exception for unimplemented methods' do
88
- expect{mock_class.new_remember_token}.to raise_error('::new_remember_token is not Implemented for Class: UserMock')
88
+ expect{UserMock.new_remember_token}.to raise_error('::new_remember_token is not Implemented for Class: UserMock')
89
89
  end
90
90
 
91
91
  it 'can be implemented as follows' do
92
92
 
93
- mock_class.mock_class_method(:new_remember_token) do
93
+ UserMock.mock_class_method(:new_remember_token) do
94
94
  "Now implemented"
95
95
  end
96
- expect{mock_class.new_remember_token}.to_not raise_error
97
- expect(mock_class.new_remember_token).to eq("Now implemented")
96
+ expect{UserMock.new_remember_token}.to_not raise_error
97
+ expect(UserMock.new_remember_token).to eq("Now implemented")
98
98
 
99
99
  end
100
100
 
@@ -103,19 +103,18 @@ describe UserMock do
103
103
  context 'active_hash' do
104
104
 
105
105
  it 'uses active_hash::base as superclass' do
106
- expect(mock_class.superclass.name).to eq 'ActiveHash::Base'
106
+ expect(UserMock.superclass.name).to eq 'ActiveHash::Base'
107
107
  end
108
108
 
109
109
  it 'can save to class and then find instance by attribute' do
110
- record = mock_class.create(name: "Sam")
111
- expect(mock_class.find_by(name:"Sam")).to eq record
110
+ record = UserMock.create(name: "Sam")
111
+ expect(UserMock.find_by(name:"Sam")).to eq record
112
112
 
113
113
  end
114
114
 
115
115
  it '#update' do
116
116
 
117
- person = mock_class.create(name: 'Justin')
118
-
117
+ person = UserMock.create(name: 'Justin')
119
118
  expect(UserMock.first.name).to eq 'Justin'
120
119
  person.update(name: 'Dustin')
121
120
  expect(UserMock.first.name).to eq 'Dustin'
@@ -126,46 +125,46 @@ describe UserMock do
126
125
 
127
126
  it '::destroy_all' do
128
127
 
129
- mock_class.create
128
+ UserMock.create
130
129
 
131
- expect(mock_class.count).to eq 1
130
+ expect(UserMock.count).to eq 1
132
131
 
133
- mock_class.destroy_all
132
+ UserMock.destroy_all
134
133
 
135
- expect(mock_class.count).to eq 0
134
+ expect(UserMock.count).to eq 0
136
135
 
137
136
  end
138
137
 
139
138
  it '::find_by' do
140
- person = mock_class.create(name: 'dustin')
141
- expect(mock_class.find_by(name: 'dustin')).to eq person
139
+ person = UserMock.create(name: 'dustin')
140
+ expect(UserMock.find_by(name: 'dustin')).to eq person
142
141
  end
143
142
 
144
143
  it '::find_or_create_by' do
145
- person = mock_class.find_or_create_by(name: 'dustin')
146
- expect(mock_class.find_by(name: 'dustin')).to eq person
147
- person = mock_class.find_or_create_by(name: 'dustin')
148
- expect(mock_class.count).to eq 1
144
+ person = UserMock.find_or_create_by(name: 'dustin')
145
+ expect(UserMock.find_by(name: 'dustin')).to eq person
146
+ person = UserMock.find_or_create_by(name: 'dustin')
147
+ expect(UserMock.count).to eq 1
149
148
  end
150
149
 
151
150
  it '::find_or_create_by with update' do
152
- mock_class.create(name: 'dustin')
153
- person = mock_class.find_or_create_by(name: 'dustin')
151
+ UserMock.create(name: 'dustin')
152
+ person = UserMock.find_or_create_by(name: 'dustin')
154
153
  person.update(email: 'Zeisler')
155
- expect(mock_class.first.attributes).to eq person.attributes
156
- expect(mock_class.count).to eq 1
154
+ expect(UserMock.first.attributes).to eq person.attributes
155
+ expect(UserMock.count).to eq 1
157
156
  end
158
157
 
159
158
  it '::find_or_initialize_by' do
160
- person = mock_class.find_or_initialize_by(name: 'dustin')
159
+ person = UserMock.find_or_initialize_by(name: 'dustin')
161
160
  expect(person.persisted?).to eq false
162
- mock_class.create(name: 'dustin')
163
- person = mock_class.find_or_initialize_by(name: 'dustin')
161
+ UserMock.create(name: 'dustin')
162
+ person = UserMock.find_or_initialize_by(name: 'dustin')
164
163
  expect(person.persisted?).to eq true
165
164
  end
166
165
 
167
166
  after(:each) do
168
- mock_class.delete_all
167
+ UserMock.delete_all
169
168
  end
170
169
 
171
170
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_mocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.pre.11
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
@@ -384,9 +384,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
384
384
  version: 2.0.0
385
385
  required_rubygems_version: !ruby/object:Gem::Requirement
386
386
  requirements:
387
- - - ">"
387
+ - - ">="
388
388
  - !ruby/object:Gem::Version
389
- version: 1.3.1
389
+ version: '0'
390
390
  requirements: []
391
391
  rubyforge_project:
392
392
  rubygems_version: 2.2.2