saharspec 0.0.1 → 0.0.2
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/lib/saharspec/matchers/eq_multiline.rb +4 -12
- data/lib/saharspec/matchers/request_webmock.rb +60 -0
- data/lib/saharspec/matchers/send_message.rb +2 -1
- data/lib/saharspec/util.rb +16 -0
- data/lib/saharspec.rb +1 -0
- data/saharspec.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69a3d4d52b75ffe4622413b927337a741b810c57
|
4
|
+
data.tar.gz: 7da973ac28887c0fbd3c65a7aaad6bb6a5140e63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02fb0e99a0b46ace2311deed7d21132582c11f8d5c04727d211f28d5725615eed36ce9e942ec7a31a9767b23b137918eac650598869ed6e01fce79bf503ab43a
|
7
|
+
data.tar.gz: b112f9ea6892c954de423ce07076c530f46c66549d2201d06fe4233b18f933a6505110f148ca4b14ad139e357c0ca3ef26fb106437749d9f23ca584f7be6c987
|
@@ -1,20 +1,12 @@
|
|
1
|
+
require_relative '../util'
|
2
|
+
|
1
3
|
module Saharspec
|
2
4
|
module Matchers
|
3
5
|
# @private
|
4
6
|
class EqMultiline < RSpec::Matchers::BuiltIn::Eq
|
7
|
+
include Util
|
5
8
|
def initialize(expected)
|
6
|
-
|
7
|
-
# 2. remove trailing spaces
|
8
|
-
# 3. preserve trailing spaces ending with "|", but remove the pipe
|
9
|
-
# 4. remove one empty line before & after, allows prettier %Q{}
|
10
|
-
# TODO: check if all lines start with "|"?
|
11
|
-
super(
|
12
|
-
expected
|
13
|
-
.gsub(/^ *\|/, '')
|
14
|
-
.gsub(/ +$/, '')
|
15
|
-
.gsub(/\|$/, '')
|
16
|
-
.gsub(/(\A *\n|\n *\z)/, '')
|
17
|
-
)
|
9
|
+
super(multiline(expected))
|
18
10
|
end
|
19
11
|
end
|
20
12
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# TODO: PR to webmock itself?..
|
2
|
+
#
|
3
|
+
# RSpec::Matchers.define :request_webmock do |url, method: :get|
|
4
|
+
# match do |block|
|
5
|
+
# WebMock.reset!
|
6
|
+
# stub_request(method, url)
|
7
|
+
# .tap { |req| req.with(@with_options) if @with_options && !@with_block }
|
8
|
+
# .tap { |req| req.with(@with_options, &@with_block) if @with_block }
|
9
|
+
# .tap { |req| req.to_return(@response) if @response }
|
10
|
+
# block.call
|
11
|
+
# matcher = have_requested(method, url)
|
12
|
+
# .tap { |matcher| matcher.with(@with_options) if @with_options && !@with_block }
|
13
|
+
# .tap { |matcher| matcher.with(@with_options, &@with_block) if @with_block }
|
14
|
+
# expect(WebMock).to matcher
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# chain :with do |options = {}, &block|
|
18
|
+
# @with_options = options
|
19
|
+
# @with_block = block
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# chain :once do
|
23
|
+
# times(1)
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# chain :twice do
|
27
|
+
# times(2)
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# chain :times do |n|
|
31
|
+
# @times = n
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# chain :at_least_once do
|
35
|
+
# at_least_times(1)
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# chain :at_least_twice do
|
39
|
+
# at_least_times(2)
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# chain :at_least_times do |n|
|
43
|
+
# @at_least_times = n
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# chain :returning do |response|
|
47
|
+
# @response =
|
48
|
+
# case response
|
49
|
+
# when String
|
50
|
+
# {body: response}
|
51
|
+
# when Hash
|
52
|
+
# response
|
53
|
+
# else
|
54
|
+
# fail "Expected string or Hash of params, got #{response.inspect}"
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# supports_block_expectations
|
59
|
+
# end
|
60
|
+
#
|
@@ -3,6 +3,7 @@ module Saharspec
|
|
3
3
|
# @private
|
4
4
|
class SendMessage
|
5
5
|
include RSpec::Mocks::ExampleMethods
|
6
|
+
include RSpec::Matchers::Composable
|
6
7
|
|
7
8
|
def initialize(target, method)
|
8
9
|
@target = target
|
@@ -76,7 +77,7 @@ module Saharspec
|
|
76
77
|
private
|
77
78
|
|
78
79
|
def run(subject)
|
79
|
-
@target.respond_to?(@method) or
|
80
|
+
@target.respond_to?(@method, true) or
|
80
81
|
raise NoMethodError,
|
81
82
|
"undefined method `#{@method}' for#{@target.inspect}:#{@target.class}"
|
82
83
|
allow(@target).to allower
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Saharspec
|
2
|
+
module Util
|
3
|
+
def multiline(string)
|
4
|
+
# 1. for all lines looking like "<spaces>|" -- remove this.
|
5
|
+
# 2. remove trailing spaces
|
6
|
+
# 3. preserve trailing spaces ending with "|", but remove the pipe
|
7
|
+
# 4. remove one empty line before & after, allows prettier %Q{}
|
8
|
+
# TODO: check if all lines start with "|"?
|
9
|
+
string
|
10
|
+
.gsub(/^ *\|/, '')
|
11
|
+
.gsub(/ +$/, '')
|
12
|
+
.gsub(/\|$/, '')
|
13
|
+
.gsub(/(\A *\n|\n *\z)/, '')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/saharspec.rb
CHANGED
data/saharspec.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Shepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -124,7 +124,9 @@ files:
|
|
124
124
|
- lib/saharspec/its/map.rb
|
125
125
|
- lib/saharspec/matchers.rb
|
126
126
|
- lib/saharspec/matchers/eq_multiline.rb
|
127
|
+
- lib/saharspec/matchers/request_webmock.rb
|
127
128
|
- lib/saharspec/matchers/send_message.rb
|
129
|
+
- lib/saharspec/util.rb
|
128
130
|
- saharspec.gemspec
|
129
131
|
homepage: https://github.com/zverok/saharspec
|
130
132
|
licenses:
|