saharspec 0.0.5 → 0.0.6
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 +5 -5
- data/CHANGELOG.md +14 -1
- data/README.md +2 -2
- data/lib/saharspec.rb +2 -0
- data/lib/saharspec/its.rb +2 -0
- data/lib/saharspec/its/block.rb +3 -1
- data/lib/saharspec/its/call.rb +3 -2
- data/lib/saharspec/its/map.rb +3 -1
- data/lib/saharspec/matchers.rb +2 -0
- data/lib/saharspec/matchers/be_json.rb +15 -9
- data/lib/saharspec/matchers/dont.rb +15 -4
- data/lib/saharspec/matchers/eq_multiline.rb +2 -0
- data/lib/saharspec/matchers/ret.rb +17 -3
- data/lib/saharspec/matchers/send_message.rb +4 -1
- data/lib/saharspec/util.rb +2 -0
- data/lib/saharspec/version.rb +3 -1
- data/saharspec.gemspec +3 -3
- metadata +12 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9467b45b9c26592854a9ce9ef7b9e5a549229a357602a3bf03241d5398f9cfcb
|
4
|
+
data.tar.gz: 0b981cb23146042faa5e584400bd941012a9ab57f8d5f68a080add82d443e23c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fef4a6f67cf9db940fcd906f6c3b3edf924c26577d2d504202776b1bcbaad35027f9071bd2658afae22d081800ae8997fe70ae73ca3b165726a7d2b630484975
|
7
|
+
data.tar.gz: b55ed52e2842a7cf4b00ce01c8c2bf8c8fd91b53833dbf86498ead0febf55ed5cd86ab42b8c130e3a538ae5e0300df25c5beb114a778ae808cecf225d9198777
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
# Saharspec history
|
2
2
|
|
3
|
+
## 0.0.6 -- 2019-10-05
|
4
|
+
|
5
|
+
* Fix `dont.send_message` combination behavior (and generally, behavior of `dont.` with matchers
|
6
|
+
defining custom `does_not_matches?`);
|
7
|
+
* Better `ret` matcher failure message when there is a complicated matcher on the right side (use
|
8
|
+
its `failure_message` instead of `description`);
|
9
|
+
* Update `send_message` matcher description to be more readable;
|
10
|
+
* Drop Ruby 2.2 support.
|
11
|
+
|
12
|
+
## 0.0.5 -- 2018-03-03
|
13
|
+
|
14
|
+
* `be_json` matcher;
|
15
|
+
* make `ret` diffable.
|
16
|
+
|
3
17
|
## 0.0.4 -- 2017-11-07
|
4
18
|
|
5
19
|
* Update `its_call` description generation, looks better with `rspec --format doc`
|
6
20
|
|
7
|
-
|
8
21
|
## 0.0.3 -- 2017-11-06
|
9
22
|
|
10
23
|
* Introduce new `its`-family addition: `its_call(*args)`
|
data/README.md
CHANGED
@@ -43,9 +43,9 @@ require 'saharspec/matchers/send_message'
|
|
43
43
|
it {
|
44
44
|
expect { fetcher }.to send_message(Net::HTTP, :get).with('http://google.com').returning('not this time')
|
45
45
|
}
|
46
|
-
# after +
|
46
|
+
# after + its_block
|
47
47
|
subject { fetcher }
|
48
|
-
|
48
|
+
its_block { is_expected.to send_message(Net::HTTP, :get).with('http://google.com').returning('not this time') }
|
49
49
|
```
|
50
50
|
|
51
51
|
Note: there is [reasons](https://github.com/rspec/rspec-expectations/issues/934) why it is not in rspec-mocks, though, not very persuative for
|
data/lib/saharspec.rb
CHANGED
data/lib/saharspec/its.rb
CHANGED
data/lib/saharspec/its/block.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Its
|
3
5
|
module Block
|
@@ -53,4 +55,4 @@ RSpec.configure do |rspec|
|
|
53
55
|
rspec.backtrace_exclusion_patterns << %r{/lib/saharspec/its/block}
|
54
56
|
end
|
55
57
|
|
56
|
-
RSpec::SharedContext.
|
58
|
+
RSpec::SharedContext.include Saharspec::Its::Block
|
data/lib/saharspec/its/call.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Its
|
3
5
|
module Call
|
@@ -27,7 +29,6 @@ module Saharspec
|
|
27
29
|
# rubocop:disable Lint/NestedMethodDefinition
|
28
30
|
describe("(#{args.map(&:inspect).join(', ')})") do
|
29
31
|
let(:__call_subject) do
|
30
|
-
warn 'No need to use its_call without arguments, just it {} will work' if args.empty?
|
31
32
|
-> { subject.call(*args) }
|
32
33
|
end
|
33
34
|
|
@@ -48,4 +49,4 @@ RSpec.configure do |rspec|
|
|
48
49
|
rspec.backtrace_exclusion_patterns << %r{/lib/saharspec/its/call}
|
49
50
|
end
|
50
51
|
|
51
|
-
RSpec::SharedContext.
|
52
|
+
RSpec::SharedContext.include Saharspec::Its::Call
|
data/lib/saharspec/its/map.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Its
|
3
5
|
module Map
|
@@ -72,4 +74,4 @@ RSpec.configure do |rspec|
|
|
72
74
|
rspec.backtrace_exclusion_patterns << %r{/lib/saharspec/its/map}
|
73
75
|
end
|
74
76
|
|
75
|
-
RSpec::SharedContext.
|
77
|
+
RSpec::SharedContext.include Saharspec::Its::Map
|
data/lib/saharspec/matchers.rb
CHANGED
@@ -1,27 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
|
3
5
|
module Saharspec
|
4
6
|
module Matchers
|
5
7
|
# @private
|
6
8
|
class BeJson
|
7
|
-
NONE = Object.new.freeze
|
8
9
|
include RSpec::Matchers::Composable
|
9
10
|
include RSpec::Matchers # to have #match
|
10
11
|
|
12
|
+
ANY = Object.new.freeze
|
13
|
+
|
11
14
|
attr_reader :actual, :expected
|
12
15
|
|
13
16
|
def initialize(expected, **parse_opts)
|
14
17
|
@expected_matcher = @expected = expected
|
18
|
+
|
15
19
|
# wrap to make be_json('foo' => matcher) work, too
|
16
|
-
|
20
|
+
unless expected == ANY || expected.respond_to?(:matches?)
|
21
|
+
@expected_matcher = match(expected)
|
22
|
+
end
|
17
23
|
@parse_opts = parse_opts
|
18
24
|
end
|
19
25
|
|
20
26
|
def matches?(json)
|
21
27
|
@actual = JSON.parse(json, **@parse_opts)
|
22
|
-
@expected_matcher ==
|
23
|
-
rescue JSON::ParserError =>
|
24
|
-
@parser_error =
|
28
|
+
@expected_matcher == ANY || @expected_matcher === @actual
|
29
|
+
rescue JSON::ParserError => e
|
30
|
+
@parser_error = e
|
25
31
|
false
|
26
32
|
end
|
27
33
|
|
@@ -34,7 +40,7 @@ module Saharspec
|
|
34
40
|
end
|
35
41
|
|
36
42
|
def description
|
37
|
-
if @expected ==
|
43
|
+
if @expected == ANY
|
38
44
|
'be a valid JSON string'
|
39
45
|
else
|
40
46
|
expected = @expected.respond_to?(:description) ? @expected.description : @expected
|
@@ -47,7 +53,7 @@ module Saharspec
|
|
47
53
|
case
|
48
54
|
when @parser_error
|
49
55
|
"failed: #{@parser_error}"
|
50
|
-
when @expected !=
|
56
|
+
when @expected != ANY
|
51
57
|
"was #{@actual}"
|
52
58
|
end
|
53
59
|
"expected value to #{description} but #{failed}"
|
@@ -81,7 +87,7 @@ module RSpec
|
|
81
87
|
#
|
82
88
|
# @param expected Value or matcher to check JSON against. It should implement `#===` method,
|
83
89
|
# so all standard and custom RSpec matchers work.
|
84
|
-
def be_json(expected = Saharspec::Matchers::BeJson::
|
90
|
+
def be_json(expected = Saharspec::Matchers::BeJson::ANY)
|
85
91
|
Saharspec::Matchers::BeJson.new(expected)
|
86
92
|
end
|
87
93
|
|
@@ -92,7 +98,7 @@ module RSpec
|
|
92
98
|
#
|
93
99
|
# @param expected Value or matcher to check JSON against. It should implement `#===` method,
|
94
100
|
# so all standard and custom RSpec matchers work.
|
95
|
-
def be_json_sym(expected = Saharspec::Matchers::BeJson::
|
101
|
+
def be_json_sym(expected = Saharspec::Matchers::BeJson::ANY)
|
96
102
|
Saharspec::Matchers::BeJson.new(expected, symbolize_names: true)
|
97
103
|
end
|
98
104
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Matchers
|
3
5
|
# @private
|
@@ -11,16 +13,25 @@ module Saharspec
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def match(_expected, actual)
|
14
|
-
@matcher or
|
15
|
-
|
16
|
-
|
16
|
+
@matcher or fail ArgumentError, '`dont` matcher used without any matcher to negate. '\
|
17
|
+
'Usage: dont.other_matcher(args)'
|
18
|
+
|
19
|
+
# https://www.rubydoc.info/github/rspec/rspec-expectations/RSpec%2FMatchers%2FMatcherProtocol:does_not_match%3F
|
20
|
+
# In a negative expectation such as `expect(x).not_to foo`, RSpec will call
|
21
|
+
# `foo.does_not_match?(x)` if this method is defined. If it's not defined it
|
22
|
+
# will fall back to using `!foo.matches?(x)`.
|
23
|
+
if @matcher.respond_to?(:does_not_match?)
|
24
|
+
@matcher.does_not_match?(actual)
|
25
|
+
else
|
26
|
+
!@matcher.matches?(actual)
|
27
|
+
end
|
17
28
|
end
|
18
29
|
|
19
30
|
def supports_block_expectations?
|
20
31
|
@matcher.supports_block_expectations?
|
21
32
|
end
|
22
33
|
|
23
|
-
def method_missing(m, *a, &b) # rubocop:disable Style/
|
34
|
+
def method_missing(m, *a, &b) # rubocop:disable Style/MethodMissingSuper
|
24
35
|
if @matcher
|
25
36
|
@matcher.send(m, *a, &b)
|
26
37
|
else
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Matchers
|
3
5
|
# @private
|
@@ -13,6 +15,7 @@ module Saharspec
|
|
13
15
|
def matches?(subject)
|
14
16
|
@subject = subject
|
15
17
|
return false unless subject.respond_to?(:call)
|
18
|
+
|
16
19
|
@actual = subject.call
|
17
20
|
@expected === @actual
|
18
21
|
end
|
@@ -30,12 +33,23 @@ module Saharspec
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def failure_message
|
33
|
-
|
34
|
-
|
36
|
+
case
|
37
|
+
when !@subject.respond_to?(:call)
|
38
|
+
"expected to #{description}, but was not callable"
|
39
|
+
when @expected.respond_to?(:failure_message)
|
40
|
+
"return value mismatch: #{@expected.failure_message}"
|
41
|
+
else
|
42
|
+
"expected to #{description}, but returned #{@actual.inspect}"
|
43
|
+
end
|
35
44
|
end
|
36
45
|
|
37
46
|
def failure_message_when_negated
|
38
|
-
|
47
|
+
case
|
48
|
+
when @expected.respond_to?(:failure_message_when_negated)
|
49
|
+
"return value mismatch: #{@expected.failure_message_when_negated}"
|
50
|
+
else
|
51
|
+
"expected not to #{description}, but returned it"
|
52
|
+
end
|
39
53
|
end
|
40
54
|
end
|
41
55
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Matchers
|
3
5
|
# @private
|
@@ -33,6 +35,7 @@ module Saharspec
|
|
33
35
|
|
34
36
|
def times
|
35
37
|
fail NoMethodError unless @times
|
38
|
+
|
36
39
|
self
|
37
40
|
end
|
38
41
|
|
@@ -68,7 +71,7 @@ module Saharspec
|
|
68
71
|
end
|
69
72
|
|
70
73
|
def description
|
71
|
-
format('
|
74
|
+
format('send %p.%s', @target, @method)
|
72
75
|
end
|
73
76
|
|
74
77
|
def failure_message
|
data/lib/saharspec/util.rb
CHANGED
data/lib/saharspec/version.rb
CHANGED
data/saharspec.gemspec
CHANGED
@@ -23,10 +23,10 @@ Gem::Specification.new do |s|
|
|
23
23
|
end
|
24
24
|
s.require_paths = ["lib"]
|
25
25
|
|
26
|
-
s.required_ruby_version = '>= 2.
|
26
|
+
s.required_ruby_version = '>= 2.3.0'
|
27
27
|
|
28
|
-
s.add_development_dependency 'rubocop', '
|
29
|
-
s.add_development_dependency 'rspec'
|
28
|
+
s.add_development_dependency 'rubocop', '~> 0.75'
|
29
|
+
s.add_development_dependency 'rspec', '~> 3.7.0'
|
30
30
|
s.add_development_dependency 'rspec-its'
|
31
31
|
s.add_development_dependency 'simplecov', '~> 0.9'
|
32
32
|
s.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saharspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Shepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.75'
|
20
20
|
type: :development
|
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: '0.
|
26
|
+
version: '0.75'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.7.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.7.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec-its
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,15 +146,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
146
|
requirements:
|
147
147
|
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: 2.
|
149
|
+
version: 2.3.0
|
150
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
152
|
- - ">="
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: '0'
|
155
155
|
requirements: []
|
156
|
-
|
157
|
-
rubygems_version: 2.6.14
|
156
|
+
rubygems_version: 3.0.3
|
158
157
|
signing_key:
|
159
158
|
specification_version: 4
|
160
159
|
summary: Several additions for DRYer RSpec code
|