smart_rspec 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -42
- data/lib/smart_rspec/support/assertions.rb +11 -7
- data/lib/smart_rspec/version.rb +1 -1
- data/spec/factories/user.rb +2 -0
- data/spec/smart_rspec/macros_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f93d0876da7f46893ef2d4c9ab277d4e3914999
|
4
|
+
data.tar.gz: 5299cc3f8aa245f8091121b6927b20289372e90f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d748af42e2e3a22be358857de32e4f55cabbef5a891e35de140aa0b5a19fd2da15a7f9a0fc706ad3f9ec8e35c89d53b69f261cdb0e0c0e29df906ea5b50fb8b3
|
7
|
+
data.tar.gz: 46687f5c6aaf73b51190d23e3fed62f8a8b36b693a398c62c5d7d1099dca8be10db640fc81e472cc42815a58050bd3a920be9176a20b46e30b0b62f7e7637fde
|
data/README.md
CHANGED
@@ -9,7 +9,10 @@ It's time to make your specs even more awesome! SmartRspec adds useful macros an
|
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
|
-
Compatible with
|
12
|
+
Compatible with:
|
13
|
+
|
14
|
+
* Ruby 1.9+
|
15
|
+
* ActiveRecord (model macros)
|
13
16
|
|
14
17
|
Add this line to your application's Gemfile:
|
15
18
|
|
@@ -40,21 +43,21 @@ end
|
|
40
43
|
* [belongs_to, has_one, has_many](#belongs_to-has_one-has_many)
|
41
44
|
* [fails_validation_of](#fails_validation_of)
|
42
45
|
* [Matchers](#matchers)
|
43
|
-
* ["Be" matchers](#)
|
44
|
-
* [be_ascending](#be_ascending)
|
45
|
-
* [be_a_bad_request](#be_a_bad_request)
|
46
|
-
* [be_a_list_of](#be_a_list_of)
|
46
|
+
* ["Be" matchers](#be-matchers)
|
47
47
|
* [be_boolean](#be_boolean)
|
48
|
-
* [be_descending](#be_descending)
|
49
48
|
* [be_email](#be_email)
|
50
|
-
* [be_image_url](#be_image_url)
|
51
49
|
* [be_url](#be_url)
|
52
|
-
|
50
|
+
* [be_image_url](#be_image_url)
|
51
|
+
* [be_a_list_of](#be_a_list_of)
|
52
|
+
* [be_ascending](#be_ascending)
|
53
|
+
* [be_descending](#be_descending)
|
54
|
+
* [be_a_bad_request](#be_a_bad_request)
|
55
|
+
* ["Have" matchers](#have-matchers)
|
53
56
|
* [have](#have)
|
54
57
|
* [have_at_least](#have_at_least)
|
55
58
|
* [have_at_most](#have_at_most)
|
56
59
|
* [have_error_on](#have_error_on)
|
57
|
-
* [Other matchers](#)
|
60
|
+
* [Other matchers](#other-matchers)
|
58
61
|
* [include_items](#include_items)
|
59
62
|
|
60
63
|
### Macros
|
@@ -132,27 +135,31 @@ fails_validation_of :foo, format: { with: /foo/, mock: 'bar' }
|
|
132
135
|
|
133
136
|
SmartRspec gathers a collection of custom useful matchers:
|
134
137
|
|
135
|
-
####
|
138
|
+
#### Be matchers
|
136
139
|
|
137
|
-
#####
|
140
|
+
##### be_boolean
|
141
|
+
``` ruby
|
142
|
+
it { expect(true).to be_boolean }
|
143
|
+
it { expect('true').not_to be_boolean }
|
144
|
+
```
|
138
145
|
|
146
|
+
##### be_email
|
139
147
|
``` ruby
|
140
|
-
it { expect(
|
141
|
-
it { expect(
|
148
|
+
it { expect('tiagopog@gmail.com').to be_email }
|
149
|
+
it { expect('tiagopog@gmail').not_to be_email }
|
142
150
|
```
|
143
151
|
|
144
|
-
#####
|
152
|
+
##### be_url
|
145
153
|
``` ruby
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
154
|
+
it { expect('http://adtangerine.com').to be_url }
|
155
|
+
it { expect('adtangerine.com').not_to be_url }
|
156
|
+
```
|
150
157
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
158
|
+
##### be_image_url
|
159
|
+
``` ruby
|
160
|
+
it { expect('http://adtangerine.com/foobar.png').to be_image_url }
|
161
|
+
it { expect('http://adtangerine.com/foobar.jpg').not_to be_image_url(:gif) }
|
162
|
+
it { expect('http://adtangerine.com/foo/bar').not_to be_image_url }
|
156
163
|
```
|
157
164
|
|
158
165
|
##### be_a_list_of
|
@@ -160,10 +167,11 @@ end
|
|
160
167
|
it { expect(Foo.fetch_api).to be_a_list_of(Foo)) }
|
161
168
|
```
|
162
169
|
|
163
|
-
#####
|
170
|
+
##### be_ascending
|
171
|
+
|
164
172
|
``` ruby
|
165
|
-
it { expect(
|
166
|
-
it { expect(
|
173
|
+
it { expect([1, 2, 3, 4]).to be_ascending }
|
174
|
+
it { expect([1, 4, 2, 3]).not_to be_ascending }
|
167
175
|
```
|
168
176
|
|
169
177
|
##### be_descending
|
@@ -172,26 +180,21 @@ it { expect([4, 3, 2, 1]).to be_descending }
|
|
172
180
|
it { expect([1, 2, 3, 4]).not_to be_descending }
|
173
181
|
```
|
174
182
|
|
175
|
-
#####
|
176
|
-
``` ruby
|
177
|
-
it { expect('tiagopog@gmail.com').to be_email }
|
178
|
-
it { expect('tiagopog@gmail').not_to be_email }
|
179
|
-
```
|
180
|
-
|
181
|
-
##### be_image_url
|
183
|
+
##### be_a_bad_request
|
182
184
|
``` ruby
|
183
|
-
|
184
|
-
|
185
|
-
it {
|
186
|
-
|
185
|
+
context 'unauthenticated' do
|
186
|
+
subject { get :profile }
|
187
|
+
it { is_expected.to be_a_bad_request }
|
188
|
+
end
|
187
189
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
it {
|
190
|
+
context 'authenticated' do
|
191
|
+
before { sign_in user }
|
192
|
+
subject { get :profile }
|
193
|
+
it { is_expected.to_not be_a_bad_request }
|
194
|
+
end
|
192
195
|
```
|
193
196
|
|
194
|
-
####
|
197
|
+
#### Have matchers
|
195
198
|
|
196
199
|
##### have(x).items
|
197
200
|
``` ruby
|
@@ -57,13 +57,17 @@ module SmartRspec
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def validates_uniqueness_of(attr, validation)
|
60
|
-
scoped
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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?
|
67
71
|
validation_expectation(attr, subject.send(attr), mock)
|
68
72
|
end
|
69
73
|
end
|
data/lib/smart_rspec/version.rb
CHANGED
data/spec/factories/user.rb
CHANGED
@@ -61,7 +61,7 @@ describe SmartRspec::Macros do
|
|
61
61
|
context 'when it receives a single arg' do
|
62
62
|
user = User.new(email: Faker::Internet.email)
|
63
63
|
|
64
|
-
fails_validation_of :email, presence: true, email: true
|
64
|
+
fails_validation_of :email, presence: true, email: true, uniqueness: true
|
65
65
|
fails_validation_of :name, length: { maximum: 80 }
|
66
66
|
fails_validation_of :username, uniqueness: { scope: :name, mock: user }, exclusion: { in: %w(foo bar) }
|
67
67
|
fails_validation_of :locale, inclusion: { in: %w(en pt) }
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Guedes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|