unidom-common-rspec 0.1 → 0.2

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: 8d23bd1137ce8d873c7be52df8604f739ceabdfd
4
- data.tar.gz: fd32faffa2cd96df1c24add30f0ae6691055f719
3
+ metadata.gz: d0d48e1ac08e611d4dd95378ee882855250685c7
4
+ data.tar.gz: 98f45cc9b4fc220ab9acb8e7fc5a9caa0b220d11
5
5
  SHA512:
6
- metadata.gz: 9cf42e17f3a52cb28d2365c1a925ee36fe5895ca41f6181e8983ecbd02d4e977536ee925f211b509c075389bd4695eea2396e5923bf572b5c9ed6adc328b0491
7
- data.tar.gz: 2de70ab479b1bb5f71c694febf611e7391402ab3038ec3cac10a6a0d0d32baa2f5dba70e846cab681548cba4fb4c0989e192dffe9cf5d096f5c3228c1cb60b51
6
+ metadata.gz: 856486f87c49af80c99b7e2b87fd205ec097d6be20eb9d70868518c669c4e3013e3ca646344fddc2aaef951aa4713a92e79782293e09e01969e4eed05f63d770
7
+ data.tar.gz: 930fb8d810301ce089166d29018ed08c9e50d3c3da630419aa384b7ef10b3205e9e180085840a0c3ccbfa5f1dacea4cbb00e8b941e66e0762b8edbb507f31efc
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/CHANGELOG.md CHANGED
@@ -2,3 +2,6 @@
2
2
 
3
3
  ## v0.1
4
4
  1. Scope shared examples
5
+
6
+ ## v0.2
7
+ 1. Validates shared examples
data/README.md CHANGED
@@ -1,9 +1,20 @@
1
1
  # Unidom Common RSpec Unidom Common RSpec 库
2
2
 
3
3
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
4
+ [![Gem Version](https://badge.fury.io/rb/unidom-common-rspec.svg)](https://badge.fury.io/rb/unidom-common-rspec)
5
+ [![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/unidom-common-rspec.svg)](https://gemnasium.com/github.com/topbitdu/unidom-common-rspec)
4
6
 
5
7
  Unidom Common RSpec is a RSpec-based Shared Example for the Unidom Common-based models. Unidom Common RSpec 是为 Unidom Common 设计的基于 RSpec 的共享测试用例。
6
8
 
9
+
10
+
11
+ ## Recent Update
12
+
13
+ Check out the [Road Map](ROADMAP.md) to find out what's the next.
14
+ Check out the [Change Log](CHANGELOG.md) to find out what's new.
15
+
16
+
17
+
7
18
  ## Installation
8
19
 
9
20
  Add this line to your application's Gemfile:
@@ -20,8 +31,12 @@ Or install it yourself as:
20
31
 
21
32
  $ gem install unidom-common-rspec
22
33
 
34
+
35
+
23
36
  ## Usage
24
37
 
38
+ ### Scope shared examples Scope 共享用例
39
+
25
40
  Assume the model class is ``Person``, the ``person_spec.rb`` looks like the following:
26
41
  If the ``count_diff`` is set to 'E', an error was expected to be raised.
27
42
  ```ruby
@@ -54,18 +69,49 @@ describe Person, type: :model do
54
69
  end
55
70
  ```
56
71
 
72
+ ### Validates shared examples Validates 共享用例
73
+
74
+ Assume the model class is ``Person``, the ``person_spec.rb`` looks like the following:
75
+ ```ruby
76
+ require 'rails_helper'
77
+
78
+ describe Person, type: :model do
79
+
80
+ context '.validates' do
81
+
82
+ tim_attributes = { name: 'Tim' }
83
+
84
+ it_behaves_like 'validates', tim_attributes, :name,
85
+ { } => 0,
86
+ { name: nil } => 2,
87
+ { name: '' } => 2,
88
+ { name: 'A' } => 1,
89
+ { name: 'AA' } => 0,
90
+ { name: '0' } => 1,
91
+ { name: '00' } => 0,
92
+ { name: 0 } => 1
93
+
94
+ end
95
+
96
+ end
97
+ ```
98
+
99
+
100
+
57
101
  ## Development
58
102
 
59
103
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
104
 
61
105
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
106
 
107
+
108
+
63
109
  ## Contributing
64
110
 
65
111
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/unidom-common-rspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
66
112
 
67
113
 
114
+
68
115
  ## License
69
116
 
70
117
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
71
-
data/ROADMAP.md CHANGED
@@ -2,3 +2,6 @@
2
2
 
3
3
  ## v0.1
4
4
  1. Scope shared examples
5
+
6
+ ## v0.2
7
+ 1. Validates shared examples
@@ -1,6 +1,7 @@
1
1
  require "unidom/common/rspec/version"
2
2
 
3
3
  require 'unidom/common/rspec/scope_shared_examples'
4
+ require 'unidom/common/rspec/validates_shared_examples'
4
5
 
5
6
  module Unidom
6
7
  module Common
@@ -0,0 +1,35 @@
1
+ shared_examples 'validates' do |model_attributes, attribute_name, error_attributes_collection|
2
+
3
+ attribute_name = attribute_name.to_sym
4
+
5
+ describe "##{attribute_name}" do
6
+
7
+ it 'is responded to' do expect(described_class.new).to respond_to(attribute_name) end
8
+
9
+ error_attributes_collection.each do |error_attributes, error_count|
10
+
11
+ title_attributes = error_attributes.clone
12
+ title_attributes.each { |k, v|
13
+ value_length = v.is_a?(String) ? v.length : 0
14
+ title_attributes[k] = "#{v[0..7]}...#{v[value_length-7..value_length]} (#{value_length} characters)" if (value_length>64)
15
+ }
16
+
17
+ describe title_attributes.inspect do
18
+
19
+ error_instance = described_class.new model_attributes.merge(error_attributes)
20
+ #error_instance.attributes = error_attributes
21
+ error_instance.valid?
22
+ count_errors = "has #{error_count} error#{error_count>1 ? 's' : ''}"
23
+
24
+ if error_count>0
25
+ it 'is invalid' do expect(error_instance).to be_invalid end
26
+ it count_errors do expect(error_instance.errors[attribute_name].size).to eq(error_count) end
27
+ else
28
+ it 'is valid' do expect(error_instance).to be_valid end
29
+ end
30
+
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -1,7 +1,7 @@
1
1
  module Unidom
2
2
  module Common
3
3
  module RSpec
4
- VERSION = '0.1'
4
+ VERSION = '0.2'
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.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-24 00:00:00.000000000 Z
11
+ date: 2016-12-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/setup
89
89
  - lib/unidom/common/rspec.rb
90
90
  - lib/unidom/common/rspec/scope_shared_examples.rb
91
+ - lib/unidom/common/rspec/validates_shared_examples.rb
91
92
  - lib/unidom/common/rspec/version.rb
92
93
  - unidom-common-rspec.gemspec
93
94
  homepage: https://github.com/topbitdu/unidom-common-rspec