-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse_steps.rb
More file actions
138 lines (112 loc) · 4.38 KB
/
Copy pathresponse_steps.rb
File metadata and controls
138 lines (112 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
Then /^I should get a '(.+)' exception$/ do |exception|
self.exception.to_s.should == exception
end
Then /^the response code should be '(.+)'$/ do |response_code|
self.response.status.should == response_code.to_i
end
Then /^the inflated responses key '(.+)' should be the integer '(\d+)'$/ do |key, int|
inflated_response[key].should == int.to_i
end
Then /^the inflated responses key '(.+)' should match '(.+)'$/ do |key, regex|
puts self.inflated_response.inspect if ENV['DEBUG']
self.inflated_response[key].should =~ /#{regex}/m
end
Then /^the inflated responses key '(.+)' should be literally '(.+)'$/ do |key, literal|
puts self.inflated_response.inspect if ENV['DEBUG']
to_check = case literal
when "true"
true
when "false"
false
end
self.inflated_response[key].should == to_check
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
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
end
Then /^the inflated responses key '(.+)' item '(\d+)' should be a kind of '(.+)'$/ do |key, index, constant|
inflated_response[key][index.to_i].should be_a_kind_of(eval(constant))
end
Then /^the inflated responses key '(.+)' item '(\d+)' key '(.+)' should be '(.+)'$/ do |key, index, sub_key, to_equal|
inflated_response[key][index.to_i][sub_key].should == to_equal
end
Then /^the inflated responses key '(.+)' should be '(\d+)' items long$/ do |key, length|
inflated_response[key].length.should == length.to_i
end
Then /^the inflated responses key '(.+)' should not exist$/ do |key|
self.inflated_response.has_key?(key).should == false
end
Then /^the inflated responses key '(.+)' should exist$/ do |key|
self.inflated_response.has_key?(key).should == true
end
Then /^the inflated response should be an empty array$/ do
self.inflated_response.should == []
end
Then /^the inflated response should be an empty hash$/ do
self.inflated_response.should == {}
end
Then /^the inflated response should include '(.+)'$/ do |entry|
if inflated_response.size == 1
inflated_response.should match(/#{entry}/)
else
inflated_response.detect { |n| n =~ /#{entry}/ }.should_not be_empty
end
end
Then /^the inflated response should be '(.+)' items long$/ do |length|
if length.respond_to?(:keys)
self.inflated_response.keys.length.should == length.to_i
else
self.inflated_response.length.should == length.to_i
end
end
Then /^the '(.+)' header should match '(.+)'$/ do |header, regex|
self.response.headers[header].should =~ /#{regex}/
end
Then /^the inflated responses key '(.+)' should include '(.+)'$/ do |key, regex|
if self.inflated_response[key].size == 1
self.inflated_response[key].first.should match(/#{regex}/)
else
self.inflated_response[key].detect { |n| n =~ /#{regex}/ }.should_not be_empty
end
end
Then /^the inflated response should match the '(.+)'$/ do |stash_name|
stash[stash_name].each do |k,v|
self.inflated_response[k.to_s].should == v
end
end
Then /^the inflated response should be the '(.+)'$/ do |stash_key|
stash[stash_key].should == self.inflated_response
end
Then /^the inflated response should be a kind of '(.+)'$/ do |thing|
self.inflated_response.should be_a_kind_of(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 = true if to_match == 'true'
to_match = false if to_match == 'false'
self.inflated_response.send(method.to_sym).should == to_match
end
Then /^the inflated response should respond to '(.+)' and match '(.+)'$/ do |method, to_match|
self.inflated_response.send(method.to_sym).should == to_match
end
Then /^the fields in the inflated response should match the '(.+)'$/ do |stash_name|
self.inflated_response.each do |k,v|
unless k =~ /^_/ || k == 'couchrest-type'
stash[stash_name][k.to_sym].should == v
end
end
end
Then /^the data_bag named '(.+)' should not have an item named '(.+)'$/ do |data_bag, item|
exists = true
begin
Chef::DataBagItem.load(data_bag, item, @couchdb)
rescue
exists = false
end
exists.should == false
end