smart_rspec 0.1.3 → 0.2.0
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 +5 -5
- data/.travis.yml +1 -4
- data/README.md +0 -15
- data/lib/smart_rspec/macros.rb +2 -3
- data/lib/smart_rspec/matchers/be_matchers.rb +0 -6
- data/lib/smart_rspec/matchers/json_api_matchers.rb +43 -0
- data/lib/smart_rspec/matchers/other_matchers.rb +0 -1
- data/lib/smart_rspec/matchers.rb +3 -1
- data/lib/smart_rspec/support/controller/response.rb +47 -0
- data/lib/smart_rspec/support/model/assertions.rb +112 -0
- data/lib/smart_rspec/support/model/expectations.rb +43 -0
- data/lib/smart_rspec/version.rb +1 -1
- data/lib/smart_rspec.rb +2 -3
- data/smart_rspec.gemspec +6 -7
- data/spec/fixtures/response.rb +11 -0
- data/spec/{factories → fixtures}/user.rb +31 -16
- data/spec/fixtures/users.json +81 -0
- data/spec/smart_rspec/macros_spec.rb +13 -12
- data/spec/smart_rspec/matchers_spec.rb +182 -121
- data/spec/spec_helper.rb +3 -3
- metadata +27 -21
- data/lib/smart_rspec/support/assertions.rb +0 -119
- data/lib/smart_rspec/support/expectations.rb +0 -42
@@ -1,173 +1,234 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe SmartRspec::Matchers do
|
4
|
+
describe BeMatchers do
|
5
|
+
describe '#be_ascending' do
|
6
|
+
context 'positive assertion' do
|
7
|
+
it { expect([1, 2, 3, 4]).to be_ascending }
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
context 'negative assertion' do
|
11
|
+
it { expect([1, 4, 2, 3]).not_to be_ascending }
|
12
|
+
end
|
11
13
|
end
|
12
|
-
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
describe '#be_boolean' do
|
16
|
+
context 'positive assertion' do
|
17
|
+
it { expect(true).to be_boolean }
|
18
|
+
it { expect(false).to be_boolean }
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
context 'negative assertion' do
|
22
|
+
it { expect('true').not_to be_boolean }
|
23
|
+
it { expect(1).not_to be_boolean }
|
24
|
+
it { expect(%w(foo bar)).not_to be_boolean }
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
describe '#be_descending' do
|
29
|
+
context 'positive assertion' do
|
30
|
+
it { expect([4, 3, 2, 1]).to be_descending }
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
context 'negative assertion' do
|
34
|
+
it { expect([1, 2, 3, 4]).not_to be_descending }
|
35
|
+
end
|
34
36
|
end
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
describe '#be_email' do
|
39
|
+
context 'positive assertion' do
|
40
|
+
it { expect(Faker::Internet.email).to be_email }
|
41
|
+
it { expect('tiagopog@gmail.com').to be_email }
|
42
|
+
it { expect('foo@bar.com.br').to be_email }
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
context 'negative assertion' do
|
46
|
+
it { expect('foo@bar').not_to be_email }
|
47
|
+
it { expect('foo@').not_to be_email }
|
48
|
+
it { expect('@bar').not_to be_email }
|
49
|
+
it { expect('@bar.com').not_to be_email }
|
50
|
+
it { expect('foo bar@bar.com').not_to be_email }
|
51
|
+
end
|
50
52
|
end
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
describe '#be_url' do
|
55
|
+
context 'positive assertion' do
|
56
|
+
it { expect(Faker::Internet.url).to be_url }
|
57
|
+
it { expect('http://adtangerine.com').to be_url }
|
58
|
+
it { expect('http://www.facebook.com').to be_url }
|
59
|
+
it { expect('www.twitflink.com').to be_url }
|
60
|
+
it { expect('google.com.br').to be_url }
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
context 'negative assertion' do
|
64
|
+
it { expect('foobar.bar').not_to be_url }
|
65
|
+
it { expect('foobar').not_to be_url }
|
66
|
+
it { expect('foo bar.com.br').not_to be_url }
|
67
|
+
end
|
66
68
|
end
|
67
|
-
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
70
|
+
describe '#be_image_url' do
|
71
|
+
context 'positive assertion' do
|
72
|
+
it { expect(Faker::Company.logo).to be_image_url }
|
73
|
+
it { expect('http://foobar.com/foo.jpg').to be_image_url }
|
74
|
+
it { expect('http://foobar.com/foo.jpg').to be_image_url(:jpg) }
|
75
|
+
it { expect('http://foobar.com/foo.gif').to be_image_url(:gif) }
|
76
|
+
it { expect('http://foobar.com/foo.png').to be_image_url(:png) }
|
77
|
+
it { expect('http://foobar.com/foo.png').to be_image_url([:jpg, :png]) }
|
78
|
+
it { expect('http://foobar.com/foo/bar?image=foo.jpg').to be_image_url }
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
context 'negative assertion' do
|
82
|
+
it { expect('http://foobar.com').not_to be_image_url }
|
83
|
+
it { expect('http://foobar.com/foo.jpg').not_to be_image_url(:gif) }
|
84
|
+
it { expect('http://foobar.com/foo.gif').not_to be_image_url(:png) }
|
85
|
+
it { expect('http://foobar.com/foo.png').not_to be_image_url(:jpg) }
|
86
|
+
it { expect('http://foobar.com/foo.gif').not_to be_image_url([:jpg, :png]) }
|
87
|
+
end
|
86
88
|
end
|
87
|
-
end
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
describe '#be_a_list_of' do
|
91
|
+
context 'positive assertion' do
|
92
|
+
subject { Array.new(3, User.new) }
|
93
|
+
it { is_expected.to be_a_list_of(User) }
|
94
|
+
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
context 'negative assertion' do
|
97
|
+
subject { Array.new(3, User.new) << nil }
|
98
|
+
it { is_expected.to_not be_a_list_of(User) }
|
99
|
+
end
|
98
100
|
end
|
99
101
|
end
|
100
102
|
|
101
|
-
describe
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
describe JsonApiMatchers do
|
104
|
+
subject(:response) { Fixtures::Response.new }
|
105
|
+
|
106
|
+
describe '#have_primary_data' do
|
107
|
+
context 'positive assertion' do
|
108
|
+
it do
|
109
|
+
expect(response).to have_primary_data('users')
|
110
|
+
end
|
111
|
+
end
|
106
112
|
|
107
|
-
|
108
|
-
|
109
|
-
|
113
|
+
context 'negative assertion' do
|
114
|
+
it do
|
115
|
+
expect(response).not_to have_primary_data('foobar')
|
116
|
+
end
|
117
|
+
end
|
110
118
|
end
|
111
|
-
end
|
112
119
|
|
113
|
-
|
114
|
-
|
120
|
+
describe '#have_data_attributes' do
|
121
|
+
let(:fields) { %w(first_name last_name full_name birthday) }
|
122
|
+
|
123
|
+
context 'positive assertion' do
|
124
|
+
it do
|
125
|
+
expect(response).to have_data_attributes(fields)
|
126
|
+
end
|
127
|
+
end
|
115
128
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
129
|
+
context 'negative assertion' do
|
130
|
+
it do
|
131
|
+
expect(response).not_to have_data_attributes(fields + %w(foobar))
|
132
|
+
end
|
120
133
|
end
|
121
134
|
end
|
122
135
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
136
|
+
describe '#have_relationships' do
|
137
|
+
let(:relationships) { %w(posts) }
|
138
|
+
|
139
|
+
context 'positive assertion' do
|
140
|
+
it do
|
141
|
+
expect(response).to have_relationships(relationships)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'negative assertion' do
|
146
|
+
it do
|
147
|
+
expect(response).not_to have_relationships(relationships + %w(foobar))
|
148
|
+
end
|
127
149
|
end
|
128
150
|
end
|
129
|
-
end
|
130
151
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
152
|
+
describe '#have_included_relationships' do
|
153
|
+
let(:relationships) { %w(posts) }
|
154
|
+
|
155
|
+
context 'positive assertion' do
|
156
|
+
it do
|
157
|
+
expect(response).to have_included_relationships
|
158
|
+
end
|
159
|
+
end
|
136
160
|
end
|
137
161
|
|
138
|
-
|
139
|
-
|
162
|
+
describe '#have_meta_record_count' do
|
163
|
+
context 'positive assertion' do
|
164
|
+
it do
|
165
|
+
expect(response).to have_meta_record_count(2)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'negative assertion' do
|
170
|
+
it do
|
171
|
+
expect(response).not_to have_meta_record_count(3)
|
172
|
+
end
|
173
|
+
end
|
140
174
|
end
|
141
175
|
end
|
142
176
|
|
143
|
-
describe
|
144
|
-
|
145
|
-
subject {
|
146
|
-
|
177
|
+
describe OtherMatchers do
|
178
|
+
describe '#have_error_on' do
|
179
|
+
subject { User.new(email: nil, name: Faker::Name.name) }
|
180
|
+
|
181
|
+
context 'positive assertion' do
|
182
|
+
it do
|
183
|
+
subject.valid?
|
184
|
+
is_expected.to have_error_on(:email)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'negative assertion' do
|
189
|
+
it do
|
190
|
+
subject.valid?
|
191
|
+
is_expected.not_to have_error_on(:name)
|
192
|
+
end
|
193
|
+
end
|
147
194
|
end
|
148
195
|
|
149
|
-
|
150
|
-
|
151
|
-
|
196
|
+
describe '#include_items' do
|
197
|
+
context 'positive assertion' do
|
198
|
+
it { expect(%w(foo bar foobar)).to include_items(%w(foo bar foobar)) }
|
199
|
+
it { expect(%w(lorem ipsum)).to include_items('lorem', 'ipsum') }
|
200
|
+
it { expect([1, 'foo', ['bar']]).to include_items([1, 'foo', ['bar']]) }
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'negative assertion' do
|
204
|
+
it { expect(%w(foo bar foobar)).not_to include_items(%w(lorem)) }
|
205
|
+
end
|
152
206
|
end
|
153
207
|
end
|
154
208
|
|
155
|
-
describe
|
156
|
-
|
209
|
+
describe ::RSpec::CollectionMatchers do
|
210
|
+
describe '#have' do
|
211
|
+
context 'positive assertion' do
|
212
|
+
it { expect([1]).to have(1).item }
|
213
|
+
it { expect(%w(foo bar)).to have(2).items }
|
214
|
+
end
|
157
215
|
|
158
|
-
|
159
|
-
|
160
|
-
|
216
|
+
context 'negative assertion' do
|
217
|
+
it { expect([1]).not_to have(2).items }
|
218
|
+
it { expect(%w(foo bar)).not_to have(1).item }
|
219
|
+
end
|
161
220
|
end
|
162
221
|
|
163
|
-
|
164
|
-
|
165
|
-
|
222
|
+
describe '#have_at_least' do
|
223
|
+
context 'positive assertion' do
|
224
|
+
it { expect(%w(foo bar foobar)).to have_at_least(3).items }
|
225
|
+
end
|
166
226
|
end
|
167
227
|
|
168
|
-
|
169
|
-
|
170
|
-
|
228
|
+
describe '#have_at_most' do
|
229
|
+
context 'positive assertion' do
|
230
|
+
it { expect(%w(foo bar foobar)).to have_at_most(3).items }
|
231
|
+
end
|
171
232
|
end
|
172
233
|
end
|
173
234
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Guedes
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec-collection_matchers
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,56 +50,56 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '2.0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '2.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: faker
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '2.0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '2.0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rake
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '13.0'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '13.0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rspec
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '3.
|
95
|
+
version: '3.5'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '3.
|
102
|
+
version: '3.5'
|
103
103
|
description: Collection of useful macros and matchers for RSpec tests of models/controllers
|
104
104
|
in Rails-based apps.
|
105
105
|
email:
|
@@ -119,13 +119,17 @@ files:
|
|
119
119
|
- lib/smart_rspec/macros.rb
|
120
120
|
- lib/smart_rspec/matchers.rb
|
121
121
|
- lib/smart_rspec/matchers/be_matchers.rb
|
122
|
+
- lib/smart_rspec/matchers/json_api_matchers.rb
|
122
123
|
- lib/smart_rspec/matchers/other_matchers.rb
|
123
|
-
- lib/smart_rspec/support/
|
124
|
-
- lib/smart_rspec/support/
|
124
|
+
- lib/smart_rspec/support/controller/response.rb
|
125
|
+
- lib/smart_rspec/support/model/assertions.rb
|
126
|
+
- lib/smart_rspec/support/model/expectations.rb
|
125
127
|
- lib/smart_rspec/support/regexes.rb
|
126
128
|
- lib/smart_rspec/version.rb
|
127
129
|
- smart_rspec.gemspec
|
128
|
-
- spec/
|
130
|
+
- spec/fixtures/response.rb
|
131
|
+
- spec/fixtures/user.rb
|
132
|
+
- spec/fixtures/users.json
|
129
133
|
- spec/smart_rspec/macros_spec.rb
|
130
134
|
- spec/smart_rspec/matchers_spec.rb
|
131
135
|
- spec/spec_helper.rb
|
@@ -133,7 +137,7 @@ homepage: https://github.com/tiagopog/smart_rspec
|
|
133
137
|
licenses:
|
134
138
|
- MIT
|
135
139
|
metadata: {}
|
136
|
-
post_install_message:
|
140
|
+
post_install_message:
|
137
141
|
rdoc_options: []
|
138
142
|
require_paths:
|
139
143
|
- lib
|
@@ -148,13 +152,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
152
|
- !ruby/object:Gem::Version
|
149
153
|
version: '0'
|
150
154
|
requirements: []
|
151
|
-
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
153
|
-
signing_key:
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.7.7
|
157
|
+
signing_key:
|
154
158
|
specification_version: 4
|
155
159
|
summary: Macros and matchers to make your RSpec tests even more amazing.
|
156
160
|
test_files:
|
157
|
-
- spec/
|
161
|
+
- spec/fixtures/response.rb
|
162
|
+
- spec/fixtures/user.rb
|
163
|
+
- spec/fixtures/users.json
|
158
164
|
- spec/smart_rspec/macros_spec.rb
|
159
165
|
- spec/smart_rspec/matchers_spec.rb
|
160
166
|
- spec/spec_helper.rb
|
@@ -1,119 +0,0 @@
|
|
1
|
-
module SmartRspec
|
2
|
-
module Support
|
3
|
-
module Assertions
|
4
|
-
private_class_method
|
5
|
-
|
6
|
-
def validates_email_of(attr, validation)
|
7
|
-
it 'has an invalid format' do
|
8
|
-
%w(foobar foobar@ @foobar foo@bar).each do |e|
|
9
|
-
validation_expectation(attr, e)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def validates_exclusion_of(attr, validation)
|
15
|
-
it 'has a reserved value' do
|
16
|
-
validation_expectation(attr, validation[:in].sample)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def validates_format_of(attr, validation)
|
21
|
-
it 'does not match the required format' do
|
22
|
-
mock, with =
|
23
|
-
validation.values_at(:mock).first,
|
24
|
-
validation.values_at(:with).first
|
25
|
-
|
26
|
-
if mock && with && with !~ mock
|
27
|
-
validation_expectation(attr, mock)
|
28
|
-
else
|
29
|
-
raise ArgumentError, ':with and :mock are required when using the :format validation'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def validates_inclusion_of(attr, validation)
|
35
|
-
it 'is out of the scope of possible values' do
|
36
|
-
begin
|
37
|
-
value = SecureRandom.hex
|
38
|
-
end while validation[:in].include?(value)
|
39
|
-
validation_expectation(attr, value)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def validates_length_of(attr, validation)
|
44
|
-
validation.each do |key, value|
|
45
|
-
next unless [:in, :is, :maximum, :minimum, :within].include?(key)
|
46
|
-
txt, n = build_length_validation(key, value)
|
47
|
-
it txt do
|
48
|
-
validation_expectation(attr, 'x' * n)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def validates_presence_of(attr, validation)
|
54
|
-
it 'is blank' do
|
55
|
-
validation_expectation(attr, nil)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def validates_uniqueness_of(attr, validation)
|
60
|
-
scoped = scoped_validation?(validation)
|
61
|
-
it "is already in use#{" (scope: #{validation[:scope]})" if scoped}" do
|
62
|
-
mock =
|
63
|
-
if scoped
|
64
|
-
copy = subject.send(validation[:scope])
|
65
|
-
validation[:mock].send("#{validation[:scope]}=", copy)
|
66
|
-
validation[:mock]
|
67
|
-
else
|
68
|
-
subject.dup
|
69
|
-
end
|
70
|
-
subject.save unless subject.persisted?
|
71
|
-
validation_expectation(attr, subject.send(attr), mock)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def assert_has_attributes(attrs, options)
|
76
|
-
type_str = build_type_str(options)
|
77
|
-
|
78
|
-
attrs.each do |attr|
|
79
|
-
it %Q(has an attribute named "#{attr}"#{type_str}) do
|
80
|
-
expect(subject).to respond_to(attr)
|
81
|
-
has_attributes_expectation(attr, options)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def assert_association(type, associations)
|
87
|
-
associations.each do |model|
|
88
|
-
it "#{type.to_s.gsub('_', ' ')} #{model}" do
|
89
|
-
expect(subject).to respond_to(model)
|
90
|
-
association_expectation(type, model)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def build_length_validation(key, value)
|
96
|
-
case key
|
97
|
-
when :in, :within then ['is out of the length range', value.max + 1]
|
98
|
-
when :is, :minimum then ["is #{key == :is ? 'invalid' : 'too short'}", value - 1]
|
99
|
-
when :maximum then ['is too long', value + 1]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def build_type_str(options)
|
104
|
-
if !options.nil? && options[:type]
|
105
|
-
" (%s%s%s)" % [
|
106
|
-
('Enumerated ' if options[:enum]),
|
107
|
-
options[:type],
|
108
|
-
(", default: #{options[:default]}" if options[:default])
|
109
|
-
]
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def scoped_validation?(validation)
|
114
|
-
validation.is_a?(Hash) && ([:scope, :mock] - validation.keys).empty?
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module SmartRspec
|
2
|
-
module Support
|
3
|
-
module Expectations
|
4
|
-
def validation_expectation(attr, value = nil, mock = nil)
|
5
|
-
mock ||= subject
|
6
|
-
mock.send("#{attr}=", value)
|
7
|
-
|
8
|
-
expect(mock).not_to be_valid
|
9
|
-
expect(mock).to have_error_on(attr)
|
10
|
-
end
|
11
|
-
|
12
|
-
def default_expectation(attr, value)
|
13
|
-
expect(subject.send(attr)).to eq(value)
|
14
|
-
end
|
15
|
-
|
16
|
-
def enum_expectation(attr, value)
|
17
|
-
expect(value).to include(subject.send(attr).to_sym)
|
18
|
-
end
|
19
|
-
|
20
|
-
def type_expectation(attr, value)
|
21
|
-
assert_type = value != :Boolean ? be_kind_of(Kernel.const_get(value)) : be_boolean
|
22
|
-
expect(subject.send(attr)).to assert_type
|
23
|
-
end
|
24
|
-
|
25
|
-
def has_attributes_expectation(attr, options) options.each do |key, value|
|
26
|
-
send("#{key}_expectation", attr, value)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def association_expectation(type, model)
|
31
|
-
if type == :has_many
|
32
|
-
expect(subject).to respond_to("#{model.to_s.singularize}_ids")
|
33
|
-
elsif type == :belongs_to
|
34
|
-
%W(#{model}= #{model}_id #{model}_id=).each do |method|
|
35
|
-
expect(subject).to respond_to(method)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|