expected 1.0.2 → 1.1.0

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
  SHA256:
3
- metadata.gz: 481afa189341a25a777d285269283587aa86b747be059e23a57e143f904757d7
4
- data.tar.gz: 96d327a39fb91d96d44332affceb3f806b9ebbe52b3833ff25fa4bfb86b06a32
3
+ metadata.gz: 66f6dcc60d13674d39514a6681853892400394ac704427369b587cd8f790c3fa
4
+ data.tar.gz: fce7d948542985fa557398625de1c64e0411a8d98789a5a62edbc19ff7a6093a
5
5
  SHA512:
6
- metadata.gz: 7aafb11ac42e9e72102d68bec3ea16ba654df89945114f35710f0f5f620062d8601d1ba71c379b89ab706c848f8257b36a8fb75870d4049733d467e122b81c28
7
- data.tar.gz: fc1b339b191a525bb4a1907f55c05ee54ef6584c34306a14d868ae3f66d3a2c5b8e4466810d9841d565e4efe2ab038ef015952742a715af96deb0694bfdf83f9
6
+ metadata.gz: 89b1776f9c5ce6730cc148adcd86243c4cd802043f0f87cf7bab8e913dd47a5013b9ceb918047af01c2ae9d635e80cd2c759489904e26a73d3d1a7beeaf42181
7
+ data.tar.gz: d34e29d614a038109302e5d00e2b2257529af933853c267c8e31f05b69694bfb607d97961a5c3ff6551d9b19ad2168c9c8cc4da0c140afdded25e2b48ca8fb5a
@@ -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 = 2
8
+ MINOR = 1
9
+ PATCH = 0
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.2
4
+ version: 1.1.0
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
@@ -35,10 +35,13 @@ files:
35
35
  - lib/expected.rb
36
36
  - lib/expected/configuration.rb
37
37
  - lib/expected/matchers.rb
38
+ - lib/expected/matchers/be_a_concern.rb
39
+ - lib/expected/matchers/extend_module.rb
38
40
  - lib/expected/matchers/have_attr_accessor.rb
39
41
  - lib/expected/matchers/have_attr_reader.rb
40
42
  - lib/expected/matchers/have_attr_writer.rb
41
43
  - lib/expected/matchers/have_constant.rb
44
+ - lib/expected/matchers/include_module.rb
42
45
  - lib/expected/matchers/inherit_from.rb
43
46
  - lib/expected/version.rb
44
47
  homepage: https://github.com/yelvert/expected