features/step_definitions/json_steps.rb in visage-app-1.0.0 vs features/step_definitions/json_steps.rb in visage-app-2.0.0

- old
+ new

@@ -92,34 +92,45 @@ Then /^the JSON should have a list of hosts$/ do @response["hosts"].size.should > 0 end Given /^a list of hosts exist$/ do - When 'I go to /data' - Then 'the request should succeed' - Then 'I should receive valid JSON' - Then 'the JSON should have a list of hosts' + step 'I go to /data' + step 'the request should succeed' + step 'I should receive valid JSON' + step 'the JSON should have a list of hosts' end When /^I visit "([^"]*)" on the first available host$/ do |glob| host = @response["hosts"].first url = "/data/#{host}/#{glob}" When "I go to #{url}" end When /^I visit the first available host$/ do - When 'I go to /data' - Then 'the request should succeed' - Then 'I should receive valid JSON' - Then 'the JSON should have a list of hosts' + step 'I go to /data' + step 'the request should succeed' + step 'I should receive valid JSON' + step 'the JSON should have a list of hosts' host = @response["hosts"].first url = "/data/#{host}" When "I go to #{url}" end +When /^I visit the first two available hosts$/ do + step 'I go to /data' + step 'the request should succeed' + step 'I should receive valid JSON' + step 'the JSON should have a list of hosts' + + host = @response["hosts"][0..1].join(',') + url = "/data/#{host}" + When "I go to #{url}" +end + Then /^the JSON should have a list of plugins$/ do host = @response.keys.first plugins = @response[host] plugins.size.should > 0 end @@ -129,7 +140,38 @@ @response.each do |type| %w(dataset datasource type min max).each do |attr| type[attr].should_not be_nil end end +end + + +When /^I visit "([^"]*)" on the first available host with the following query parameters:$/ do |glob, table| + host = @response["hosts"].first + url = "/data/#{host}/#{glob}" + + params = Hash[table.hashes.map { |hash| [hash["parameter"], hash["value"]] }] + query = params.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&") + url += "?#{query}" + + step "I go to #{url}" +end + +Then /^I should see the following parameters for each plugin instance:$/ do |table| + params = Hash[table.hashes.map { |hash| [hash["parameter"], hash["value"]] }] + + @response.should_not be_nil + + @response.each_pair do |host, plugin| + plugin.each_pair do |instance, metric| + metric.each_pair do |k, series| + series.each_pair do |k, data| + params.each do |key, value| + data[key].should == value.to_i + end + end + end + end + end + end