summaryrefslogtreecommitdiff
path: root/features/steps/response_steps.rb
diff options
context:
space:
mode:
Diffstat (limited to 'features/steps/response_steps.rb')
-rw-r--r--features/steps/response_steps.rb38
1 files changed, 34 insertions, 4 deletions
diff --git a/features/steps/response_steps.rb b/features/steps/response_steps.rb
index 37480b7108..989099d78d 100644
--- a/features/steps/response_steps.rb
+++ b/features/steps/response_steps.rb
@@ -1,3 +1,28 @@
+
+# Walk array/hash to determine maximum depth. A scalar (anything but an
+# Array or Hash) has depth 0.
+def count_structure_levels(obj)
+ if obj.respond_to?(:keys)
+ # empty hash also has depth 0.
+ max_depth = 0
+ obj.keys.each do |key|
+ child_levels = 1 + count_structure_levels(obj[key])
+ max_depth = [max_depth, child_levels].max
+ end
+ max_depth
+ elsif obj.is_a?(Array)
+ # empty array also has depth 0.
+ max_depth = 0
+ obj.each do |child|
+ child_levels = 1 + count_structure_levels(child)
+ max_depth = [max_depth, child_levels].max
+ end
+ max_depth
+ else
+ 0
+ end
+end
+
Then /^I should get a '(.+)' exception$/ do |exception|
self.exception.message.to_s.should == exception
end
@@ -40,12 +65,12 @@ end
Then /^the inflated response should match '(.+)' as json$/ do |regex|
puts self.inflated_response.inspect if ENV["DEBUG"]
- self.inflated_response.to_json.should =~ /#{regex}/m
+ Chef::JSON.to_json(self.inflated_response).should =~ /#{regex}/m
end
Then /^the inflated responses key '(.+)' should match '(.+)' as json$/ do |key, regex|
puts self.inflated_response.inspect if ENV["DEBUG"]
- self.inflated_response[key].to_json.should =~ /#{regex}/m
+ Chef::JSON.to_json(self.inflated_response[key]).should =~ /#{regex}/m
end
Then /^the inflated responses key '(.+)' item '(\d+)' should be '(.+)'$/ do |key, index, to_equal|
@@ -135,7 +160,7 @@ Then /^the inflated response should be a kind of '(.+)'$/ do |thing|
end
Then /^the inflated response should respond to '(.+)' with '(.+)'$/ do |method, to_match|
- to_match = JSON.parse(to_match) if to_match =~ /^\[|\{/
+ to_match = Chef::JSON.from_json(to_match) if to_match =~ /^\[|\{/
to_match = true if to_match == 'true'
to_match = false if to_match == 'false'
self.inflated_response.to_hash[method].should == to_match
@@ -146,7 +171,12 @@ Then /^the inflated response should respond to '(.+)' and match '(.+)'$/ do |met
end
Then /^the inflated response should respond to '(.+)' and match '(.+)' as json$/ do |method, regex|
- self.inflated_response.to_hash[method].to_json.should =~ /#{regex}/m
+ Chef::JSON.to_json(self.inflated_response.to_hash[method]).should =~ /#{regex}/m
+end
+
+#And the 'deep_array' component has depth of '50' levels
+Then /^the '(.+)' component has depth of '(.+)' levels$/ do |method, levels|
+ count_structure_levels(self.inflated_response.to_hash[method]).should == levels.to_i
end
Then /^the fields in the inflated response should match the '(.+)'$/ do |stash_name|