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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ff5716dab4e7adc48ce3d9a68f5ac08335c9447
4
- data.tar.gz: e00030e125016a66de204b9d106ae68e60d39ab3
3
+ metadata.gz: 3f93d0876da7f46893ef2d4c9ab277d4e3914999
4
+ data.tar.gz: 5299cc3f8aa245f8091121b6927b20289372e90f
5
5
  SHA512:
6
- metadata.gz: e84dac0dff7b0985a9a7925c61444e34bd26854ad5c354809932bfe74111207534dde371f239ed279af497afed89eb41520e4393cdf26cec96848031983c41b8
7
- data.tar.gz: 2ff5953423af3958d6fda0586f1794927024569f1f8114fcfc5587a848685d4345510a43474da70e015e0b6e8c9705c493a59f074b46c66d3acab26f55925ad8
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 Ruby 1.9+
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
- * ["Have" matchers](#)
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
- #### "Be" matchers
138
+ #### Be matchers
136
139
 
137
- ##### be_ascending
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([1, 2, 3, 4]).to be_ascending }
141
- it { expect([1, 4, 2, 3]).not_to be_ascending }
148
+ it { expect('tiagopog@gmail.com').to be_email }
149
+ it { expect('tiagopog@gmail').not_to be_email }
142
150
  ```
143
151
 
144
- ##### be_a_bad_request
152
+ ##### be_url
145
153
  ``` ruby
146
- context 'unauthenticated' do
147
- subject { get :profile }
148
- it { is_expected.to be_a_bad_request }
149
- end
154
+ it { expect('http://adtangerine.com').to be_url }
155
+ it { expect('adtangerine.com').not_to be_url }
156
+ ```
150
157
 
151
- context 'authenticated' do
152
- before { sign_in user }
153
- subject { get :profile }
154
- it { is_expected.to_not be_a_bad_request }
155
- end
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
- ##### be_boolean
170
+ ##### be_ascending
171
+
164
172
  ``` ruby
165
- it { expect(true).to be_boolean }
166
- it { expect('true').not_to be_boolean }
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
- ##### be_email
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
- it { expect('http://adtangerine.com/foobar.png').to be_image_url }
184
- it { expect('http://adtangerine.com/foobar.jpg').not_to be_image_url(:gif) }
185
- it { expect('http://adtangerine.com/foo/bar').not_to be_image_url }
186
- ```
185
+ context 'unauthenticated' do
186
+ subject { get :profile }
187
+ it { is_expected.to be_a_bad_request }
188
+ end
187
189
 
188
- ##### be_url
189
- ``` ruby
190
- it { expect('http://adtangerine.com').to be_url }
191
- it { expect('adtangerine.com').not_to be_url }
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
- #### "Have" matchers
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, scope =
61
- scoped_validation?(validation),
62
- validation.values_at(:scope).first
63
-
64
- it "is already in use#{" (scope: #{scope})" if scoped}" do
65
- mock = validation.values_at(:mock).first || subject.dup
66
- scoped && mock.send("#{validation[:scope]}=", subject.send(validation[:scope]))
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
@@ -1,3 +1,3 @@
1
1
  module SmartRspec
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -39,6 +39,8 @@ module Factories
39
39
  [:en, :pt].include?(locale) && @locale = locale
40
40
  end
41
41
 
42
+ def persisted?; true end
43
+
42
44
  def valid?
43
45
  %w(email father locale name username).each { |e| send("check_#{e}") }
44
46
  @errors.nil?
@@ -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.0
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-03-25 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport