unidom-common-rspec 0.9.1 → 0.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e28568165c67bc6f4aa46a5e162f3fdc4b2558b
4
- data.tar.gz: e3621f4fe0cbd2ad0c3614f88443893e91d1bc0c
3
+ metadata.gz: bc9f1aade781883ed8d968ddd012226828dc9f21
4
+ data.tar.gz: e0dbea08eb51150996cf6c45bf843c91d56963d8
5
5
  SHA512:
6
- metadata.gz: 4c6c1a846436b66b8009a05ca4be54939ba5ee4f44547d877f802251454b9a6b2f94bf36fa21f57a521155b7fdb0c2060479cf37058960a79f4616092f811bac
7
- data.tar.gz: 3fee500adaed6ba6910d2488354639c5322d9df93251db2b3c8847b82db7e594a9ad8e54194a687dc11c7edb7606aadc827b60609313185606b7effed12f3470
6
+ metadata.gz: 7c74dd4f8f502ed40ab419689d3ed26745c2fccd568a1fd5c374533300bdc1a3f68224d77da38a83ac38ec1a9ff2ebf23ab6bfe3d031d208937b857e6f4fb995
7
+ data.tar.gz: 5d18a4e0e28d2290753962e3dfac8d25cc960fe2969b993fafc8500b6c9db6cfaf6cbda4bde88d4ee1f3de3b150e1b66383c61a44b940d1b10f369f99ad0a9b7
data/CHANGELOG.md CHANGED
@@ -47,3 +47,6 @@
47
47
 
48
48
  ## v0.9.1
49
49
  1. Improve the Validates Text shared examples for the length
50
+
51
+ ## v0.10
52
+ 1. Assert Present shared examples
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unidom-common-rspec (0.9)
4
+ unidom-common-rspec (0.9.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
@@ -1,5 +1,7 @@
1
1
  require "unidom/common/rspec/version"
2
2
 
3
+ require 'unidom/common/rspec/assert_present_shared_examples'
4
+
3
5
  require 'unidom/common/rspec/each_validator_shared_examples'
4
6
 
5
7
  require 'unidom/common/rspec/scope_shared_examples'
@@ -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
@@ -1,7 +1,7 @@
1
1
  module Unidom
2
2
  module Common
3
3
  module RSpec
4
- VERSION = '0.9.1'
4
+ VERSION = '0.10'
5
5
  end
6
6
  end
7
7
  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.9.1
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-20 00:00:00.000000000 Z
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