saharspec 0.0.3 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +26 -0
- data/LICENSE.txt +1 -1
- data/README.md +27 -5
- data/lib/saharspec.rb +2 -0
- data/lib/saharspec/its.rb +25 -3
- data/lib/saharspec/its/block.rb +3 -1
- data/lib/saharspec/its/call.rb +7 -4
- data/lib/saharspec/its/map.rb +8 -5
- data/lib/saharspec/matchers.rb +9 -4
- data/lib/saharspec/matchers/be_json.rb +105 -0
- data/lib/saharspec/matchers/dont.rb +22 -6
- data/lib/saharspec/matchers/eq_multiline.rb +2 -0
- data/lib/saharspec/matchers/ret.rb +26 -5
- data/lib/saharspec/matchers/send_message.rb +7 -4
- data/lib/saharspec/util.rb +2 -0
- data/lib/saharspec/version.rb +3 -4
- data/saharspec.gemspec +7 -3
- metadata +27 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 402e6f62d9abc17f1dad82a3a5f38ae8f844ca458ad87a4756192976e4cd5496
|
4
|
+
data.tar.gz: 1541630eb677716d9ab2e58e1a25427ea86b67c5e001a52a25e9641491006971
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7923af91fee36b0a8b8c79fdba8d0bf6503598ca62589d8d30a2e8dace0428f9338e892d5e3a0538c4fc857a209b390b6b88eebf8637c41dc68dd6c61d6772d5
|
7
|
+
data.tar.gz: 5b844ac0a0098001638d19a2113e0eca4bf7acb225a87a456133e3d1ff564fc96648b95a0e0c37478c07d2532fc005e9c4db35a15b00f6b92018565c70097175
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Saharspec history
|
2
2
|
|
3
|
+
## 0.0.8 -- 2020-10-10
|
4
|
+
|
5
|
+
* Better `dont` failure message (just use underlying matchers `failure_message_when_negated`)
|
6
|
+
|
7
|
+
## 0.0.7 -- 2020-04-11
|
8
|
+
|
9
|
+
* Allow `its_call` to work properly with keyword args on Ruby 2.7
|
10
|
+
|
11
|
+
## 0.0.6 -- 2019-10-05
|
12
|
+
|
13
|
+
* Fix `dont.send_message` combination behavior (and generally, behavior of `dont.` with matchers
|
14
|
+
defining custom `does_not_matches?`);
|
15
|
+
* Better `ret` matcher failure message when there is a complicated matcher on the right side (use
|
16
|
+
its `failure_message` instead of `description`);
|
17
|
+
* Update `send_message` matcher description to be more readable;
|
18
|
+
* Drop Ruby 2.2 support.
|
19
|
+
|
20
|
+
## 0.0.5 -- 2018-03-03
|
21
|
+
|
22
|
+
* `be_json` matcher;
|
23
|
+
* make `ret` diffable.
|
24
|
+
|
25
|
+
## 0.0.4 -- 2017-11-07
|
26
|
+
|
27
|
+
* Update `its_call` description generation, looks better with `rspec --format doc`
|
28
|
+
|
3
29
|
## 0.0.3 -- 2017-11-06
|
4
30
|
|
5
31
|
* Introduce new `its`-family addition: `its_call(*args)`
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,8 @@ specs dry as a desert.
|
|
9
9
|
|
10
10
|
## Usage
|
11
11
|
|
12
|
-
Install it as a usual gem `saharspec
|
12
|
+
Install it as a usual gem `saharspec` with `gem install` or `gem "saharspec"` in `:test` group of
|
13
|
+
your `Gemfile`.
|
13
14
|
|
14
15
|
Then, probably in your `spec_helper.rb`
|
15
16
|
|
@@ -42,9 +43,9 @@ require 'saharspec/matchers/send_message'
|
|
42
43
|
it {
|
43
44
|
expect { fetcher }.to send_message(Net::HTTP, :get).with('http://google.com').returning('not this time')
|
44
45
|
}
|
45
|
-
# after +
|
46
|
+
# after + its_block
|
46
47
|
subject { fetcher }
|
47
|
-
|
48
|
+
its_block { is_expected.to send_message(Net::HTTP, :get).with('http://google.com').returning('not this time') }
|
48
49
|
```
|
49
50
|
|
50
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
|
@@ -102,6 +103,27 @@ end
|
|
102
103
|
|
103
104
|
Plays really well with `its_call` shown below.
|
104
105
|
|
106
|
+
#### `be_json(value)` and `be_json_sym(value)` matchers
|
107
|
+
|
108
|
+
Simple matcher to check if string is valid JSON and optionally if it matches to expected values:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
expect('{}').to be_json # ok
|
112
|
+
expect('garbage').to be_json
|
113
|
+
# expected value to be a valid JSON string but failed: 765: unexpected token at 'garbage'
|
114
|
+
|
115
|
+
expect('{"foo": "bar"}').to be_json('foo' => 'bar') # ok
|
116
|
+
|
117
|
+
# be_json_sym is more convenient to check with hash keys, parses JSON to symbols
|
118
|
+
expect('{"foo": "bar"}').to be_json_sym(foo: 'bar')
|
119
|
+
|
120
|
+
# nested matchers work, too
|
121
|
+
expect('{"foo": [1, 2, 3]').to be_json_sym(foo: array_including(3))
|
122
|
+
|
123
|
+
# We need to go deeper!
|
124
|
+
expect(something_large).to be_json_sym(include(meta: include(next_page: Integer)))
|
125
|
+
```
|
126
|
+
|
105
127
|
#### `eq_multiline(text)` matcher
|
106
128
|
|
107
129
|
Dedicated to checking some multiline text generators.
|
@@ -135,7 +157,7 @@ require 'saharspec/matchers/eq_multiline'
|
|
135
157
|
|
136
158
|
### `dont`: matcher negation
|
137
159
|
|
138
|
-
|
160
|
+
Allows to get rid of gazilliions of `define_negated_matcher`. `dont` is not 100% grammatically
|
139
161
|
correct, yet short and readable enought. It just negates attached matcher.
|
140
162
|
|
141
163
|
```ruby
|
@@ -241,4 +263,4 @@ checking them). Stay tuned.
|
|
241
263
|
|
242
264
|
## License
|
243
265
|
|
244
|
-
[MIT](https://github.com/zverok/
|
266
|
+
[MIT](https://github.com/zverok/saharspec/blob/master/LICENSE.txt).
|
data/lib/saharspec.rb
CHANGED
data/lib/saharspec/its.rb
CHANGED
@@ -1,11 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
# Wrapper module for all `its_*` RSpec additions.
|
3
5
|
#
|
4
6
|
# See:
|
5
7
|
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
8
|
+
# ## {Map#its_map #its_map}
|
9
|
+
#
|
10
|
+
# ```ruby
|
11
|
+
# subject { %w[1 2 3] }
|
12
|
+
# its_map(:to_s) { is_expected.to eq [1, 2, 3] }
|
13
|
+
# ```
|
14
|
+
#
|
15
|
+
# ## {Call#its_call #its_call}
|
16
|
+
#
|
17
|
+
# ```ruby
|
18
|
+
# subject { [1, 2, 3].method(:[]) }
|
19
|
+
# its_call(2) { is_expected.to ret 3 }
|
20
|
+
# its_call('foo') { is_expected.to raise_error }
|
21
|
+
# ```
|
22
|
+
#
|
23
|
+
# ## {Block#its_block #its_block}
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# subject { something_action }
|
27
|
+
# its_block { is_expected.not_to raise_error }
|
28
|
+
# its_block { is_expected.to change(some, :value).by(1) }
|
29
|
+
# ```
|
30
|
+
#
|
9
31
|
module Its
|
10
32
|
end
|
11
33
|
end
|
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,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby2_keywords'
|
4
|
+
|
1
5
|
module Saharspec
|
2
6
|
module Its
|
3
7
|
module Call
|
@@ -23,11 +27,10 @@ module Saharspec
|
|
23
27
|
# its_call(5) { is_expected.to change(array, :length).by(1) }
|
24
28
|
# end
|
25
29
|
#
|
26
|
-
def its_call(*args, &block)
|
30
|
+
ruby2_keywords def its_call(*args, &block)
|
27
31
|
# rubocop:disable Lint/NestedMethodDefinition
|
28
|
-
describe('
|
32
|
+
describe("(#{args.map(&:inspect).join(', ')})") do
|
29
33
|
let(:__call_subject) do
|
30
|
-
warn 'No need to use its_call without arguments, just it {} will work' if args.empty?
|
31
34
|
-> { subject.call(*args) }
|
32
35
|
end
|
33
36
|
|
@@ -48,4 +51,4 @@ RSpec.configure do |rspec|
|
|
48
51
|
rspec.backtrace_exclusion_patterns << %r{/lib/saharspec/its/call}
|
49
52
|
end
|
50
53
|
|
51
|
-
RSpec::SharedContext.
|
54
|
+
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
|
@@ -11,7 +13,7 @@ module Saharspec
|
|
11
13
|
# its_map(:length) { is_expected.to eq [4, 2, 6] }
|
12
14
|
#
|
13
15
|
# # with attribute chain
|
14
|
-
# its_map(
|
16
|
+
# its_map('reverse.upcase') { is_expected.to eq %w[TSET EM ESAELP] }
|
15
17
|
#
|
16
18
|
# # with Hash (or any other object responding to `#[]`)
|
17
19
|
# subject {
|
@@ -30,12 +32,13 @@ module Saharspec
|
|
30
32
|
# @param block [Proc] The test itself. Inside it, `is_expected` (or `are_expected`) is related to result
|
31
33
|
# of `map`ping the subject.
|
32
34
|
#
|
33
|
-
def its_map(attribute, *options, &block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
35
|
+
def its_map(attribute, *options, &block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
34
36
|
# rubocop:disable Lint/NestedMethodDefinition
|
37
|
+
# TODO: better desciption for different cases
|
35
38
|
describe("map(&:#{attribute})") do
|
36
39
|
let(:__its_map_subject) do
|
37
|
-
if Array === attribute
|
38
|
-
if subject.all? { |s| Hash === s }
|
40
|
+
if Array === attribute
|
41
|
+
if subject.all? { |s| Hash === s }
|
39
42
|
subject.map do |s|
|
40
43
|
attribute.inject(s) { |inner, attr| inner[attr] }
|
41
44
|
end
|
@@ -71,4 +74,4 @@ RSpec.configure do |rspec|
|
|
71
74
|
rspec.backtrace_exclusion_patterns << %r{/lib/saharspec/its/map}
|
72
75
|
end
|
73
76
|
|
74
|
-
RSpec::SharedContext.
|
77
|
+
RSpec::SharedContext.include Saharspec::Its::Map
|
data/lib/saharspec/matchers.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
# All Saharspec matchers, when required, included into `RSpec::Matchers` namespace.
|
3
5
|
#
|
4
6
|
# See:
|
5
7
|
#
|
6
|
-
# * {RSpec::Matchers#dont #dont}
|
7
|
-
# * {RSpec::Matchers#send_message #send_message}
|
8
|
-
# * {RSpec::Matchers#
|
9
|
-
# * {RSpec::Matchers#
|
8
|
+
# * {RSpec::Matchers#dont #dont}: `expect { block }.to change(this).and dont.change(that)`
|
9
|
+
# * {RSpec::Matchers#send_message #send_message}: `expect { block }.to send_message(File, :write)`
|
10
|
+
# * {RSpec::Matchers#ret #ret}: `expect { block }.to ret value`
|
11
|
+
# * {RSpec::Matchers#be_json #be_json}: `expect(response.body).to be_json('foo' => 'bar')`
|
12
|
+
# * {RSpec::Matchers#eq_multiline #eq_multiline}: multiline equality akin to squiggly heredoc
|
10
13
|
#
|
11
14
|
module Matchers
|
12
15
|
end
|
@@ -15,3 +18,5 @@ end
|
|
15
18
|
require_relative 'matchers/eq_multiline'
|
16
19
|
require_relative 'matchers/send_message'
|
17
20
|
require_relative 'matchers/ret'
|
21
|
+
require_relative 'matchers/dont'
|
22
|
+
require_relative 'matchers/be_json'
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Saharspec
|
6
|
+
module Matchers
|
7
|
+
# @private
|
8
|
+
class BeJson
|
9
|
+
include RSpec::Matchers::Composable
|
10
|
+
include RSpec::Matchers # to have #match
|
11
|
+
|
12
|
+
ANY = Object.new.freeze
|
13
|
+
|
14
|
+
attr_reader :actual, :expected
|
15
|
+
|
16
|
+
def initialize(expected, **parse_opts)
|
17
|
+
@expected_matcher = @expected = expected
|
18
|
+
|
19
|
+
# wrap to make be_json('foo' => matcher) work, too
|
20
|
+
unless expected == ANY || expected.respond_to?(:matches?)
|
21
|
+
@expected_matcher = match(expected)
|
22
|
+
end
|
23
|
+
@parse_opts = parse_opts
|
24
|
+
end
|
25
|
+
|
26
|
+
def matches?(json)
|
27
|
+
@actual = JSON.parse(json, **@parse_opts)
|
28
|
+
@expected_matcher == ANY || @expected_matcher === @actual
|
29
|
+
rescue JSON::ParserError => e
|
30
|
+
@parser_error = e
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
def does_not_match?(*args)
|
35
|
+
!matches?(*args)
|
36
|
+
end
|
37
|
+
|
38
|
+
def diffable?
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
def description
|
43
|
+
if @expected == ANY
|
44
|
+
'be a valid JSON string'
|
45
|
+
else
|
46
|
+
expected = @expected.respond_to?(:description) ? @expected.description : @expected
|
47
|
+
"be a valid JSON matching (#{expected})"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def failure_message
|
52
|
+
failed =
|
53
|
+
case
|
54
|
+
when @parser_error
|
55
|
+
"failed: #{@parser_error}"
|
56
|
+
when @expected != ANY
|
57
|
+
"was #{@actual}"
|
58
|
+
end
|
59
|
+
"expected value to #{description} but #{failed}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def failure_message_when_negated
|
63
|
+
'expected value not to be parsed as JSON, but succeeded'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module RSpec
|
70
|
+
module Matchers
|
71
|
+
# `be_json` checks if provided value is JSON, and optionally checks it contents.
|
72
|
+
#
|
73
|
+
# If you need to check against some hashes, it is more convenient to use `be_json_sym`, which
|
74
|
+
# parses JSON with `symbolize_names: true`.
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
#
|
78
|
+
# expect('{}').to be_json # ok
|
79
|
+
# expect('garbage').to be_json
|
80
|
+
# # expected value to be a valid JSON string but failed: 765: unexpected token at 'garbage'
|
81
|
+
#
|
82
|
+
# expect('{"foo": "bar"}').to be_json('foo' => 'bar') # ok
|
83
|
+
# expect('{"foo": "bar"}').to be_json_sym(foo: 'bar') # more convenient
|
84
|
+
#
|
85
|
+
# expect('{"foo": [1, 2, 3]').to be_json_sym(foo: array_including(3)) # nested matchers work
|
86
|
+
# expect(something_large).to be_json_sym(include(meta: include(next_page: Integer)))
|
87
|
+
#
|
88
|
+
# @param expected Value or matcher to check JSON against. It should implement `#===` method,
|
89
|
+
# so all standard and custom RSpec matchers work.
|
90
|
+
def be_json(expected = Saharspec::Matchers::BeJson::ANY)
|
91
|
+
Saharspec::Matchers::BeJson.new(expected)
|
92
|
+
end
|
93
|
+
|
94
|
+
# `be_json_sym` checks if value is a valid JSON and parses it with `symbolize_names: true`. This
|
95
|
+
# way, it is convenient to check hashes content with Ruby's short symbolic keys syntax.
|
96
|
+
#
|
97
|
+
# See {#be_json_sym} for examples.
|
98
|
+
#
|
99
|
+
# @param expected Value or matcher to check JSON against. It should implement `#===` method,
|
100
|
+
# so all standard and custom RSpec matchers work.
|
101
|
+
def be_json_sym(expected = Saharspec::Matchers::BeJson::ANY)
|
102
|
+
Saharspec::Matchers::BeJson.new(expected, symbolize_names: true)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Matchers
|
3
5
|
# @private
|
4
6
|
class Not < RSpec::Matchers::BuiltIn::BaseMatcher
|
5
|
-
def initialize
|
7
|
+
def initialize(*)
|
8
|
+
super
|
6
9
|
@delegator = Delegator.new
|
7
10
|
end
|
8
11
|
|
@@ -11,16 +14,29 @@ module Saharspec
|
|
11
14
|
end
|
12
15
|
|
13
16
|
def match(_expected, actual)
|
14
|
-
@matcher or
|
15
|
-
|
16
|
-
|
17
|
+
@matcher or fail ArgumentError, '`dont` matcher used without any matcher to negate. '\
|
18
|
+
'Usage: dont.other_matcher(args)'
|
19
|
+
|
20
|
+
# https://www.rubydoc.info/github/rspec/rspec-expectations/RSpec%2FMatchers%2FMatcherProtocol:does_not_match%3F
|
21
|
+
# In a negative expectation such as `expect(x).not_to foo`, RSpec will call
|
22
|
+
# `foo.does_not_match?(x)` if this method is defined. If it's not defined it
|
23
|
+
# will fall back to using `!foo.matches?(x)`.
|
24
|
+
if @matcher.respond_to?(:does_not_match?)
|
25
|
+
@matcher.does_not_match?(actual)
|
26
|
+
else
|
27
|
+
!@matcher.matches?(actual)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def failure_message
|
32
|
+
@matcher.failure_message_when_negated
|
17
33
|
end
|
18
34
|
|
19
35
|
def supports_block_expectations?
|
20
36
|
@matcher.supports_block_expectations?
|
21
37
|
end
|
22
38
|
|
23
|
-
def method_missing(m, *a, &b) # rubocop:disable
|
39
|
+
def method_missing(m, *a, &b) # rubocop:disable Lint/MissingSuper
|
24
40
|
if @matcher
|
25
41
|
@matcher.send(m, *a, &b)
|
26
42
|
else
|
@@ -30,7 +46,7 @@ module Saharspec
|
|
30
46
|
self
|
31
47
|
end
|
32
48
|
|
33
|
-
def respond_to_missing?(method, include_private = false)
|
49
|
+
def respond_to_missing?(method, include_private = false) # rubocop:disable Lint/MissingSuper
|
34
50
|
if @matcher
|
35
51
|
@matcher.respond_to?(method, include_private)
|
36
52
|
else
|
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Matchers
|
3
5
|
# @private
|
4
6
|
class Ret
|
5
7
|
include RSpec::Matchers::Composable
|
6
8
|
|
9
|
+
attr_reader :actual, :expected
|
10
|
+
|
7
11
|
def initialize(expected)
|
8
12
|
@expected = expected
|
9
13
|
end
|
@@ -11,25 +15,41 @@ module Saharspec
|
|
11
15
|
def matches?(subject)
|
12
16
|
@subject = subject
|
13
17
|
return false unless subject.respond_to?(:call)
|
18
|
+
|
14
19
|
@actual = subject.call
|
15
|
-
@expected === @actual
|
20
|
+
@expected === @actual
|
16
21
|
end
|
17
22
|
|
18
23
|
def supports_block_expectations?
|
19
24
|
true
|
20
25
|
end
|
21
26
|
|
27
|
+
def diffable?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
22
31
|
def description
|
23
32
|
"return #{@expected.respond_to?(:description) ? @expected.description : @expected.inspect}"
|
24
33
|
end
|
25
34
|
|
26
35
|
def failure_message
|
27
|
-
|
28
|
-
|
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
|
29
44
|
end
|
30
45
|
|
31
46
|
def failure_message_when_negated
|
32
|
-
|
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
|
33
53
|
end
|
34
54
|
end
|
35
55
|
end
|
@@ -42,7 +62,8 @@ module RSpec
|
|
42
62
|
# It should be considered instead of simple value matchers (like `eq`) in the situations:
|
43
63
|
#
|
44
64
|
# 1. Several block behaviors tested in the same test, joined with `.and`, or in separate tests
|
45
|
-
# 2. You test what some block or method returns with arguments, using
|
65
|
+
# 2. You test what some block or method returns with arguments, using
|
66
|
+
# {Saharspec::Its::Call#its_call #its_call}
|
46
67
|
#
|
47
68
|
# Values are tested with `===`, which allows chaining other matchers and patterns to the check.
|
48
69
|
#
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Matchers
|
3
5
|
# @private
|
@@ -16,8 +18,8 @@ module Saharspec
|
|
16
18
|
self
|
17
19
|
end
|
18
20
|
|
19
|
-
def returning(res)
|
20
|
-
@res = res
|
21
|
+
def returning(*res)
|
22
|
+
@res = [*res]
|
21
23
|
self
|
22
24
|
end
|
23
25
|
|
@@ -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
|
@@ -91,7 +94,7 @@ module Saharspec
|
|
91
94
|
|
92
95
|
def allower
|
93
96
|
receive(@method).tap do |a|
|
94
|
-
a.and_return(
|
97
|
+
a.and_return(*@res) if @res
|
95
98
|
a.and_call_original if @call_original
|
96
99
|
end
|
97
100
|
end
|
data/lib/saharspec/util.rb
CHANGED
data/lib/saharspec/version.rb
CHANGED
data/saharspec.gemspec
CHANGED
@@ -23,10 +23,14 @@ 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.
|
29
|
-
|
28
|
+
s.add_runtime_dependency 'ruby2_keywords'
|
29
|
+
|
30
|
+
if RUBY_VERSION >= '2.4' # Newest Rubocop fails on 2.3
|
31
|
+
s.add_development_dependency 'rubocop', '~> 0.93'
|
32
|
+
end
|
33
|
+
s.add_development_dependency 'rspec', '~> 3.7.0'
|
30
34
|
s.add_development_dependency 'rspec-its'
|
31
35
|
s.add_development_dependency 'simplecov', '~> 0.9'
|
32
36
|
s.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,43 +1,57 @@
|
|
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.8
|
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: 2020-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: ruby2_keywords
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
20
|
-
type: :
|
19
|
+
version: '0'
|
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: '0
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.93'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.93'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 3.7.0
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 3.7.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec-its
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,6 +139,7 @@ files:
|
|
125
139
|
- lib/saharspec/its/call.rb
|
126
140
|
- lib/saharspec/its/map.rb
|
127
141
|
- lib/saharspec/matchers.rb
|
142
|
+
- lib/saharspec/matchers/be_json.rb
|
128
143
|
- lib/saharspec/matchers/dont.rb
|
129
144
|
- lib/saharspec/matchers/eq_multiline.rb
|
130
145
|
- lib/saharspec/matchers/request_webmock.rb
|
@@ -145,15 +160,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
160
|
requirements:
|
146
161
|
- - ">="
|
147
162
|
- !ruby/object:Gem::Version
|
148
|
-
version: 2.
|
163
|
+
version: 2.3.0
|
149
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
165
|
requirements:
|
151
166
|
- - ">="
|
152
167
|
- !ruby/object:Gem::Version
|
153
168
|
version: '0'
|
154
169
|
requirements: []
|
155
|
-
|
156
|
-
rubygems_version: 2.6.10
|
170
|
+
rubygems_version: 3.0.3
|
157
171
|
signing_key:
|
158
172
|
specification_version: 4
|
159
173
|
summary: Several additions for DRYer RSpec code
|