rspec-sleeping_king_studios 2.2.4 → 2.3.0.rc.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 +4 -4
- data/CHANGELOG.md +23 -1
- data/DEVELOPMENT.md +20 -30
- data/README.md +201 -10
- data/lib/rspec/sleeping_king_studios/concerns/example_constants.rb +94 -0
- data/lib/rspec/sleeping_king_studios/concerns/shared_example_group.rb +3 -1
- data/lib/rspec/sleeping_king_studios/concerns/toolbelt.rb +25 -0
- data/lib/rspec/sleeping_king_studios/concerns/wrap_env.rb +46 -0
- data/lib/rspec/sleeping_king_studios/examples/property_examples/class_properties.rb +66 -0
- data/lib/rspec/sleeping_king_studios/examples/property_examples/constants.rb +51 -0
- data/lib/rspec/sleeping_king_studios/examples/property_examples/predicates.rb +28 -0
- data/lib/rspec/sleeping_king_studios/examples/property_examples/private_properties.rb +64 -0
- data/lib/rspec/sleeping_king_studios/examples/property_examples/properties.rb +78 -0
- data/lib/rspec/sleeping_king_studios/examples/property_examples.rb +12 -117
- data/lib/rspec/sleeping_king_studios/matchers/core/have_property.rb +5 -2
- data/lib/rspec/sleeping_king_studios/matchers/core/have_property_matcher.rb +19 -10
- data/lib/rspec/sleeping_king_studios/matchers/core/have_reader.rb +5 -2
- data/lib/rspec/sleeping_king_studios/matchers/core/have_reader_matcher.rb +17 -8
- data/lib/rspec/sleeping_king_studios/matchers/core/have_writer.rb +5 -2
- data/lib/rspec/sleeping_king_studios/matchers/core/have_writer_matcher.rb +14 -7
- data/lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb +6 -6
- data/lib/rspec/sleeping_king_studios/version.rb +4 -4
- metadata +44 -8
@@ -0,0 +1,66 @@
|
|
1
|
+
# lib/rspec/sleeping_king_studios/examples/property_examples/class_properties.rb
|
2
|
+
|
3
|
+
require 'rspec/sleeping_king_studios/concerns/shared_example_group'
|
4
|
+
require 'rspec/sleeping_king_studios/examples'
|
5
|
+
require 'rspec/sleeping_king_studios/matchers/core/have_property'
|
6
|
+
require 'rspec/sleeping_king_studios/matchers/core/have_reader'
|
7
|
+
require 'rspec/sleeping_king_studios/matchers/core/have_writer'
|
8
|
+
|
9
|
+
module RSpec::SleepingKingStudios::Examples
|
10
|
+
module PropertyExamples
|
11
|
+
module ClassProperties
|
12
|
+
extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
|
13
|
+
|
14
|
+
shared_examples 'should have class reader' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
15
|
+
it "should have class reader :#{property}" do
|
16
|
+
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
17
|
+
expect(described_class).to have_reader(property)
|
18
|
+
else
|
19
|
+
expected_value = format_expected_value(expected_value)
|
20
|
+
|
21
|
+
expect(described_class).to have_reader(property).with_value(expected_value)
|
22
|
+
end # if-else
|
23
|
+
end # it
|
24
|
+
end # shared_examples
|
25
|
+
alias_shared_examples 'has class reader', 'should have class reader'
|
26
|
+
|
27
|
+
shared_examples 'should not have class reader' do |property|
|
28
|
+
it "should not have class reader :#{property}" do
|
29
|
+
expect(described_class).not_to have_reader(property)
|
30
|
+
end # it
|
31
|
+
end # shared_examples
|
32
|
+
alias_shared_examples 'does not have class reader', 'should not have class reader'
|
33
|
+
|
34
|
+
shared_examples 'should not have class writer' do |property|
|
35
|
+
writer_name = property.to_s.sub /\=\z/, ''
|
36
|
+
|
37
|
+
it "should not have class writer :#{writer_name}" do
|
38
|
+
expect(described_class).not_to have_writer(property)
|
39
|
+
end # it
|
40
|
+
end # shared_examples
|
41
|
+
alias_shared_examples 'does not have class writer', 'should not have class writer'
|
42
|
+
|
43
|
+
shared_examples 'should have class writer' do |property|
|
44
|
+
writer_name = property.to_s.sub /\=\z/, ''
|
45
|
+
|
46
|
+
it "should have class writer :#{writer_name}" do
|
47
|
+
expect(described_class).to have_writer(property)
|
48
|
+
end # it
|
49
|
+
end # shared_examples
|
50
|
+
alias_shared_examples 'has class writer', 'should have class writer'
|
51
|
+
|
52
|
+
shared_examples 'should have class property' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
53
|
+
it "should have class property :#{property}" do
|
54
|
+
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
55
|
+
expect(described_class).to have_property(property)
|
56
|
+
else
|
57
|
+
expected_value = format_expected_value(expected_value)
|
58
|
+
|
59
|
+
expect(described_class).to have_property(property).with_value(expected_value)
|
60
|
+
end # if-else
|
61
|
+
end # it
|
62
|
+
end # shared_examples
|
63
|
+
alias_shared_examples 'has class property', 'should have class property'
|
64
|
+
end # module
|
65
|
+
end # module
|
66
|
+
end # module
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# lib/rspec/sleeping_king_studios/examples/property_examples/constants.rb
|
2
|
+
|
3
|
+
require 'rspec/sleeping_king_studios/concerns/shared_example_group'
|
4
|
+
require 'rspec/sleeping_king_studios/examples'
|
5
|
+
require 'rspec/sleeping_king_studios/matchers/core/have_constant'
|
6
|
+
|
7
|
+
module RSpec::SleepingKingStudios::Examples
|
8
|
+
module PropertyExamples
|
9
|
+
module Constants
|
10
|
+
extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
|
11
|
+
|
12
|
+
shared_examples 'should have constant' do |constant_name, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
13
|
+
it "should have constant :#{constant_name}" do
|
14
|
+
if defined?(described_class) && described_class.is_a?(Module)
|
15
|
+
object = described_class
|
16
|
+
else
|
17
|
+
object = subject
|
18
|
+
end # if-else
|
19
|
+
|
20
|
+
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
21
|
+
expect(object).to have_constant(constant_name)
|
22
|
+
else
|
23
|
+
expected_value = format_expected_value(expected_value)
|
24
|
+
|
25
|
+
expect(object).to have_constant(constant_name).with_value(expected_value)
|
26
|
+
end # if-else
|
27
|
+
end # it
|
28
|
+
end # shared_examples
|
29
|
+
alias_shared_examples 'has constant', 'should have constant'
|
30
|
+
|
31
|
+
shared_examples 'should have immutable constant' do |constant_name, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
32
|
+
it "should have immutable constant :#{constant_name}" do
|
33
|
+
if defined?(described_class) && described_class.is_a?(Module)
|
34
|
+
object = described_class
|
35
|
+
else
|
36
|
+
object = subject
|
37
|
+
end # if-else
|
38
|
+
|
39
|
+
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
40
|
+
expect(object).to have_immutable_constant(constant_name)
|
41
|
+
else
|
42
|
+
expected_value = format_expected_value(expected_value)
|
43
|
+
|
44
|
+
expect(object).to have_immutable_constant(constant_name).with_value(expected_value)
|
45
|
+
end # if-else
|
46
|
+
end # it
|
47
|
+
end # shared_examples
|
48
|
+
alias_shared_examples 'has immutable constant', 'should have immutable constant'
|
49
|
+
end # module
|
50
|
+
end # module
|
51
|
+
end # module
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# lib/rspec/sleeping_king_studios/examples/property_examples/predicates.rb
|
2
|
+
|
3
|
+
require 'rspec/sleeping_king_studios/concerns/shared_example_group'
|
4
|
+
require 'rspec/sleeping_king_studios/examples/property_examples'
|
5
|
+
require 'rspec/sleeping_king_studios/matchers/core/have_predicate'
|
6
|
+
|
7
|
+
module RSpec::SleepingKingStudios::Examples
|
8
|
+
module PropertyExamples
|
9
|
+
module Predicates
|
10
|
+
extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
|
11
|
+
|
12
|
+
shared_examples 'should have predicate' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
13
|
+
it "should have predicate :#{property}?" do
|
14
|
+
object = defined?(instance) ? instance : subject
|
15
|
+
|
16
|
+
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
17
|
+
expect(object).to have_predicate(property)
|
18
|
+
else
|
19
|
+
expected_value = format_expected_value(expected_value)
|
20
|
+
|
21
|
+
expect(object).to have_predicate(property).with_value(expected_value)
|
22
|
+
end # if-else
|
23
|
+
end # it
|
24
|
+
end # shared_examples
|
25
|
+
alias_shared_examples 'has predicate', 'should have predicate'
|
26
|
+
end # module
|
27
|
+
end # module
|
28
|
+
end # module
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# lib/rspec/sleeping_king_studios/examples/property_examples/private_properties.rb
|
2
|
+
|
3
|
+
require 'rspec/sleeping_king_studios/concerns/shared_example_group'
|
4
|
+
require 'rspec/sleeping_king_studios/examples'
|
5
|
+
|
6
|
+
module RSpec::SleepingKingStudios::Examples
|
7
|
+
module PropertyExamples
|
8
|
+
module PrivateProperties
|
9
|
+
extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
|
10
|
+
|
11
|
+
shared_examples 'should have private reader' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
12
|
+
it "should have private reader :#{property}" do
|
13
|
+
object = defined?(instance) ? instance : subject
|
14
|
+
matcher = have_reader(property, :allow_private => true)
|
15
|
+
|
16
|
+
expect(object).not_to respond_to(property)
|
17
|
+
|
18
|
+
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
19
|
+
expect(object).to matcher
|
20
|
+
else
|
21
|
+
expected_value = format_expected_value(expected_value)
|
22
|
+
|
23
|
+
expect(object).to matcher.with_value(expected_value)
|
24
|
+
end # if-else
|
25
|
+
end # it
|
26
|
+
end # shared_examples
|
27
|
+
alias_shared_examples 'has private reader', 'should have private reader'
|
28
|
+
|
29
|
+
shared_examples 'should have private writer' do |property|
|
30
|
+
writer_name = :"#{property.to_s.sub(/=\z/, '')}="
|
31
|
+
|
32
|
+
it "should have private writer :#{writer_name}" do
|
33
|
+
object = defined?(instance) ? instance : subject
|
34
|
+
|
35
|
+
expect(object).not_to respond_to(writer_name)
|
36
|
+
|
37
|
+
expect(object).to have_writer(writer_name, :allow_private => true)
|
38
|
+
end # it
|
39
|
+
end # shared_examples
|
40
|
+
alias_shared_examples 'has private writer', 'should have private writer'
|
41
|
+
|
42
|
+
shared_examples 'should have private property' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
43
|
+
writer_name = :"#{property.to_s.sub(/=\z/, '')}="
|
44
|
+
|
45
|
+
it "should have private property :#{property}" do
|
46
|
+
object = defined?(instance) ? instance : subject
|
47
|
+
matcher = have_property(property, :allow_private => true)
|
48
|
+
|
49
|
+
expect(object).not_to respond_to(property)
|
50
|
+
expect(object).not_to respond_to(writer_name)
|
51
|
+
|
52
|
+
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
53
|
+
expect(object).to matcher
|
54
|
+
else
|
55
|
+
expected_value = format_expected_value(expected_value)
|
56
|
+
|
57
|
+
expect(object).to matcher.with_value(expected_value)
|
58
|
+
end # if-else
|
59
|
+
end # it
|
60
|
+
end # shared_examples
|
61
|
+
alias_shared_examples 'has private property', 'should have private property'
|
62
|
+
end # module
|
63
|
+
end # module
|
64
|
+
end # module
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# lib/rspec/sleeping_king_studios/examples/property_examples/properties.rb
|
2
|
+
|
3
|
+
require 'rspec/sleeping_king_studios/concerns/shared_example_group'
|
4
|
+
require 'rspec/sleeping_king_studios/examples/property_examples'
|
5
|
+
require 'rspec/sleeping_king_studios/matchers/core/have_property'
|
6
|
+
require 'rspec/sleeping_king_studios/matchers/core/have_reader'
|
7
|
+
require 'rspec/sleeping_king_studios/matchers/core/have_writer'
|
8
|
+
|
9
|
+
module RSpec::SleepingKingStudios::Examples
|
10
|
+
module PropertyExamples
|
11
|
+
module Properties
|
12
|
+
extend RSpec::SleepingKingStudios::Concerns::SharedExampleGroup
|
13
|
+
|
14
|
+
shared_examples 'should have reader' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION, allow_private: false|
|
15
|
+
it "should have reader :#{property}" do
|
16
|
+
object = defined?(instance) ? instance : subject
|
17
|
+
matcher = have_reader(property, :allow_private => allow_private)
|
18
|
+
|
19
|
+
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
20
|
+
expect(object).to matcher
|
21
|
+
else
|
22
|
+
expected_value = format_expected_value(expected_value)
|
23
|
+
|
24
|
+
expect(object).to matcher.with_value(expected_value)
|
25
|
+
end # if-else
|
26
|
+
end # it
|
27
|
+
end # shared_examples
|
28
|
+
alias_shared_examples 'has reader', 'should have reader'
|
29
|
+
|
30
|
+
shared_examples 'should not have reader' do |property, allow_private: false|
|
31
|
+
it "should not have reader :#{property}" do
|
32
|
+
object = defined?(instance) ? instance : subject
|
33
|
+
|
34
|
+
expect(object).not_to have_reader(property, :allow_private => allow_private)
|
35
|
+
end # it
|
36
|
+
end # shared_examples
|
37
|
+
alias_shared_examples 'does not have reader', 'should not have reader'
|
38
|
+
|
39
|
+
shared_examples 'should have writer' do |property, allow_private: false|
|
40
|
+
writer_name = property.to_s.sub /\=\z/, ''
|
41
|
+
|
42
|
+
it "should have writer :#{writer_name}" do
|
43
|
+
object = defined?(instance) ? instance : subject
|
44
|
+
|
45
|
+
expect(object).to have_writer(property, :allow_private => allow_private)
|
46
|
+
end # it
|
47
|
+
end # shared_examples
|
48
|
+
alias_shared_examples 'has writer', 'should have writer'
|
49
|
+
|
50
|
+
shared_examples 'should not have writer' do |property, allow_private: false|
|
51
|
+
writer_name = property.to_s.sub /\=\z/, ''
|
52
|
+
|
53
|
+
it "should not have writer :#{writer_name}" do
|
54
|
+
object = defined?(instance) ? instance : subject
|
55
|
+
|
56
|
+
expect(object).not_to have_writer(property, :allow_private => allow_private)
|
57
|
+
end # it
|
58
|
+
end # shared_examples
|
59
|
+
alias_shared_examples 'does not have writer', 'should not have writer'
|
60
|
+
|
61
|
+
shared_examples 'should have property' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION, allow_private: false|
|
62
|
+
it "should have property :#{property}" do
|
63
|
+
object = defined?(instance) ? instance : subject
|
64
|
+
matcher = have_property(property, :allow_private => allow_private)
|
65
|
+
|
66
|
+
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
67
|
+
expect(object).to matcher
|
68
|
+
else
|
69
|
+
expected_value = format_expected_value(expected_value)
|
70
|
+
|
71
|
+
expect(object).to matcher.with_value(expected_value)
|
72
|
+
end # if-else
|
73
|
+
end # it
|
74
|
+
end # shared_examples
|
75
|
+
alias_shared_examples 'has property', 'should have property'
|
76
|
+
end # module
|
77
|
+
end # module
|
78
|
+
end # module
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# lib/rspec/sleeping_king_studios/examples/property_examples.rb
|
2
2
|
|
3
|
+
require 'sleeping_king_studios/tools/object_tools'
|
4
|
+
|
3
5
|
require 'rspec/sleeping_king_studios/concerns/shared_example_group'
|
4
6
|
require 'rspec/sleeping_king_studios/examples'
|
5
|
-
require 'rspec/sleeping_king_studios/
|
6
|
-
require 'rspec/sleeping_king_studios/
|
7
|
-
require 'rspec/sleeping_king_studios/
|
8
|
-
require 'rspec/sleeping_king_studios/
|
9
|
-
require 'rspec/sleeping_king_studios/
|
10
|
-
require 'sleeping_king_studios/tools/object_tools'
|
7
|
+
require 'rspec/sleeping_king_studios/examples/property_examples/class_properties'
|
8
|
+
require 'rspec/sleeping_king_studios/examples/property_examples/constants'
|
9
|
+
require 'rspec/sleeping_king_studios/examples/property_examples/private_properties'
|
10
|
+
require 'rspec/sleeping_king_studios/examples/property_examples/predicates'
|
11
|
+
require 'rspec/sleeping_king_studios/examples/property_examples/properties'
|
11
12
|
|
12
13
|
# Pregenerated example groups for testing the presence and value of reader and
|
13
14
|
# writer methods.
|
@@ -38,115 +39,9 @@ module RSpec::SleepingKingStudios::Examples::PropertyExamples
|
|
38
39
|
comparable_value
|
39
40
|
end # method format_expected_value
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
object = subject
|
47
|
-
end # if-else
|
48
|
-
|
49
|
-
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
50
|
-
expect(object).to have_constant(constant_name)
|
51
|
-
else
|
52
|
-
expected_value = format_expected_value(expected_value)
|
53
|
-
|
54
|
-
expect(object).to have_constant(constant_name).with_value(expected_value)
|
55
|
-
end # if-else
|
56
|
-
end # it
|
57
|
-
end # shared_examples
|
58
|
-
|
59
|
-
shared_examples 'should have immutable constant' do |constant_name, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
60
|
-
it "should have immutable constant :#{constant_name}" do
|
61
|
-
if defined?(described_class) && described_class.is_a?(Module)
|
62
|
-
object = described_class
|
63
|
-
else
|
64
|
-
object = subject
|
65
|
-
end # if-else
|
66
|
-
|
67
|
-
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
68
|
-
expect(object).to have_immutable_constant(constant_name)
|
69
|
-
else
|
70
|
-
expected_value = format_expected_value(expected_value)
|
71
|
-
|
72
|
-
expect(object).to have_immutable_constant(constant_name).with_value(expected_value)
|
73
|
-
end # if-else
|
74
|
-
end # it
|
75
|
-
end # shared_examples
|
76
|
-
|
77
|
-
shared_examples 'should have predicate' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
78
|
-
it "should have predicate :#{property}?" do
|
79
|
-
object = defined?(instance) ? instance : subject
|
80
|
-
|
81
|
-
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
82
|
-
expect(object).to have_predicate(property)
|
83
|
-
else
|
84
|
-
expected_value = format_expected_value(expected_value)
|
85
|
-
|
86
|
-
expect(object).to have_predicate(property).with_value(expected_value)
|
87
|
-
end # if-else
|
88
|
-
end # it
|
89
|
-
end # shared_examples
|
90
|
-
alias_shared_examples 'has predicate', 'should have predicate'
|
91
|
-
|
92
|
-
shared_examples 'should have reader' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
93
|
-
it "should have reader :#{property}" do
|
94
|
-
object = defined?(instance) ? instance : subject
|
95
|
-
|
96
|
-
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
97
|
-
expect(object).to have_reader(property)
|
98
|
-
else
|
99
|
-
expected_value = format_expected_value(expected_value)
|
100
|
-
|
101
|
-
expect(object).to have_reader(property).with_value(expected_value)
|
102
|
-
end # if-else
|
103
|
-
end # it
|
104
|
-
end # shared_examples
|
105
|
-
alias_shared_examples 'has reader', 'should have reader'
|
106
|
-
|
107
|
-
shared_examples 'should not have reader' do |property|
|
108
|
-
it "should not have reader :#{property}" do
|
109
|
-
object = defined?(instance) ? instance : subject
|
110
|
-
|
111
|
-
expect(object).not_to have_reader(property)
|
112
|
-
end # it
|
113
|
-
end # shared_examples
|
114
|
-
alias_shared_examples 'does not have reader', 'should not have reader'
|
115
|
-
|
116
|
-
shared_examples 'should have writer' do |property|
|
117
|
-
property_name = property.to_s.sub /\=\z/, ''
|
118
|
-
|
119
|
-
it "should have writer :#{property_name}=" do
|
120
|
-
object = defined?(instance) ? instance : subject
|
121
|
-
|
122
|
-
expect(object).to have_writer(property)
|
123
|
-
end # it
|
124
|
-
end # shared_examples
|
125
|
-
alias_shared_examples 'has writer', 'should have writer'
|
126
|
-
|
127
|
-
shared_examples 'should not have writer' do |property|
|
128
|
-
property_name = property.to_s.sub /\=\z/, ''
|
129
|
-
|
130
|
-
it "should not have writer :#{property}=" do
|
131
|
-
object = defined?(instance) ? instance : subject
|
132
|
-
|
133
|
-
expect(object).not_to have_writer(property)
|
134
|
-
end # it
|
135
|
-
end # shared_examples
|
136
|
-
alias_shared_examples 'does not have writer', 'should not have writer'
|
137
|
-
|
138
|
-
shared_examples 'should have property' do |property, expected_value = UNDEFINED_VALUE_EXPECTATION|
|
139
|
-
it "should have property :#{property}" do
|
140
|
-
object = defined?(instance) ? instance : subject
|
141
|
-
|
142
|
-
if expected_value == UNDEFINED_VALUE_EXPECTATION
|
143
|
-
expect(object).to have_property(property)
|
144
|
-
else
|
145
|
-
expected_value = format_expected_value(expected_value)
|
146
|
-
|
147
|
-
expect(object).to have_property(property).with_value(expected_value)
|
148
|
-
end # if-else
|
149
|
-
end # it
|
150
|
-
end # shared_examples
|
151
|
-
alias_shared_examples 'has property', 'should have property'
|
42
|
+
include RSpec::SleepingKingStudios::Examples::PropertyExamples::ClassProperties
|
43
|
+
include RSpec::SleepingKingStudios::Examples::PropertyExamples::Constants
|
44
|
+
include RSpec::SleepingKingStudios::Examples::PropertyExamples::PrivateProperties
|
45
|
+
include RSpec::SleepingKingStudios::Examples::PropertyExamples::Predicates
|
46
|
+
include RSpec::SleepingKingStudios::Examples::PropertyExamples::Properties
|
152
47
|
end # module
|
@@ -5,7 +5,10 @@ require 'rspec/sleeping_king_studios/matchers/macros'
|
|
5
5
|
|
6
6
|
module RSpec::SleepingKingStudios::Matchers::Macros
|
7
7
|
# @see RSpec::SleepingKingStudios::Matchers::Core::HavePropertyMatcher#matches?
|
8
|
-
def have_property expected
|
9
|
-
RSpec::SleepingKingStudios::Matchers::Core::HavePropertyMatcher.new
|
8
|
+
def have_property expected, allow_private: false
|
9
|
+
RSpec::SleepingKingStudios::Matchers::Core::HavePropertyMatcher.new(
|
10
|
+
expected,
|
11
|
+
:allow_private => allow_private
|
12
|
+
) # end matcher
|
10
13
|
end # method have_property
|
11
14
|
end # module
|
@@ -13,21 +13,30 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
13
13
|
class HavePropertyMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
|
14
14
|
include RSpec::SleepingKingStudios::Matchers::Shared::MatchProperty
|
15
15
|
|
16
|
+
# @param [String, Symbol] expected The property to check for on the actual
|
17
|
+
# object.
|
18
|
+
# @param [Boolean] allow_private If true, then the matcher will match a
|
19
|
+
# protected or private reader method. Defaults to false.
|
20
|
+
def initialize expected, allow_private: false
|
21
|
+
@expected = expected.intern
|
22
|
+
@allow_private = allow_private
|
23
|
+
end # method initialize
|
24
|
+
|
25
|
+
# @return [Boolean] True if the matcher matches private reader methods,
|
26
|
+
# otherwise false.
|
27
|
+
def allow_private?
|
28
|
+
!!@allow_private
|
29
|
+
end # method allow_private?
|
30
|
+
|
16
31
|
# (see BaseMatcher#description)
|
17
32
|
def description
|
18
33
|
value_message = value_to_string
|
19
34
|
"have property :#{@expected}#{@value_set ? " with value #{value_message}" : ''}"
|
20
35
|
end # method description
|
21
36
|
|
22
|
-
# @param [String, Symbol] expected The property to check for on the actual
|
23
|
-
# object.
|
24
|
-
def initialize expected
|
25
|
-
@expected = expected.intern
|
26
|
-
end # method initialize
|
27
|
-
|
28
37
|
# (see BaseMatcher#does_not_match?)
|
29
38
|
def does_not_match? actual
|
30
|
-
|
39
|
+
@actual = actual
|
31
40
|
|
32
41
|
matches_property?(:none?)
|
33
42
|
end # method does_not_match?
|
@@ -99,9 +108,9 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
99
108
|
private
|
100
109
|
|
101
110
|
def matches_property? filter
|
102
|
-
[ responds_to_reader
|
103
|
-
responds_to_writer
|
104
|
-
matches_reader_value?
|
111
|
+
[ responds_to_reader?(:allow_private => allow_private?),
|
112
|
+
responds_to_writer?(:allow_private => allow_private?),
|
113
|
+
matches_reader_value?(:allow_private => allow_private?)
|
105
114
|
].send(filter) { |bool| bool }
|
106
115
|
end # method matches_property?
|
107
116
|
end # class
|
@@ -5,7 +5,10 @@ require 'rspec/sleeping_king_studios/matchers/macros'
|
|
5
5
|
|
6
6
|
module RSpec::SleepingKingStudios::Matchers::Macros
|
7
7
|
# @see RSpec::SleepingKingStudios::Matchers::Core::HaveReaderMatcher#matches?
|
8
|
-
def have_reader expected
|
9
|
-
RSpec::SleepingKingStudios::Matchers::Core::HaveReaderMatcher.new
|
8
|
+
def have_reader expected, allow_private: false
|
9
|
+
RSpec::SleepingKingStudios::Matchers::Core::HaveReaderMatcher.new(
|
10
|
+
expected,
|
11
|
+
:allow_private => allow_private
|
12
|
+
) # end matcher
|
10
13
|
end # method have_reader
|
11
14
|
end # module
|
@@ -12,18 +12,27 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
12
12
|
class HaveReaderMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
|
13
13
|
include RSpec::SleepingKingStudios::Matchers::Shared::MatchProperty
|
14
14
|
|
15
|
+
# @param [String, Symbol] expected The property to check for on the actual
|
16
|
+
# object.
|
17
|
+
# @param [Boolean] allow_private If true, then the matcher will match a
|
18
|
+
# protected or private reader method. Defaults to false.
|
19
|
+
def initialize expected, allow_private: false
|
20
|
+
@expected = expected.intern
|
21
|
+
@allow_private = allow_private
|
22
|
+
end # method initialize
|
23
|
+
|
24
|
+
# @return [Boolean] True if the matcher matches private reader methods,
|
25
|
+
# otherwise false.
|
26
|
+
def allow_private?
|
27
|
+
!!@allow_private
|
28
|
+
end # method allow_private?
|
29
|
+
|
15
30
|
# (see BaseMatcher#description)
|
16
31
|
def description
|
17
32
|
value_message = value_to_string
|
18
33
|
"have reader :#{@expected}#{@value_set ? " with value #{value_message}" : ''}"
|
19
34
|
end # method description
|
20
35
|
|
21
|
-
# @param [String, Symbol] expected The property to check for on the actual
|
22
|
-
# object.
|
23
|
-
def initialize expected
|
24
|
-
@expected = expected.intern
|
25
|
-
end # method initialize
|
26
|
-
|
27
36
|
# (see BaseMatcher#does_not_match?)
|
28
37
|
def does_not_match? actual
|
29
38
|
super
|
@@ -88,8 +97,8 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
88
97
|
private
|
89
98
|
|
90
99
|
def matches_reader? filter
|
91
|
-
[ responds_to_reader
|
92
|
-
matches_reader_value?
|
100
|
+
[ responds_to_reader?(:allow_private => allow_private?),
|
101
|
+
matches_reader_value?(:allow_private => allow_private?)
|
93
102
|
].send(filter) { |bool| bool }
|
94
103
|
end # method matches_property?
|
95
104
|
end # class
|
@@ -5,7 +5,10 @@ require 'rspec/sleeping_king_studios/matchers/macros'
|
|
5
5
|
|
6
6
|
module RSpec::SleepingKingStudios::Matchers::Macros
|
7
7
|
# @see RSpec::SleepingKingStudios::Matchers::Core::HaveWriterMatcher#matches?
|
8
|
-
def have_writer expected
|
9
|
-
RSpec::SleepingKingStudios::Matchers::Core::HaveWriterMatcher.new
|
8
|
+
def have_writer expected, allow_private: false
|
9
|
+
RSpec::SleepingKingStudios::Matchers::Core::HaveWriterMatcher.new(
|
10
|
+
expected,
|
11
|
+
:allow_private => allow_private
|
12
|
+
) # end matcher
|
10
13
|
end # method have_writer
|
11
14
|
end # module
|
@@ -12,6 +12,19 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
12
12
|
class HaveWriterMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
|
13
13
|
include RSpec::SleepingKingStudios::Matchers::Shared::MatchProperty
|
14
14
|
|
15
|
+
# @param [String, Symbol] expected the property to check for on the actual
|
16
|
+
# object
|
17
|
+
def initialize expected, allow_private: false
|
18
|
+
@expected = expected.to_s.gsub(/=$/,'').intern
|
19
|
+
@allow_private = allow_private
|
20
|
+
end # method initialize
|
21
|
+
|
22
|
+
# @return [Boolean] True if the matcher matches private reader methods,
|
23
|
+
# otherwise false.
|
24
|
+
def allow_private?
|
25
|
+
!!@allow_private
|
26
|
+
end # method allow_private?
|
27
|
+
|
15
28
|
# Generates a description of the matcher expectation.
|
16
29
|
#
|
17
30
|
# @return [String] The matcher description.
|
@@ -19,12 +32,6 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
19
32
|
"have writer :#{@expected}"
|
20
33
|
end # method description
|
21
34
|
|
22
|
-
# @param [String, Symbol] expected the property to check for on the actual
|
23
|
-
# object
|
24
|
-
def initialize expected
|
25
|
-
@expected = expected.to_s.gsub(/=$/,'').intern
|
26
|
-
end # method initialize
|
27
|
-
|
28
35
|
# Checks if the object responds to :expected=. Additionally, if a value
|
29
36
|
# expectation is set, assigns the value via :expected= and compares the
|
30
37
|
# subsequent value to the specified value using :expected or the block
|
@@ -37,7 +44,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
37
44
|
def matches? actual
|
38
45
|
super
|
39
46
|
|
40
|
-
responds_to_writer?
|
47
|
+
responds_to_writer?(:allow_private => allow_private?)
|
41
48
|
end # method matches?
|
42
49
|
|
43
50
|
# @see BaseMatcher#failure_message
|
@@ -28,8 +28,8 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
28
28
|
#
|
29
29
|
# @return [Boolean] true if the value matches the expected value; otherwise
|
30
30
|
# false.
|
31
|
-
def matches_reader_value?
|
32
|
-
return false unless responds_to_reader?
|
31
|
+
def matches_reader_value? allow_private: false
|
32
|
+
return false unless responds_to_reader?(:allow_private => allow_private)
|
33
33
|
return true unless @value_set
|
34
34
|
|
35
35
|
actual_value = @actual.send(@expected)
|
@@ -51,16 +51,16 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
51
51
|
#
|
52
52
|
# @return [Boolean] true if the object responds to the method; otherwise
|
53
53
|
# false.
|
54
|
-
def responds_to_reader?
|
55
|
-
@matches_reader = @actual.respond_to?(@expected)
|
54
|
+
def responds_to_reader? allow_private: false
|
55
|
+
@matches_reader = @actual.respond_to?(@expected, allow_private)
|
56
56
|
end # method responds_to_reader?
|
57
57
|
|
58
58
|
# Checks whether the object responds to the writer method :#{property}=.
|
59
59
|
#
|
60
60
|
# @return [Boolean] true if the object responds to the method; otherwise
|
61
61
|
# false.
|
62
|
-
def responds_to_writer?
|
63
|
-
@matches_writer = @actual.respond_to?(:"#{@expected}=")
|
62
|
+
def responds_to_writer? allow_private: false
|
63
|
+
@matches_writer = @actual.respond_to?(:"#{@expected}=", allow_private)
|
64
64
|
end # method responds_to_reader?
|
65
65
|
|
66
66
|
# Formats the expected value as a human-readable string. If the value looks
|
@@ -11,13 +11,13 @@ module RSpec
|
|
11
11
|
# Major version.
|
12
12
|
MAJOR = 2
|
13
13
|
# Minor version.
|
14
|
-
MINOR =
|
14
|
+
MINOR = 3
|
15
15
|
# Patch version.
|
16
|
-
PATCH =
|
16
|
+
PATCH = 0
|
17
17
|
# Prerelease version.
|
18
|
-
PRERELEASE =
|
18
|
+
PRERELEASE = :rc
|
19
19
|
# Build metadata.
|
20
|
-
BUILD =
|
20
|
+
BUILD = 0
|
21
21
|
|
22
22
|
# Generates the gem version string from the Version constants.
|
23
23
|
#
|