webspicy 0.9.0 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ee44fbfe2ca04541a590d8d5cac3afc54e8bb92
4
- data.tar.gz: b92cf71bf4ab3715918f544706f84a1f580ec59a
3
+ metadata.gz: 2a450b7c37c1dd58a30dcb2bc1e9317509f1d5e5
4
+ data.tar.gz: 6f471bbb4aea22f92564c22f720e6eaf50ff5937
5
5
  SHA512:
6
- metadata.gz: 2478429f74cdf469a7182054bd6f9b110b2460bfbb7f6c8631dc3f554ff9c1c5e7dcfde9da928fd05316b5d71c3495daad6650e83802f7bc742eb582a3400586
7
- data.tar.gz: 941daafd12fffa3d700b3bd4023ca009027fb229f9e13193582fda47bef18764f3cebb51c5995574b6436b40bf60e84294c9632257dfa475914dc365688c74bb
6
+ metadata.gz: 4bf135af59ee9a2b9dff46a9849b2b2539bf612728d88c719835ed5012c101ae8f0b8b8c1ba4d00010f8db93c42aeb48200e9ccf2b086d133d492bb43bfb7ac1
7
+ data.tar.gz: 65d79ba0f514277d7bc52e81b3cd92d311708fc58bd570476ab03cc7e4d78ef51e1780a06accc59fbeb686ac17d88fac10e80f6347100ff0f38c23b46d2ee33d
@@ -13,48 +13,62 @@ module Webspicy
13
13
  @assertions = AssertionsClass.new
14
14
  end
15
15
 
16
+ def includes(path, expected = NO_ARG)
17
+ path, expected = '', path if expected == NO_ARG
18
+ unless @assertions.includes(@target, path, expected)
19
+ _! "Expected #{_s(@target, path)} to include #{expected}"
20
+ end
21
+ end
22
+
23
+ def notIncludes(path, expected = NO_ARG)
24
+ path, expected = '', path if expected == NO_ARG
25
+ unless @assertions.notIncludes(@target, path, expected)
26
+ _! "Expected #{_s(@target, path)} not to include #{expected}"
27
+ end
28
+ end
29
+
16
30
  def exists(path = '')
17
31
  unless @assertions.exists(@target, path)
18
- _! "Expected #{_s(@target)} to exists"
32
+ _! "Expected #{_s(@target, path)} to exists"
19
33
  end
20
34
  end
21
35
 
22
36
  def notExists(path = '')
23
37
  unless @assertions.notExists(@target, path)
24
- _! "Expected #{_s(@target)} not to exists"
38
+ _! "Expected #{_s(@target, path)} not to exists"
25
39
  end
26
40
  end
27
41
 
28
42
  def empty(path = '')
29
43
  unless @assertions.empty(@target, path)
30
- _! "Expected #{_s(@target)} to be empty"
44
+ _! "Expected #{_s(@target, path)} to be empty"
31
45
  end
32
46
  end
33
47
 
34
48
  def notEmpty(path = '')
35
49
  unless @assertions.notEmpty(@target, path)
36
- _! "Expected #{_s(@target)} to be non empty"
50
+ _! "Expected #{_s(@target, path)} to be non empty"
37
51
  end
38
52
  end
39
53
 
40
54
  def size(path, expected = NO_ARG)
41
55
  path, expected = '', path if expected == NO_ARG
42
56
  unless @assertions.size(@target, path, expected)
43
- _! "Expected #{_s(@target)} to have a size of #{expected}"
57
+ _! "Expected #{_s(@target, path)} to have a size of #{expected}"
44
58
  end
45
59
  end
46
60
 
47
61
  def idIn(path, *expected)
48
62
  path, expected = '', [path]+expected unless path.is_a?(String)
49
63
  unless @assertions.idIn(@target, path, expected)
50
- _! "Expected #{_s(@target)} to have ids #{expected.join(',')}"
64
+ _! "Expected #{_s(@target, path)} to have ids #{expected.join(',')}"
51
65
  end
52
66
  end
53
67
 
54
68
  def idNotIn(path, *expected)
55
69
  path, expected = '', [path]+expected unless path.is_a?(String)
56
70
  unless @assertions.idNotIn(@target, path, expected)
57
- _! "Expected #{_s(@target)} to not have ids #{expected.join(',')}"
71
+ _! "Expected #{_s(@target, path)} to not have ids #{expected.join(',')}"
58
72
  end
59
73
  end
60
74
 
@@ -64,27 +78,27 @@ module Webspicy
64
78
  id, path = path, ''
65
79
  end
66
80
  unless @assertions.idFD(@target, path, id, expected)
67
- _! "Expected #{_s(@target)} to meet FD #{expected.inspect}"
81
+ _! "Expected #{_s(@target, path)} to meet FD #{expected.inspect}"
68
82
  end
69
83
  end
70
84
 
71
85
  def pathFD(path, expected)
72
86
  unless @assertions.pathFD(@target, path, expected)
73
- _! "Expected #{_s(@target)} to meet FD #{expected.inspect}"
87
+ _! "Expected #{_s(@target, path)} to meet FD #{expected.inspect}"
74
88
  end
75
89
  end
76
90
 
77
91
  def match(path, expected = NO_ARG)
78
92
  path, expected = '', path if expected == NO_ARG
79
93
  unless @assertions.match(@target, path, expected)
80
- _! "Expected #{_s(@target)} to match #{expected.inspect}"
94
+ _! "Expected #{_s(@target, path)} to match #{expected.inspect}"
81
95
  end
82
96
  end
83
97
 
84
98
  def notMatch(path, expected = NO_ARG)
85
99
  path, expected = '', path if expected == NO_ARG
86
100
  unless @assertions.notMatch(@target, path, expected)
87
- _! "Expected #{_s(@target)} not to match #{expected.inspect}"
101
+ _! "Expected #{_s(@target, path)} not to match #{expected.inspect}"
88
102
  end
89
103
  end
90
104
 
@@ -94,8 +108,11 @@ module Webspicy
94
108
  DateTime.parse(str)
95
109
  end
96
110
 
97
- def _s(target)
98
- target.inspect[0..25]
111
+ def _s(target, path)
112
+ result = @assertions.extract_path(target, path)
113
+ result = result.to_json
114
+ result = result[0..25] + "..." if result.size>25
115
+ result
99
116
  end
100
117
 
101
118
  def _!(msg)
@@ -6,6 +6,16 @@ module Webspicy
6
6
 
7
7
  NO_ARG = Object.new
8
8
 
9
+ def includes(target, path, expected = NO_ARG)
10
+ path, expected = '', path if expected == NO_ARG
11
+ target = extract_path(target, path)
12
+ an_array(target).include?(expected)
13
+ end
14
+
15
+ def notIncludes(target, path, expected = NO_ARG)
16
+ not self.includes(target, path, expected)
17
+ end
18
+
9
19
  def exists(target, path = NO_ARG)
10
20
  target = extract_path(target, path)
11
21
  not target.nil?
@@ -77,7 +87,7 @@ module Webspicy
77
87
  !match(target, path, rx)
78
88
  end
79
89
 
80
- private
90
+ public
81
91
 
82
92
  def extract_path(target, path = NO_ARG)
83
93
  return target if path.nil? or path==NO_ARG or path.empty?
@@ -87,6 +97,8 @@ module Webspicy
87
97
  end
88
98
  end
89
99
 
100
+ private
101
+
90
102
  def respond_to!(target, method)
91
103
  unless target.respond_to?(method)
92
104
  raise InvalidArgError, "Expecting instance responding to #{method}"
@@ -2,7 +2,7 @@ module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- TINY = 0
5
+ TINY = 1
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -18,6 +18,16 @@ module Webspicy
18
18
  expect(extract_path(target, 'baz/0/foo')).to eql("world")
19
19
  end
20
20
 
21
+ it 'has an includes() assertion' do
22
+ expect(includes [], 1).to be(false)
23
+ expect(includes [5, 1], 1).to be(true)
24
+ end
25
+
26
+ it 'has an notIcludes() assertion' do
27
+ expect(notIncludes [], 1).to be(true)
28
+ expect(notIncludes [5, 1], 1).to be(false)
29
+ end
30
+
21
31
  it 'has an exists() assertion' do
22
32
  expect(exists nil).to be(false)
23
33
  expect(exists []).to be(true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspicy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau