progne_tapera-rspec 0.1 → 0.2
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 +35 -0
- data/README.md +24 -0
- data/ROADMAP.md +3 -0
- data/bin/console +1 -1
- data/lib/progne_tapera/rspec/code_attribute_shared_examples.rb +47 -0
- data/lib/progne_tapera/rspec/version.rb +1 -1
- data/progne_tapera-rspec.gemspec +5 -5
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df528bff47c45a3c68d221180ce546ded17f16b5
|
4
|
+
data.tar.gz: bbecaa73f186f6958793ae0cc5c756fb19688406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9c17ea0664fd4c3b98f015d21628ef8395c64a15312ea1c5c0d0ffe6bd277d153f9d6b12c35cb4df5e466975a58110027d2a2778da16f01cc616b8396bc4127
|
7
|
+
data.tar.gz: 53d73a19d36e997b839e00b1c7e27da5b64f7c6002738a1692d894e52838821cf4858972bb8ba0d75d8a2b7716c0f9271c0955795fec7c94f0dc712cb1c8b699
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
progne_tapera-rspec (0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.5.0)
|
12
|
+
rspec-core (~> 3.5.0)
|
13
|
+
rspec-expectations (~> 3.5.0)
|
14
|
+
rspec-mocks (~> 3.5.0)
|
15
|
+
rspec-core (3.5.4)
|
16
|
+
rspec-support (~> 3.5.0)
|
17
|
+
rspec-expectations (3.5.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.5.0)
|
20
|
+
rspec-mocks (3.5.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.5.0)
|
23
|
+
rspec-support (3.5.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.12)
|
30
|
+
progne_tapera-rspec!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.12.5
|
data/README.md
CHANGED
@@ -26,6 +26,7 @@ Add the following line into the ``spec/rails_helper.rb`` file:
|
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
require 'progne_tapera/rspec/enum_code_shared_examples'
|
29
|
+
require 'progne_tapera/rspec/code_attribute_shared_examples'
|
29
30
|
```
|
30
31
|
|
31
32
|
Create the RSpec examples for your enum code (assume the enum code is Gender):
|
@@ -48,6 +49,29 @@ RSpec.describe Gender, type: :type do
|
|
48
49
|
end
|
49
50
|
```
|
50
51
|
|
52
|
+
Create the RSpec examples for your model which has the #gender_code attribute (assume the model is Person):
|
53
|
+
```ruby
|
54
|
+
# person.rb
|
55
|
+
class Person < ApplicationRecord
|
56
|
+
include Unidom::Common::ModelExtension
|
57
|
+
include ProgneTapera::EnumCode
|
58
|
+
|
59
|
+
code :gender # 这里将 #gender_code 字段和 Gender 枚举型集成起来。
|
60
|
+
end
|
61
|
+
|
62
|
+
# person_spec.rb
|
63
|
+
require 'rails_helper'
|
64
|
+
|
65
|
+
describe Person do
|
66
|
+
|
67
|
+
context '#gender' do
|
68
|
+
@person = Person.new
|
69
|
+
it_behaves_like 'code attribute', @person, :gender, Gender
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
51
75
|
|
52
76
|
|
53
77
|
## Development
|
data/ROADMAP.md
CHANGED
data/bin/console
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
shared_examples 'code attribute' do |model, attribute_name, enum|
|
2
|
+
|
3
|
+
describe "##{attribute_name}" do
|
4
|
+
it 'exists' do expect(model).to respond_to(attribute_name) end
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "##{attribute_name}=" do
|
8
|
+
|
9
|
+
it 'exists' do expect(model).to respond_to("#{attribute_name}=") end
|
10
|
+
|
11
|
+
enum.each do |enum_item|
|
12
|
+
it "should be able to assign #{enum_item.inspect} and load by ##{attribute_name}" do
|
13
|
+
model.send "#{attribute_name}=", enum_item
|
14
|
+
expect(model.send attribute_name).to eq(enum_item)
|
15
|
+
end
|
16
|
+
it "should be able to assign #{enum_item.inspect} and load by ##{attribute_name}_code" do
|
17
|
+
model.send "#{attribute_name}=", enum_item
|
18
|
+
expect(model.send "#{attribute_name}_code").to eq(enum_item.code)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "##{attribute_name}_code" do
|
25
|
+
|
26
|
+
it 'exists' do expect(model).to respond_to("#{attribute_name}_code") end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "##{attribute_name}_code=" do
|
31
|
+
|
32
|
+
it 'exists' do expect(model).to respond_to("#{attribute_name}_code=") end
|
33
|
+
|
34
|
+
enum.each do |enum_item|
|
35
|
+
it "should be able to assign #{enum_item.code.inspect} and load by ##{attribute_name}" do
|
36
|
+
model.send "#{attribute_name}_code=", enum_item.code
|
37
|
+
expect(model.send attribute_name).to eq(enum_item)
|
38
|
+
end
|
39
|
+
it "should be able to assign #{enum_item.code.inspect} and load by ##{attribute_name}_code" do
|
40
|
+
model.send "#{attribute_name}_code=", enum_item.code
|
41
|
+
expect(model.send "#{attribute_name}_code").to eq(enum_item.code)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/progne_tapera-rspec.gemspec
CHANGED
@@ -7,12 +7,12 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'progne_tapera-rspec'
|
8
8
|
spec.version = ProgneTapera::RSpec::VERSION
|
9
9
|
spec.authors = [ 'Topbit Du' ]
|
10
|
-
spec.email = [
|
10
|
+
spec.email = [ 'topbit.du@gmail.com' ]
|
11
11
|
|
12
12
|
spec.summary = %q{Progne Tapera RSpec 是为 Progne Tapera 设计的基于 RSpec 的共享测试用例。}
|
13
13
|
spec.description = %q{Progne Tapera RSpec is a RSpec-based Shared Example for the Progne Tapera-based enum implementation. Progne Tapera RSpec 是为 Progne Tapera 设计的基于 RSpec 的共享测试用例。}
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://github.com/topbitdu/progne_tapera-rspec'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
18
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
26
|
spec.bindir = "exe"
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = [ 'lib' ]
|
29
29
|
|
30
|
-
spec.add_development_dependency
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
33
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: progne_tapera-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
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-
|
11
|
+
date: 2016-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- CHANGELOG.md
|
67
67
|
- CODE_OF_CONDUCT.md
|
68
68
|
- Gemfile
|
69
|
+
- Gemfile.lock
|
69
70
|
- LICENSE.txt
|
70
71
|
- README.md
|
71
72
|
- ROADMAP.md
|
@@ -73,6 +74,7 @@ files:
|
|
73
74
|
- bin/console
|
74
75
|
- bin/setup
|
75
76
|
- lib/progne_tapera/rspec.rb
|
77
|
+
- lib/progne_tapera/rspec/code_attribute_shared_examples.rb
|
76
78
|
- lib/progne_tapera/rspec/enum_code_shared_examples.rb
|
77
79
|
- lib/progne_tapera/rspec/version.rb
|
78
80
|
- progne_tapera-rspec.gemspec
|