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 +4 -4
- data/README.md +4 -0
- data/lib/active_mocker/mock_template.erb +4 -0
- data/lib/active_mocker/version.rb +1 -1
- data/mocks/micropost_mock.rb +4 -0
- data/mocks/relationship_mock.rb +4 -0
- data/mocks/user_mock.rb +4 -0
- data/sample_app_rails_4/Gemfile +1 -0
- data/sample_app_rails_4/spec/mocks/micropost_mock.rb +4 -0
- data/sample_app_rails_4/spec/mocks/relationship_mock.rb +4 -0
- data/sample_app_rails_4/spec/mocks/user_mock.rb +4 -0
- data/sample_app_rails_4/spec/user_mock_spec.rb +43 -44
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 439e04b0f76f49bdf4e00ec5e2b89e7e4956b355
|
4
|
+
data.tar.gz: fbac11173deec5cc2bd514e60d8969b4bed1def6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fda21c454f146b0f71ab12534c6e9b002a9ade2f55a94580ed1bc2aef1939906450d37e93895a7642d75337049e39961599caf30b664fcbf0d5c215b69011593
|
7
|
+
data.tar.gz: e383efe824051292bd4215db6c824d59b8186c0b4e4605f751e434c54d1e942e0afa82aa3b95bc5e564008d7650acd80d4ac69a1d9389762f75c7b1fad931b93
|
data/README.md
CHANGED
@@ -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 %>]
|
data/mocks/micropost_mock.rb
CHANGED
data/mocks/relationship_mock.rb
CHANGED
data/mocks/user_mock.rb
CHANGED
data/sample_app_rails_4/Gemfile
CHANGED
@@ -4,12 +4,12 @@ load 'mocks/user_mock.rb'
|
|
4
4
|
|
5
5
|
describe UserMock do
|
6
6
|
|
7
|
-
|
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(
|
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 =
|
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{
|
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 =
|
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(
|
41
|
-
expect(
|
42
|
-
mock_inst =
|
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(
|
54
|
-
expect{
|
55
|
-
expect{
|
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
|
-
|
60
|
+
UserMock.mock_instance_method(:follow!) do |other_user|
|
61
61
|
"Now implemented with #{other_user}"
|
62
62
|
end
|
63
|
-
result =
|
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
|
-
|
71
|
+
UserMock.mock_instance_method(:following?) do |person|
|
72
72
|
true
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
UserMock.mock_instance_method(:follow!) do |person|
|
76
76
|
following?(person)
|
77
77
|
end
|
78
78
|
|
79
|
-
expect(
|
80
|
-
expect(
|
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{
|
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
|
-
|
93
|
+
UserMock.mock_class_method(:new_remember_token) do
|
94
94
|
"Now implemented"
|
95
95
|
end
|
96
|
-
expect{
|
97
|
-
expect(
|
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(
|
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 =
|
111
|
-
expect(
|
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 =
|
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
|
-
|
128
|
+
UserMock.create
|
130
129
|
|
131
|
-
expect(
|
130
|
+
expect(UserMock.count).to eq 1
|
132
131
|
|
133
|
-
|
132
|
+
UserMock.destroy_all
|
134
133
|
|
135
|
-
expect(
|
134
|
+
expect(UserMock.count).to eq 0
|
136
135
|
|
137
136
|
end
|
138
137
|
|
139
138
|
it '::find_by' do
|
140
|
-
person =
|
141
|
-
expect(
|
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 =
|
146
|
-
expect(
|
147
|
-
person =
|
148
|
-
expect(
|
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
|
-
|
153
|
-
person =
|
151
|
+
UserMock.create(name: 'dustin')
|
152
|
+
person = UserMock.find_or_create_by(name: 'dustin')
|
154
153
|
person.update(email: 'Zeisler')
|
155
|
-
expect(
|
156
|
-
expect(
|
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 =
|
159
|
+
person = UserMock.find_or_initialize_by(name: 'dustin')
|
161
160
|
expect(person.persisted?).to eq false
|
162
|
-
|
163
|
-
person =
|
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
|
-
|
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
|
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:
|
389
|
+
version: '0'
|
390
390
|
requirements: []
|
391
391
|
rubyforge_project:
|
392
392
|
rubygems_version: 2.2.2
|