unidom-common-rspec 0.9.1 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +28 -1
- data/lib/unidom/common/rspec.rb +2 -0
- data/lib/unidom/common/rspec/assert_present_shared_examples.rb +30 -0
- data/lib/unidom/common/rspec/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc9f1aade781883ed8d968ddd012226828dc9f21
|
4
|
+
data.tar.gz: e0dbea08eb51150996cf6c45bf843c91d56963d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c74dd4f8f502ed40ab419689d3ed26745c2fccd568a1fd5c374533300bdc1a3f68224d77da38a83ac38ec1a9ff2ebf23ab6bfe3d031d208937b857e6f4fb995
|
7
|
+
data.tar.gz: 5d18a4e0e28d2290753962e3dfac8d25cc960fe2969b993fafc8500b6c9db6cfaf6cbda4bde88d4ee1f3de3b150e1b66383c61a44b940d1b10f369f99ad0a9b7
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -47,6 +47,12 @@ class Person < ApplicationRecord
|
|
47
47
|
has_many :pets
|
48
48
|
has_one :identity_card
|
49
49
|
|
50
|
+
def own_identity_card!(identity_card, at: Time.now)
|
51
|
+
self.identity_card.soft_destroy
|
52
|
+
self.identity_card = identity_card
|
53
|
+
save!
|
54
|
+
end
|
55
|
+
|
50
56
|
end
|
51
57
|
|
52
58
|
# pet.rb
|
@@ -333,7 +339,6 @@ describe Person, type: :model do
|
|
333
339
|
end
|
334
340
|
```
|
335
341
|
|
336
|
-
|
337
342
|
### Each Validator shared examples 单属性验证器共享用例
|
338
343
|
|
339
344
|
The ``identification_number_validator_spec.rb`` looks like the following:
|
@@ -360,6 +365,28 @@ RSpec.describe IdentificationNumberValidator, type: :validator do
|
|
360
365
|
end
|
361
366
|
```
|
362
367
|
|
368
|
+
### Assert Present shared examples 必填参数共享用例
|
369
|
+
The ``person_spec.rb`` looks like the following:
|
370
|
+
```ruby
|
371
|
+
require 'rails_helper'
|
372
|
+
|
373
|
+
describe Person, type: :model do
|
374
|
+
|
375
|
+
context do
|
376
|
+
|
377
|
+
tim_attributes = { name: 'Tim' }
|
378
|
+
model = described_class.create! tim_attributes
|
379
|
+
|
380
|
+
tim_identity_card_attributes = { name: 'Tim', gender_code: '1', birth_date: '1980-07-01' }
|
381
|
+
identity_card_model = IdentityCard.create! tim_identity_card_attributes
|
382
|
+
|
383
|
+
it_behaves_like 'assert_present!', model, :own_identity_card!, [ identity_card, { at: Time.now } ], [ { 0 => :identity_card }, :at ]
|
384
|
+
|
385
|
+
end
|
386
|
+
|
387
|
+
end
|
388
|
+
```
|
389
|
+
|
363
390
|
|
364
391
|
|
365
392
|
## Development
|
data/lib/unidom/common/rspec.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
shared_examples 'assert_present!' do |model, method_name, arguments, required_argument_names|
|
2
|
+
|
3
|
+
context "##{method_name}" do
|
4
|
+
|
5
|
+
# argument
|
6
|
+
required_argument_names.each do |required_argument_name|
|
7
|
+
next unless required_argument_name.is_a? Hash #Numeric
|
8
|
+
it "should reject the #{required_argument_name.values.first} argument = nil" do
|
9
|
+
actual_arguments = arguments.dup
|
10
|
+
actual_arguments[required_argument_name.keys.first] = nil
|
11
|
+
expect { model.send method_name, *actual_arguments }.
|
12
|
+
to raise_error(ArgumentError, Regexp.new("\s+#{required_argument_name.values.first}\s+"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# keywords argument
|
17
|
+
required_argument_names.each do |required_argument_name|
|
18
|
+
next unless required_argument_name.is_a? Symbol
|
19
|
+
it "should reject the #{required_argument_name} argument = nil" do
|
20
|
+
actual_arguments = arguments.dup
|
21
|
+
actual_arguments[actual_arguments.length-1] = arguments.last.dup
|
22
|
+
actual_arguments.last[required_argument_name] = nil
|
23
|
+
expect { model.send method_name, *actual_arguments }.
|
24
|
+
to raise_error(ArgumentError, Regexp.new("\s+#{required_argument_name}\s+"))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unidom-common-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.10'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- bin/console
|
89
89
|
- bin/setup
|
90
90
|
- lib/unidom/common/rspec.rb
|
91
|
+
- lib/unidom/common/rspec/assert_present_shared_examples.rb
|
91
92
|
- lib/unidom/common/rspec/belongs_to_shared_examples.rb
|
92
93
|
- lib/unidom/common/rspec/each_validator_shared_examples.rb
|
93
94
|
- lib/unidom/common/rspec/has_many_shared_examples.rb
|