expected 1.0.0 → 1.1.2

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
2
  SHA256:
3
- metadata.gz: '0954ddfccf5072455413c702650c98e39ccdbd72a1db7806463598e5c6c0e52b'
4
- data.tar.gz: c41841fcb0cfcfde9dfff9c1c27445f88c10a168254c965ea681a0e62676ee0c
3
+ metadata.gz: bbca42d3e57b1a222b2e75768bba23ef79eceec10c59e25388d0234cdd5099c2
4
+ data.tar.gz: ff40dd47a526a18912391837d1346c89aa9c422d6c21d081c13959aac67a3975
5
5
  SHA512:
6
- metadata.gz: a6cf5251016d8d3f9b36af9ac429a0e9c8f433ee4c03b687a438e339d84361c913df7b63f6779597b49f0fb675ca4998c9da8a066e1371458ad04c1dff3675b5
7
- data.tar.gz: bb7461e7f4e02295962c7b52288e86a710bf72f93f7a6ab4129eb29a8f9b7d27a66c50c95eea4b0d8681d0ed620b95f0237cf02818b5c5fda5de1e30f81f82c7
6
+ metadata.gz: 93552e9c8c85b6291b02e82a687748d69122f8458e38a2504a2ab8a3babadb9a11e9ff97af33419241201ac303223bf8498f9e2d4635909fc61f98ff75e1a90d
7
+ data.tar.gz: 971093756132a91567d723e76abff892adfe71d8f31861a0c9962e8d482188907f469c4439e90f2cb93687a9494ea13826e3edf29c6e04d204d497e511eee05e
data/README.md CHANGED
@@ -19,10 +19,9 @@ end
19
19
  ```
20
20
 
21
21
  ### Add to RSpec
22
- Add the following to your projects `spec/rails_helper.rb` for Rails apps, or `spec/spec_helper.rb for non-Rails apps.
22
+ Add the following to your projects `spec/rails_helper.rb` for Rails apps, or `spec/spec_helper.rb` for non-Rails apps.
23
23
  ```ruby
24
- Expected.configure do |config|
25
- end
24
+ Expected.configure
26
25
  ```
27
26
 
28
27
 
@@ -33,12 +32,22 @@ end
33
32
 
34
33
 
35
34
 
36
- ### `inherit_from`
37
- Used to test inheritance
35
+ ### `be_a_concern`
36
+ Used to test that a Module is an ActiveSupport::Concern
38
37
 
39
38
  ```ruby
40
- # Test if the subject inherits from the supplied Class
41
- it { is_expected.to inherit_from(SomeClass) }
39
+ # Test if the subject is an ActiveSupport::Concern`
40
+ it { is_expected.to be_a_concern }
41
+ ```
42
+
43
+
44
+
45
+ ### `extend_module`
46
+ Used to test that a Class or Module extends the supplied Module
47
+
48
+ ```ruby
49
+ # Test if the subject extends the supplied Module
50
+ it { is_expected.to extend_module(SomeModule) }
42
51
  ```
43
52
 
44
53
 
@@ -89,6 +98,26 @@ it { is_expected.to have_attr_accessor(:attribute) }
89
98
 
90
99
 
91
100
 
101
+ ### `include_module`
102
+ Used to test that a Class or Module includes the supplied Module
103
+
104
+ ```ruby
105
+ # Test if the subject includes the supplied Module
106
+ it { is_expected.to include_module(SomeModule) }
107
+ ```
108
+
109
+
110
+
111
+ ### `inherit_from`
112
+ Used to test inheritance
113
+
114
+ ```ruby
115
+ # Test if the subject inherits from the supplied Class
116
+ it { is_expected.to inherit_from(SomeClass) }
117
+ ```
118
+
119
+
120
+
92
121
  ## License
93
122
  Expected is copyright © 2019-2020 Taylor Yelverton.
94
123
  It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -7,7 +7,12 @@ module Expected
7
7
  # Configure the library
8
8
  # @yield [Configuration]
9
9
  def configure
10
- yield configuration
10
+ yield configuration if block_given?
11
+ return unless defined?(::RSpec)
12
+ ::RSpec.configure do |config|
13
+ config.include(Matchers)
14
+ end
15
+ configuration
11
16
  end
12
17
 
13
18
  # Memoized {Configuration}
@@ -6,8 +6,11 @@ module Expected
6
6
  end
7
7
  end
8
8
 
9
+ require 'expected/matchers/be_a_concern'
10
+ require 'expected/matchers/extend_module'
9
11
  require 'expected/matchers/have_constant'
10
- require 'expected/matchers/inherit_from'
12
+ require 'expected/matchers/have_attr_accessor'
11
13
  require 'expected/matchers/have_attr_reader'
12
14
  require 'expected/matchers/have_attr_writer'
13
- require 'expected/matchers/have_attr_accessor'
15
+ require 'expected/matchers/include_module'
16
+ require 'expected/matchers/inherit_from'
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'expected/matchers/extend_module'
4
+
5
+ module Expected
6
+ # :nodoc:
7
+ module Matchers
8
+
9
+ # Used to test inheritance
10
+ # @return [BeAConcernMatcher]
11
+ #
12
+ # @example Test if the subject is an ActiveSupport::Concern
13
+ # it { is_expected.to be_a_concern }
14
+ #
15
+ def be_a_concern
16
+ BeAConcernMatcher.new
17
+ end
18
+
19
+ # Class used by {#be_a_concern}
20
+ class BeAConcernMatcher
21
+ attr_reader :extend_module_matcher, :subject
22
+
23
+ def initialize
24
+ @extend_module_matcher = ExtendModuleMatcher.new(ActiveSupport::Concern)
25
+ end
26
+
27
+ # Run the test
28
+ # @param subject The thing to test against
29
+ # @return [True] If the test passes
30
+ # @return [False] if the test fails
31
+ def matches?(subject)
32
+ self.subject = subject
33
+ @extend_module_matcher.matches?(subject)
34
+ end
35
+
36
+ # @return [String]
37
+ def failure_message
38
+ "Expected #{expectation}"
39
+ end
40
+
41
+ # @return [String]
42
+ def failure_message_when_negated
43
+ "Did not expect #{expectation}"
44
+ end
45
+
46
+ # @return [String]
47
+ def description
48
+ 'be_a_concern'
49
+ end
50
+
51
+ private
52
+
53
+ # The thing to test against
54
+ # @return [Module]
55
+ def subject=(subject)
56
+ unless subject.instance_of?(Module)
57
+ raise "The subject for BeAConcernMatcher must be a Module, but was: `#{subject.inspect}`"
58
+ end
59
+ @subject = subject
60
+ end
61
+
62
+ # @return String
63
+ def expectation
64
+ "<#{subject.inspect}> to be an ActiveSupport::Concern"
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expected
4
+ # :nodoc:
5
+ module Matchers
6
+
7
+ # Used to test inheritance
8
+ # @param expected_module [Class]
9
+ # @return [ExtendModuleMatcher]
10
+ #
11
+ # @example Test if the subject extends the supplied Module
12
+ # it { is_expected.to extend(SomeClass) }
13
+ #
14
+ def extend_module(expected_module)
15
+ ExtendModuleMatcher.new(expected_module)
16
+ end
17
+
18
+ # Class used by {#extend_module}
19
+ class ExtendModuleMatcher
20
+ attr_reader :expected_module, :subject
21
+
22
+ # @param expected_module [Class] The module the {#subject} is expected to include
23
+ def initialize(expected_module)
24
+ @expected_module = expected_module
25
+ end
26
+
27
+ # Run the test
28
+ # @param subject The thing to test against
29
+ # @return [True] If the test passes
30
+ # @return [False] if the test fails
31
+ def matches?(subject)
32
+ self.subject = subject
33
+ klass = self.subject.singleton_class
34
+ klass.included_modules.include? expected_module
35
+ end
36
+
37
+ # @return [String]
38
+ def failure_message
39
+ "Expected #{expectation}"
40
+ end
41
+
42
+ # @return [String]
43
+ def failure_message_when_negated
44
+ "Did not expect #{expectation}"
45
+ end
46
+
47
+ # @return [String]
48
+ def description
49
+ "extend_module: <#{expected_module.inspect}>"
50
+ end
51
+
52
+ private
53
+
54
+ # The thing to test against
55
+ # @return [Class, Module]
56
+ def subject=(subject)
57
+ @subject = subject.instance_of?(Class) || subject.is_a?(Module) ? subject : subject.class
58
+ end
59
+
60
+ # @return String
61
+ def expectation
62
+ "<#{subject.inspect}> to extend <#{expected_module.inspect}>"
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'securerandom'
4
+ require 'expected/matchers/have_attr_reader'
5
+ require 'expected/matchers/have_attr_writer'
4
6
 
5
7
  module Expected
6
8
  # :nodoc:
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Expected
4
+ # :nodoc:
5
+ module Matchers
6
+
7
+ # Used to test inheritance
8
+ # @param expected_module [Module]
9
+ # @return [IncludeModuleMatcher]
10
+ #
11
+ # @example Test if the subject includes the supplied Module
12
+ # it { is_expected.to include_module(SomeModule) }
13
+ #
14
+ def include_module(expected_module)
15
+ IncludeModuleMatcher.new(expected_module)
16
+ end
17
+
18
+ # Class used by {#include_module}
19
+ class IncludeModuleMatcher
20
+ attr_reader :expected_module, :subject
21
+
22
+ # @param expected_module [Module] The module the {#subject} is expected to include
23
+ def initialize(expected_module)
24
+ @expected_module = expected_module
25
+ end
26
+
27
+ # Run the test
28
+ # @param subject The thing to test against
29
+ # @return [True] If the test passes
30
+ # @return [False] if the test fails
31
+ def matches?(subject)
32
+ self.subject = subject
33
+ self.subject.included_modules.include? expected_module
34
+ end
35
+
36
+ # @return [String]
37
+ def failure_message
38
+ "Expected #{expectation}"
39
+ end
40
+
41
+ # @return [String]
42
+ def failure_message_when_negated
43
+ "Did not expect #{expectation}"
44
+ end
45
+
46
+ # @return [String]
47
+ def description
48
+ "include_module: <#{expected_module.inspect}>"
49
+ end
50
+
51
+ private
52
+
53
+ # The thing to test against
54
+ # @return [Class, Module]
55
+ def subject=(subject)
56
+ @subject = subject.instance_of?(Class) || subject.is_a?(Module) ? subject : subject.class
57
+ end
58
+
59
+ # @return String
60
+ def expectation
61
+ "<#{subject.inspect}> to include <#{expected_module.inspect}>"
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+ end
@@ -15,7 +15,7 @@ module Expected
15
15
  InheritFromMatcher.new(expected_ancestor)
16
16
  end
17
17
 
18
- # Class used by {#have_constant}
18
+ # Class used by {#inherit_from}
19
19
  class InheritFromMatcher
20
20
  attr_reader :expected_ancestor, :subject
21
21
 
@@ -5,8 +5,8 @@ module Expected
5
5
  # Contains version information
6
6
  module Version
7
7
  MAJOR = 1
8
- MINOR = 0
9
- PATCH = 0
8
+ MINOR = 1
9
+ PATCH = 2
10
10
 
11
11
  end
12
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expected
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Yelverton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-07 00:00:00.000000000 Z
11
+ date: 2021-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 5.0.0
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: '5.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 5.0.0
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '5.0'
33
27
  description: RSpec's missing matchers
34
28
  email: rubygems@yelvert.io
35
29
  executables: []
@@ -41,10 +35,13 @@ files:
41
35
  - lib/expected.rb
42
36
  - lib/expected/configuration.rb
43
37
  - lib/expected/matchers.rb
38
+ - lib/expected/matchers/be_a_concern.rb
39
+ - lib/expected/matchers/extend_module.rb
44
40
  - lib/expected/matchers/have_attr_accessor.rb
45
41
  - lib/expected/matchers/have_attr_reader.rb
46
42
  - lib/expected/matchers/have_attr_writer.rb
47
43
  - lib/expected/matchers/have_constant.rb
44
+ - lib/expected/matchers/include_module.rb
48
45
  - lib/expected/matchers/inherit_from.rb
49
46
  - lib/expected/version.rb
50
47
  homepage: https://github.com/yelvert/expected