@@ -105,32 +105,36 @@ def scrub(json, path = nil)
105105 include JsonSpec ::Helpers
106106
107107 match do |json |
108- parse_json ( json , @path ) . is_a? ( klass )
108+ @json = json
109+ actual . is_a? ( klass )
109110 end
110111
111112 chain :at_path do |path |
112113 @path = path
113114 end
114115
115116 failure_message_for_should do
116- message = "Expected JSON value type to be #{ klass } "
117+ message = "Expected JSON value type to be #{ klass } , got #{ actual . class } "
117118 message << %( at path "#{ @path } ") if @path
118119 message
119120 end
120121
121122 failure_message_for_should_not do
122- message = "Expected JSON value type to not be #{ klass } "
123+ message = "Expected JSON value type to not be #{ klass } , got #{ actual . class } "
123124 message << %( at path "#{ @path } ") if @path
124125 message
125126 end
127+
128+ def actual
129+ parse_json ( @json , @path )
130+ end
126131end
127132
128133RSpec ::Matchers . define :have_json_size do |expected_size |
129134 include JsonSpec ::Helpers
130135
131136 match do |json |
132- ruby = parse_json ( json , @path )
133- actual_size = ruby . is_a? ( Enumerable ) ? ruby . size : 1
137+ @json = json
134138 actual_size == expected_size
135139 end
136140
@@ -139,14 +143,19 @@ def scrub(json, path = nil)
139143 end
140144
141145 failure_message_for_should do
142- message = "Expected JSON value size to be #{ expected_size } "
146+ message = "Expected JSON value size to be #{ expected_size } , got #{ actual_size } "
143147 message << %( at path "#{ @path } ") if @path
144148 message
145149 end
146150
147151 failure_message_for_should_not do
148- message = "Expected JSON value size to not be #{ expected_size } "
152+ message = "Expected JSON value size to not be #{ expected_size } , got #{ actual_size } "
149153 message << %( at path "#{ @path } ") if @path
150154 message
151155 end
156+
157+ def actual_size
158+ ruby = parse_json ( @json , @path )
159+ ruby . is_a? ( Enumerable ) ? ruby . size : 1
160+ end
152161end
0 commit comments