rspec-sleeping_king_studios 2.0.0.beta.0 → 2.0.0.beta.1
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 +84 -13
- data/DEVELOPMENT.md +16 -0
- data/README.md +203 -100
- data/lib/rspec/sleeping_king_studios/all.rb +4 -0
- data/lib/rspec/sleeping_king_studios/configuration.rb +42 -0
- data/lib/rspec/sleeping_king_studios/examples/all.rb +5 -0
- data/lib/rspec/sleeping_king_studios/examples/property_examples.rb +58 -0
- data/lib/rspec/sleeping_king_studios/examples/rspec_matcher_examples.rb +105 -0
- data/lib/rspec/sleeping_king_studios/examples/shared_example_group.rb +62 -0
- data/lib/rspec/sleeping_king_studios/examples.rb +8 -0
- data/lib/rspec/sleeping_king_studios/matchers/active_model/all.rb +5 -0
- data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/error_expectation.rb +0 -1
- data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/message_expectation.rb +1 -2
- data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors.rb +75 -24
- data/lib/rspec/sleeping_king_studios/matchers/active_model.rb +6 -3
- data/lib/rspec/sleeping_king_studios/matchers/all.rb +5 -0
- data/lib/rspec/sleeping_king_studios/matchers/base_matcher.rb +20 -1
- data/lib/rspec/sleeping_king_studios/matchers/built_in/all.rb +5 -0
- data/lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of.rb +16 -10
- data/lib/rspec/sleeping_king_studios/matchers/built_in/include.rb +14 -9
- data/lib/rspec/sleeping_king_studios/matchers/built_in/respond_to.rb +45 -31
- data/lib/rspec/sleeping_king_studios/matchers/built_in.rb +5 -3
- data/lib/rspec/sleeping_king_studios/matchers/core/all.rb +5 -0
- data/lib/rspec/sleeping_king_studios/matchers/core/be_boolean.rb +11 -4
- data/lib/rspec/sleeping_king_studios/matchers/core/construct.rb +56 -32
- data/lib/rspec/sleeping_king_studios/matchers/core/have_property.rb +59 -29
- data/lib/rspec/sleeping_king_studios/matchers/core/have_reader.rb +31 -22
- data/lib/rspec/sleeping_king_studios/matchers/core/have_writer.rb +21 -55
- data/lib/rspec/sleeping_king_studios/matchers/core.rb +5 -3
- data/lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb +1 -3
- data/lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb +52 -0
- data/lib/rspec/sleeping_king_studios/matchers.rb +10 -3
- data/lib/rspec/sleeping_king_studios/version.rb +22 -1
- data/lib/rspec/sleeping_king_studios.rb +7 -1
- metadata +38 -16
- data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/require.rb +0 -7
- data/lib/rspec/sleeping_king_studios/matchers/active_model/require.rb +0 -8
- data/lib/rspec/sleeping_king_studios/matchers/built_in/require.rb +0 -7
- data/lib/rspec/sleeping_king_studios/matchers/core/require.rb +0 -7
- data/lib/rspec/sleeping_king_studios/matchers/meta/fail_with_actual.rb +0 -107
- data/lib/rspec/sleeping_king_studios/matchers/meta/pass_with_actual.rb +0 -95
- data/lib/rspec/sleeping_king_studios/matchers/meta/require.rb +0 -7
- data/lib/rspec/sleeping_king_studios/matchers/meta.rb +0 -5
- data/lib/rspec/sleeping_king_studios/matchers/require.rb +0 -12
- data/lib/rspec/sleeping_king_studios/matchers/shared/require.rb +0 -7
- data/lib/rspec/sleeping_king_studios/require.rb +0 -7
@@ -1,14 +1,24 @@
|
|
1
1
|
# lib/rspec/sleeping_king_studios/matchers/core/have_mutator.rb
|
2
2
|
|
3
3
|
require 'rspec/sleeping_king_studios/matchers/base_matcher'
|
4
|
-
require 'rspec/sleeping_king_studios/matchers/core
|
4
|
+
require 'rspec/sleeping_king_studios/matchers/core'
|
5
|
+
require 'rspec/sleeping_king_studios/matchers/shared/match_property'
|
5
6
|
|
6
7
|
module RSpec::SleepingKingStudios::Matchers::Core
|
7
8
|
# Matcher for testing whether an object has a specific property writer, e.g.
|
8
9
|
# responds to :property= and updates the state.
|
9
|
-
#
|
10
|
+
#
|
10
11
|
# @since 1.0.0
|
11
12
|
class HaveWriterMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
|
13
|
+
include RSpec::SleepingKingStudios::Matchers::Shared::MatchProperty
|
14
|
+
|
15
|
+
# Generates a description of the matcher expectation.
|
16
|
+
#
|
17
|
+
# @return [String] The matcher description.
|
18
|
+
def description
|
19
|
+
"have writer :#{@expected}"
|
20
|
+
end # method description
|
21
|
+
|
12
22
|
# @param [String, Symbol] expected the property to check for on the actual
|
13
23
|
# object
|
14
24
|
def initialize expected
|
@@ -19,75 +29,31 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
19
29
|
# expectation is set, assigns the value via :expected= and compares the
|
20
30
|
# subsequent value to the specified value using :expected or the block
|
21
31
|
# provided to #with.
|
22
|
-
#
|
32
|
+
#
|
23
33
|
# @param [Object] actual the object to check
|
24
|
-
#
|
34
|
+
#
|
25
35
|
# @return [Boolean] true if the object responds to :expected= and matches
|
26
36
|
# the value expectation (if any); otherwise false
|
27
37
|
def matches? actual
|
28
38
|
super
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
if @value_set
|
33
|
-
@actual.send :"#{@expected}=", @value
|
34
|
-
|
35
|
-
if @value_block.respond_to?(:call)
|
36
|
-
return false unless @value == (@actual_value = @actual.instance_eval(&@value_block))
|
37
|
-
elsif @actual.respond_to?(@expected)
|
38
|
-
return false unless @value == (@actual_value = @actual.send(@expected))
|
39
|
-
else
|
40
|
-
return false
|
41
|
-
end # if-elsif
|
42
|
-
end # if
|
43
|
-
|
44
|
-
true
|
40
|
+
responds_to_writer?
|
45
41
|
end # method matches?
|
46
42
|
|
47
|
-
# Sets a value expectation. The matcher will set the object's value to the
|
48
|
-
# specified value using :property=, then compare the value from :property
|
49
|
-
# with the specified value. If a block is provided, the actual object
|
50
|
-
# evaluates the block and the value is compared to the specified value
|
51
|
-
# instead of using :property.
|
52
|
-
#
|
53
|
-
# @param [Object] value the value to compare
|
54
|
-
#
|
55
|
-
# @yield if a block is provided, the block is used to check the value after
|
56
|
-
# setting :property= instead of using :property.
|
57
|
-
#
|
58
|
-
# @example Using :property to check the value
|
59
|
-
# expect(instance).to have_writer(:foo).with(42)
|
60
|
-
#
|
61
|
-
# @example Using a block to check the valuye
|
62
|
-
# expect(instance).to have_writer(:bar).with(42) { self.getBar() }
|
63
|
-
#
|
64
|
-
# @return [HaveWriterMatcher] self
|
65
|
-
def with value, &block
|
66
|
-
@value = value
|
67
|
-
@value_set = true
|
68
|
-
@value_block = block
|
69
|
-
self
|
70
|
-
end # method with
|
71
|
-
|
72
43
|
# @see BaseMatcher#failure_message
|
73
44
|
def failure_message
|
74
|
-
|
45
|
+
message = "expected #{@actual.inspect} to respond to :#{@expected}="
|
75
46
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end # unless
|
47
|
+
if !@matches_writer
|
48
|
+
message << ", but did not respond to :#{@expected}="
|
49
|
+
end # if
|
80
50
|
|
81
|
-
|
82
|
-
" expected: #{@value.inspect}\n" +
|
83
|
-
" got: #{@actual_value.inspect}"
|
51
|
+
message
|
84
52
|
end # method failure_message
|
85
53
|
|
86
54
|
# @see BaseMatcher#failure_message_when_negated
|
87
55
|
def failure_message_when_negated
|
88
|
-
|
89
|
-
message << " with value #{@value.inspect}" if @value_set && @match_writer
|
90
|
-
message
|
56
|
+
"expected #{@actual} not to respond to :#{@expected}="
|
91
57
|
end # method failure_message
|
92
58
|
end # class
|
93
59
|
end # module
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# lib/rspec/sleeping_king_studios/matchers/core.rb
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require 'rspec/sleeping_king_studios/matchers'
|
4
|
+
|
5
|
+
module RSpec::SleepingKingStudios::Matchers
|
6
|
+
module Core; end
|
7
|
+
end # module
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# lib/rspec/sleeping_king_studios/matchers/shared/parameters_matcher.rb
|
2
2
|
|
3
|
-
require 'rspec/sleeping_king_studios/matchers
|
3
|
+
require 'rspec/sleeping_king_studios/matchers'
|
4
4
|
|
5
5
|
module RSpec::SleepingKingStudios::Matchers::Shared
|
6
6
|
# Helper methods for checking the parameters and keywords (Ruby 2.0 only) of
|
@@ -41,8 +41,6 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
41
41
|
# @return [Boolean] true if the method accepts the specified keywords;
|
42
42
|
# otherwise false
|
43
43
|
def check_method_keywords method, keywords
|
44
|
-
return nil unless RUBY_VERSION >= "2.0.0"
|
45
|
-
|
46
44
|
keywords ||= []
|
47
45
|
parameters = method.parameters
|
48
46
|
reasons = {}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb
|
2
|
+
|
3
|
+
module RSpec::SleepingKingStudios::Matchers::Shared
|
4
|
+
# Helper methods for checking reader and writer methods and values.
|
5
|
+
module MatchProperty
|
6
|
+
private
|
7
|
+
|
8
|
+
# Checks whether the value of the reader matches the expected value. If the
|
9
|
+
# value looks like an RSpec matcher (it responds to :matches?), runs
|
10
|
+
# value.matches?(); otherwise checks for equality using :==.
|
11
|
+
#
|
12
|
+
# @return [Boolean] true if the value matches the expected value; otherwise
|
13
|
+
# false.
|
14
|
+
def matches_reader_value?
|
15
|
+
return false unless responds_to_reader?
|
16
|
+
return true unless @value_set
|
17
|
+
|
18
|
+
actual_value = @actual.send(@expected)
|
19
|
+
|
20
|
+
@matches_reader_value = @value.respond_to?(:matches?) ?
|
21
|
+
@value.matches?(actual_value) :
|
22
|
+
@value == actual_value
|
23
|
+
end # method matches_reader_value?
|
24
|
+
|
25
|
+
# Checks whether the object responds to the reader method :#{property}.
|
26
|
+
#
|
27
|
+
# @return [Boolean] true if the object responds to the method; otherwise
|
28
|
+
# false.
|
29
|
+
def responds_to_reader?
|
30
|
+
@matches_reader = @actual.respond_to?(@expected)
|
31
|
+
end # method responds_to_reader?
|
32
|
+
|
33
|
+
# Checks whether the object responds to the writer method :#{property}=.
|
34
|
+
#
|
35
|
+
# @return [Boolean] true if the object responds to the method; otherwise
|
36
|
+
# false.
|
37
|
+
def responds_to_writer?
|
38
|
+
@matches_writer = @actual.respond_to?(:"#{@expected}=")
|
39
|
+
end # method responds_to_reader?
|
40
|
+
|
41
|
+
# Formats the expected value as a human-readable string. If the value looks
|
42
|
+
# like an RSpec matcher (it responds to :matches?), calls
|
43
|
+
# value#description; otherwise calls value#inspect.
|
44
|
+
#
|
45
|
+
# @return [String] the value as a human-readable string.
|
46
|
+
def value_to_string
|
47
|
+
return @value.description if @value.respond_to?(:matches?)
|
48
|
+
|
49
|
+
@value.inspect
|
50
|
+
end # method value_to_string
|
51
|
+
end # module
|
52
|
+
end # module
|
@@ -1,5 +1,12 @@
|
|
1
1
|
# lib/rspec/sleeping_king_studios/matchers.rb
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require 'rspec/sleeping_king_studios'
|
4
|
+
|
5
|
+
module RSpec::SleepingKingStudios
|
6
|
+
# Custom matchers for use with RSpec::Expectations.
|
7
|
+
module Matchers; end
|
8
|
+
end # module
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.include RSpec::SleepingKingStudios::Matchers
|
12
|
+
end # configuration
|
@@ -2,6 +2,27 @@
|
|
2
2
|
|
3
3
|
module RSpec
|
4
4
|
module SleepingKingStudios
|
5
|
-
|
5
|
+
# @api private
|
6
|
+
module Version
|
7
|
+
MAJOR = 2
|
8
|
+
MINOR = 0
|
9
|
+
PATCH = 0
|
10
|
+
PRERELEASE = 'beta'
|
11
|
+
BUILD = 1
|
12
|
+
|
13
|
+
def self.to_gem_version
|
14
|
+
str = "#{MAJOR}.#{MINOR}.#{PATCH}"
|
15
|
+
|
16
|
+
prerelease = self.const_defined?(:PRERELEASE) ? PRERELEASE : nil
|
17
|
+
str << ".#{prerelease}" unless prerelease.nil? || (prerelease.respond_to?(:empty?) && prerelease.empty?)
|
18
|
+
|
19
|
+
build = self.const_defined?(:BUILD) ? BUILD : nil
|
20
|
+
str << ".#{build}" unless build.nil? || (build.respond_to?(:empty?) && build.empty?)
|
21
|
+
|
22
|
+
str
|
23
|
+
end # class method to_version
|
24
|
+
end # module
|
25
|
+
|
26
|
+
VERSION = Version.to_gem_version
|
6
27
|
end # module
|
7
28
|
end # module
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-sleeping_king_studios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.beta.
|
4
|
+
version: 2.0.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob "Merlin" Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,14 +16,34 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.1'
|
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.
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sleeping_king_studios-tools
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.1.2
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.1'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.1.2
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: rake
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,37 +117,39 @@ extensions: []
|
|
97
117
|
extra_rdoc_files: []
|
98
118
|
files:
|
99
119
|
- CHANGELOG.md
|
120
|
+
- DEVELOPMENT.md
|
100
121
|
- LICENSE
|
101
122
|
- README.md
|
102
123
|
- lib/rspec/sleeping_king_studios.rb
|
124
|
+
- lib/rspec/sleeping_king_studios/all.rb
|
125
|
+
- lib/rspec/sleeping_king_studios/configuration.rb
|
126
|
+
- lib/rspec/sleeping_king_studios/examples.rb
|
127
|
+
- lib/rspec/sleeping_king_studios/examples/all.rb
|
128
|
+
- lib/rspec/sleeping_king_studios/examples/property_examples.rb
|
129
|
+
- lib/rspec/sleeping_king_studios/examples/rspec_matcher_examples.rb
|
130
|
+
- lib/rspec/sleeping_king_studios/examples/shared_example_group.rb
|
103
131
|
- lib/rspec/sleeping_king_studios/matchers.rb
|
104
132
|
- lib/rspec/sleeping_king_studios/matchers/active_model.rb
|
133
|
+
- lib/rspec/sleeping_king_studios/matchers/active_model/all.rb
|
105
134
|
- lib/rspec/sleeping_king_studios/matchers/active_model/have_errors.rb
|
106
135
|
- lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/error_expectation.rb
|
107
136
|
- lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/message_expectation.rb
|
108
|
-
- lib/rspec/sleeping_king_studios/matchers/
|
109
|
-
- lib/rspec/sleeping_king_studios/matchers/active_model/require.rb
|
137
|
+
- lib/rspec/sleeping_king_studios/matchers/all.rb
|
110
138
|
- lib/rspec/sleeping_king_studios/matchers/base_matcher.rb
|
111
139
|
- lib/rspec/sleeping_king_studios/matchers/built_in.rb
|
140
|
+
- lib/rspec/sleeping_king_studios/matchers/built_in/all.rb
|
112
141
|
- lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of.rb
|
113
142
|
- lib/rspec/sleeping_king_studios/matchers/built_in/include.rb
|
114
|
-
- lib/rspec/sleeping_king_studios/matchers/built_in/require.rb
|
115
143
|
- lib/rspec/sleeping_king_studios/matchers/built_in/respond_to.rb
|
116
144
|
- lib/rspec/sleeping_king_studios/matchers/core.rb
|
145
|
+
- lib/rspec/sleeping_king_studios/matchers/core/all.rb
|
117
146
|
- lib/rspec/sleeping_king_studios/matchers/core/be_boolean.rb
|
118
147
|
- lib/rspec/sleeping_king_studios/matchers/core/construct.rb
|
119
148
|
- lib/rspec/sleeping_king_studios/matchers/core/have_property.rb
|
120
149
|
- lib/rspec/sleeping_king_studios/matchers/core/have_reader.rb
|
121
150
|
- lib/rspec/sleeping_king_studios/matchers/core/have_writer.rb
|
122
|
-
- lib/rspec/sleeping_king_studios/matchers/core/require.rb
|
123
|
-
- lib/rspec/sleeping_king_studios/matchers/meta.rb
|
124
|
-
- lib/rspec/sleeping_king_studios/matchers/meta/fail_with_actual.rb
|
125
|
-
- lib/rspec/sleeping_king_studios/matchers/meta/pass_with_actual.rb
|
126
|
-
- lib/rspec/sleeping_king_studios/matchers/meta/require.rb
|
127
|
-
- lib/rspec/sleeping_king_studios/matchers/require.rb
|
128
151
|
- lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb
|
129
|
-
- lib/rspec/sleeping_king_studios/matchers/shared/
|
130
|
-
- lib/rspec/sleeping_king_studios/require.rb
|
152
|
+
- lib/rspec/sleeping_king_studios/matchers/shared/match_property.rb
|
131
153
|
- lib/rspec/sleeping_king_studios/version.rb
|
132
154
|
homepage: http://sleepingkingstudios.com
|
133
155
|
licenses:
|
@@ -149,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
171
|
version: 1.3.1
|
150
172
|
requirements: []
|
151
173
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.4.2
|
153
175
|
signing_key:
|
154
176
|
specification_version: 4
|
155
177
|
summary: A collection of RSpec patches and custom matchers.
|
@@ -1,8 +0,0 @@
|
|
1
|
-
# lib/rspec/sleeping_king_studios/matchers/active_model/require.rb
|
2
|
-
|
3
|
-
require 'rspec/sleeping_king_studios/matchers/require'
|
4
|
-
|
5
|
-
module RSpec::SleepingKingStudios::Matchers
|
6
|
-
# Matchers for ActiveModel object validation testing.
|
7
|
-
module ActiveModel; end
|
8
|
-
end # module
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# lib/rspec/sleeping_king_studios/matchers/rspec/fail_with_actual.rb
|
2
|
-
|
3
|
-
require 'rspec/sleeping_king_studios/matchers/base_matcher'
|
4
|
-
require 'rspec/sleeping_king_studios/matchers/meta/require'
|
5
|
-
|
6
|
-
module RSpec::SleepingKingStudios::Matchers::Meta
|
7
|
-
# Matcher for testing whether an RSpec matcher will fail with a given actual
|
8
|
-
# object, and return the specified failure message if the matcher is called
|
9
|
-
# via expect#to.
|
10
|
-
#
|
11
|
-
# @note Do not use this matcher with expect#not_to to verify that a matcher
|
12
|
-
# will pass with a given actual object; use the #pass_with_actual matcher
|
13
|
-
# instead.
|
14
|
-
#
|
15
|
-
# @see RSpec::SleepingKingStudios::Matchers::Meta::PassWithActualMatcher
|
16
|
-
#
|
17
|
-
# @since 1.0.0
|
18
|
-
class FailWithActualMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
|
19
|
-
# @param [Object] expected the actual object to check the matcher against
|
20
|
-
def initialize expected
|
21
|
-
@expected = expected
|
22
|
-
end # method initialize
|
23
|
-
|
24
|
-
# Checks if the matcher evaluates to false with the expected object. If a
|
25
|
-
# message expectation is set, checks the value of
|
26
|
-
# #failure_message against the expected message.
|
27
|
-
#
|
28
|
-
# @param [Object] actual the RSpec matcher to check; should respond to
|
29
|
-
# :matches? and :failure_message, as a minimum
|
30
|
-
#
|
31
|
-
# @return [Boolean] true if the matcher evaluates to false and the
|
32
|
-
# matcher's #failure_message matches the expected message
|
33
|
-
# (if any); otherwise false
|
34
|
-
def matches? actual
|
35
|
-
super
|
36
|
-
|
37
|
-
return false if matches_actual?
|
38
|
-
|
39
|
-
if @message.is_a? Regexp
|
40
|
-
!!(@actual.failure_message =~ @message)
|
41
|
-
elsif @message
|
42
|
-
@actual.failure_message == @message.to_s
|
43
|
-
else
|
44
|
-
true
|
45
|
-
end # if-elsif-else
|
46
|
-
end # method matches?
|
47
|
-
|
48
|
-
def failure_message
|
49
|
-
if @matches
|
50
|
-
"expected #{@actual} not to match #{@expected}"
|
51
|
-
else
|
52
|
-
message_text = @message.is_a?(Regexp) ? @message.inspect : @message.to_s
|
53
|
-
|
54
|
-
"expected message#{@message.is_a?(Regexp) ? " matching" : ""}:\n#{
|
55
|
-
message_text.lines.map { |line| "#{" " * 2}#{line}" }.join
|
56
|
-
}\nreceived message:\n#{
|
57
|
-
@actual.failure_message.lines.map { |line| "#{" " * 2}#{line}" }.join
|
58
|
-
}"
|
59
|
-
end # if-else
|
60
|
-
end # method failure_message
|
61
|
-
|
62
|
-
# @see BaseMatcher#failure_message_when_negated
|
63
|
-
def failure_message_when_negated
|
64
|
-
"failure: testing positive condition with negative matcher\n~> use the :pass_with_actual matcher instead"
|
65
|
-
end # method failure_message_when_negated
|
66
|
-
|
67
|
-
# The expected failure message for should when the matcher is called via
|
68
|
-
# expect#to.
|
69
|
-
#
|
70
|
-
# @return [String, nil] the expected message if one has been defined;
|
71
|
-
# otherwise nil
|
72
|
-
attr_reader :message
|
73
|
-
|
74
|
-
# Sets up a message expectation. When the matcher is called with the
|
75
|
-
# provided actual object, the matcher's failure_message
|
76
|
-
# message is compared to the provided message.
|
77
|
-
#
|
78
|
-
# @param [String, Regexp] message the message to compare
|
79
|
-
#
|
80
|
-
# @return [FailWithActualMatcher] self
|
81
|
-
def with_message message
|
82
|
-
@message = message
|
83
|
-
self
|
84
|
-
end # method with_message
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
# Handles the actual matching through #does_not_match? if the matcher
|
89
|
-
# supports that method, otherwise falls back to @matches?.
|
90
|
-
#
|
91
|
-
# @return [Boolean]
|
92
|
-
def matches_actual?
|
93
|
-
if @actual.respond_to?(:does_not_match?)
|
94
|
-
@matches = !@actual.does_not_match?(@expected)
|
95
|
-
else
|
96
|
-
@matches = @actual.matches?(@expected)
|
97
|
-
end # if-else
|
98
|
-
end # method matches_actual?
|
99
|
-
end # class
|
100
|
-
end # module
|
101
|
-
|
102
|
-
module RSpec::SleepingKingStudios::Matchers
|
103
|
-
# @see RSpec::SleepingKingStudios::Matchers::Meta::FailWithActualMatcher#matches?
|
104
|
-
def fail_with_actual expected
|
105
|
-
Meta::FailWithActualMatcher.new expected
|
106
|
-
end # method fail_with_actual
|
107
|
-
end # module
|
@@ -1,95 +0,0 @@
|
|
1
|
-
# lib/rspec/sleeping_king_studios/matchers/meta/pass_with_actual.rb
|
2
|
-
|
3
|
-
require 'rspec/sleeping_king_studios/matchers/base_matcher'
|
4
|
-
require 'rspec/sleeping_king_studios/matchers/meta/require'
|
5
|
-
|
6
|
-
module RSpec::SleepingKingStudios::Matchers::Meta
|
7
|
-
# Matcher for testing whether an RSpec matcher will pass with a given actual
|
8
|
-
# object, and return the specified failure message if the matcher is called
|
9
|
-
# via expect#not_to.
|
10
|
-
#
|
11
|
-
# @note Do not use this matcher with expect#not_to to verify that a matcher
|
12
|
-
# will fail with a given actual object; use the #fail_with_actual matcher
|
13
|
-
# instead.
|
14
|
-
#
|
15
|
-
# @see RSpec::SleepingKingStudios::Matchers::Meta::FailWithActualMatcher
|
16
|
-
#
|
17
|
-
# @since 1.0.0
|
18
|
-
class PassWithActualMatcher < RSpec::SleepingKingStudios::Matchers::BaseMatcher
|
19
|
-
# @param [Object] expected the actual object to check the matcher against
|
20
|
-
def initialize expected
|
21
|
-
@expected = expected
|
22
|
-
end # method initialize
|
23
|
-
|
24
|
-
# Checks if the matcher evaluates to true with the expected object. If a
|
25
|
-
# message expectation is set, checks the value of
|
26
|
-
# #failure_message_when_negated against the expected message.
|
27
|
-
#
|
28
|
-
# @param [Object] actual the RSpec matcher to check; should respond to
|
29
|
-
# :matches? and :failure_message_when_negated, as a minimum
|
30
|
-
#
|
31
|
-
# @return [Boolean] true if the matcher evaluates to true and the matcher's
|
32
|
-
# #failure_message_when_negated matches the expected message (if any);
|
33
|
-
# otherwise false
|
34
|
-
def matches? actual
|
35
|
-
super
|
36
|
-
return false unless @matches = @actual.matches?(@expected)
|
37
|
-
|
38
|
-
if @message.is_a? Regexp
|
39
|
-
!!(@actual.failure_message_when_negated =~ @message)
|
40
|
-
elsif @message
|
41
|
-
@actual.failure_message_when_negated == @message.to_s
|
42
|
-
else
|
43
|
-
true
|
44
|
-
end # if-elsif-else
|
45
|
-
end # method matches?
|
46
|
-
|
47
|
-
# @see BaseMatcher#failure_message_when_negated
|
48
|
-
def failure_message
|
49
|
-
if @matches
|
50
|
-
message_text = @message.is_a?(Regexp) ? @message.inspect : @message.to_s
|
51
|
-
|
52
|
-
"expected message#{@message.is_a?(Regexp) ? " matching" : ""}:\n#{
|
53
|
-
message_text.lines.map { |line| "#{" " * 2}#{line}" }.join
|
54
|
-
}\nreceived message:\n#{
|
55
|
-
@actual.failure_message_when_negated.lines.map { |line| "#{" " * 2}#{line}" }.join
|
56
|
-
}"
|
57
|
-
else
|
58
|
-
failure_message = @actual.failure_message
|
59
|
-
failure_message = failure_message.lines.map { |line| "#{" " * 4}#{line}" }.join("\n")
|
60
|
-
"expected #{@actual} to match #{@expected}\n message:\n#{failure_message}"
|
61
|
-
end # if-else
|
62
|
-
end # method failure_message
|
63
|
-
|
64
|
-
# @see BaseMatcher#failure_message_when_negated
|
65
|
-
def failure_message_when_negated
|
66
|
-
"failure: testing negative condition with positive matcher\n~> use the :fail_with_actual matcher instead"
|
67
|
-
end # method failure_message_when_negated
|
68
|
-
|
69
|
-
# The expected failure message for should_not when the matcher is called
|
70
|
-
# via expect#not_to.
|
71
|
-
#
|
72
|
-
# @return [String, nil] the expected message if one has been defined;
|
73
|
-
# otherwise nil
|
74
|
-
attr_reader :message
|
75
|
-
|
76
|
-
# Sets up a message expectation. When the matcher is called with the
|
77
|
-
# provided actual object, the matcher's failure_message_when_negated
|
78
|
-
# message is compared to the provided message.
|
79
|
-
#
|
80
|
-
# @param [String, Regexp] message the message to compare
|
81
|
-
#
|
82
|
-
# @return [PassWithActualMatcher] self
|
83
|
-
def with_message message
|
84
|
-
@message = message
|
85
|
-
self
|
86
|
-
end # method with_message
|
87
|
-
end # class
|
88
|
-
end # module
|
89
|
-
|
90
|
-
module RSpec::SleepingKingStudios::Matchers
|
91
|
-
# @see RSpec::SleepingKingStudios::Matchers::Meta::PassWithActualMatcher#matches?
|
92
|
-
def pass_with_actual expected
|
93
|
-
Meta::PassWithActualMatcher.new expected
|
94
|
-
end # method pass_with_actual
|
95
|
-
end # module
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# lib/rspec/sleeping_king_studios/matchers/require.rb
|
2
|
-
|
3
|
-
require 'rspec/sleeping_king_studios/require'
|
4
|
-
|
5
|
-
module RSpec::SleepingKingStudios
|
6
|
-
# Custom matchers for use with RSpec::Expectations.
|
7
|
-
module Matchers; end
|
8
|
-
end # module
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
config.include RSpec::SleepingKingStudios::Matchers
|
12
|
-
end # configuration
|