expected 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/expected/matchers.rb +5 -2
- data/lib/expected/matchers/be_a_concern.rb +70 -0
- data/lib/expected/matchers/extend_module.rb +68 -0
- data/lib/expected/matchers/have_attr_accessor.rb +2 -0
- data/lib/expected/matchers/include_module.rb +67 -0
- data/lib/expected/matchers/inherit_from.rb +1 -1
- data/lib/expected/version.rb +2 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66f6dcc60d13674d39514a6681853892400394ac704427369b587cd8f790c3fa
|
4
|
+
data.tar.gz: fce7d948542985fa557398625de1c64e0411a8d98789a5a62edbc19ff7a6093a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89b1776f9c5ce6730cc148adcd86243c4cd802043f0f87cf7bab8e913dd47a5013b9ceb918047af01c2ae9d635e80cd2c759489904e26a73d3d1a7beeaf42181
|
7
|
+
data.tar.gz: d34e29d614a038109302e5d00e2b2257529af933853c267c8e31f05b69694bfb607d97961a5c3ff6551d9b19ad2168c9c8cc4da0c140afdded25e2b48ca8fb5a
|
data/lib/expected/matchers.rb
CHANGED
@@ -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/
|
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/
|
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
|
@@ -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
|
data/lib/expected/version.rb
CHANGED
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
|
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:
|
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
|