rspec-dry-struct 0.1.1 → 0.5.0

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
- SHA1:
3
- metadata.gz: 1ff418f131c19ff9a7733f3a2df8102e9d3cf31c
4
- data.tar.gz: dd0a772bc326b195a4e682abe31ba0c4453ecb8a
2
+ SHA256:
3
+ metadata.gz: a38aca21d268b46948b7a1df4da3373a7e24fd2b58efbb59bd1721cb0fae875a
4
+ data.tar.gz: 48b8b65549be390c7320d6719379d30a97f8a09c3c57c5d83b21ee249ca48ff9
5
5
  SHA512:
6
- metadata.gz: f905aa87bfe132182d771b3cc18df1b0acc048482c732503739e3a8a2807d7a024ac51b45dd85cd2c59393813188129981f694e08a1170b03ad51b117102d722
7
- data.tar.gz: fefe5550e4455f1d44ee0a79cb0808c1d4fb0cd68c49a49566aea49b8f3e6fc77b93fa3f05892f57b3af085d0c76de87344a1d08dcf40c75361f80b61dde65bb
6
+ metadata.gz: 5f960bee1582252848de5250b2f2d26f97f2967e161e57cfe89283bc41ff552a44b1ec8d5bc58470056aa15055f5f28ad8263a327628bc3a0d8d10a026fb1203
7
+ data.tar.gz: 0bcf65a2fe0fd2d6da8674a5a27a2533af0fecee5638238f77d451add49644663733ee26c52f69cce994950c747cbc522ed50fde6a76541514ce9c5e44e2e390
@@ -0,0 +1,10 @@
1
+ require: rubocop-rspec
2
+
3
+ Metrics/LineLength:
4
+ Max: 95
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Style/SpaceInsideHashLiteralBraces:
10
+ EnforcedStyle: no_space
data/README.md CHANGED
@@ -50,7 +50,20 @@ require 'spec_helper'
50
50
  RSpec.describe PersonName do
51
51
  describe 'attributes' do
52
52
  subject { described_class }
53
- it { is_expected.to have_attributes(:first_name, Types::Strict::String) }
53
+ it { is_expected.to have_attribute(:first_name) }
54
+ end
55
+ end
56
+ ```
57
+
58
+ or with specific attribute type
59
+
60
+ ```ruby
61
+ require 'spec_helper'
62
+
63
+ RSpec.describe PersonName do
64
+ describe 'attributes' do
65
+ subject { described_class }
66
+ it { is_expected.to have_attribute(:first_name, Types::Strict::String) }
54
67
  end
55
68
  end
56
69
  ```
@@ -1,12 +1,12 @@
1
1
  require 'rspec/core'
2
- require 'dry/types'
2
+ require 'dry/struct'
3
3
  require 'rspec/dry/struct/version'
4
4
  require 'rspec/dry/struct/matcher'
5
5
 
6
6
  module RSpec
7
7
  module Dry
8
8
  module Struct
9
- def have_attribute(name, type)
9
+ def have_attribute(name, type = nil) # rubocop:disable Style/PredicateName
10
10
  Matcher.new(name, type)
11
11
  end
12
12
  end
@@ -4,15 +4,19 @@ module RSpec
4
4
  class Matcher
5
5
  attr_reader :attr_name, :attr_type
6
6
 
7
- def initialize(attr_name, attr_type)
7
+ def initialize(attr_name, attr_type = nil)
8
8
  @attr_name = attr_name
9
9
  @attr_type = attr_type
10
10
  end
11
11
 
12
12
  def matches?(actual)
13
13
  @actual = actual
14
- @actual_attribute = actual.schema[@attr_name]
15
- @actual_attribute == @attr_type
14
+ attribute = actual.schema.find do |attr|
15
+ attr.name == @attr_name
16
+ end
17
+ @actual_attribute = attribute.type if attribute
18
+
19
+ attr_present? && correct_attr_type?
16
20
  end
17
21
 
18
22
  def description
@@ -24,8 +28,20 @@ module RSpec
24
28
  attr_type_mismatch_message(@actual)
25
29
  end
26
30
 
31
+ def failure_message_when_negated
32
+ "#{unexpected_message(@actual)}, but it was found"
33
+ end
34
+
27
35
  private
28
36
 
37
+ def attr_present?
38
+ !@actual_attribute.nil?
39
+ end
40
+
41
+ def correct_attr_type?
42
+ @attr_type.nil? || @actual_attribute == @attr_type
43
+ end
44
+
29
45
  def attr_not_found_message(actual)
30
46
  "#{expected_message(actual)}, but it was not found"
31
47
  end
@@ -37,6 +53,10 @@ module RSpec
37
53
  def expected_message(actual)
38
54
  "expected #{actual} to have #{@attr_name.inspect} attribute"
39
55
  end
56
+
57
+ def unexpected_message(actual)
58
+ expected_message(actual).gsub('to have', 'to not have')
59
+ end
40
60
  end
41
61
  end
42
62
  end
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Dry
3
3
  module Struct
4
- VERSION = '0.1.1'.freeze
4
+ VERSION = '0.5.0'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -20,9 +20,11 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_runtime_dependency 'rspec', '>= 3.0'
24
- spec.add_runtime_dependency 'dry-types', '~> 0.8'
23
+ spec.add_runtime_dependency 'rspec'
24
+ spec.add_runtime_dependency 'dry-struct'
25
+ spec.add_runtime_dependency 'dry-types', '>= 0.15.0'
25
26
 
26
- spec.add_development_dependency 'bundler', '~> 1.11'
27
- spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'rspec-its'
29
+ spec.add_development_dependency 'rake'
28
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-dry-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Kukunin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-09 00:00:00.000000000 Z
11
+ date: 2020-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,56 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-struct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: dry-types
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: '0.8'
47
+ version: 0.15.0
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: '0.8'
54
+ version: 0.15.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
- version: '1.11'
75
+ version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - "~>"
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
- version: '1.11'
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - "~>"
87
+ - - ">="
60
88
  - !ruby/object:Gem::Version
61
- version: '10.0'
89
+ version: '0'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - "~>"
94
+ - - ">="
67
95
  - !ruby/object:Gem::Version
68
- version: '10.0'
96
+ version: '0'
69
97
  description: RSpec `have_attribute` matcher for dry-struct gem
70
98
  email:
71
99
  - sergey.kukunin@gmail.com
@@ -75,6 +103,7 @@ extra_rdoc_files: []
75
103
  files:
76
104
  - ".gitignore"
77
105
  - ".rspec"
106
+ - ".rubocop.yml"
78
107
  - ".travis.yml"
79
108
  - Gemfile
80
109
  - LICENSE
@@ -104,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
133
  - !ruby/object:Gem::Version
105
134
  version: '0'
106
135
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.5.1
136
+ rubygems_version: 3.0.3
109
137
  signing_key:
110
138
  specification_version: 4
111
139
  summary: RSpec matcher for dry-struct gem