0
У меня есть рубин функция написанной так:Огурец, вызывающий внешнюю рубиновую функцию с шага?
#./features/sjsonTesting.feature
Feature: Validate DUT JSON
JSON should be evaluated for all routes in API
All API routes should return valid JSON
If JSON is invalid for one or more route in API it has DUT failed
Scenario Outline: Validate JSON
Given there is a DUT with <IP> and <USERNAME> and <PASSWORD>
Then it should return the word PASSED
Examples:
|IP |USERNAME|PASSWORD|
|'172.168.101.139'|admin |test |
I then have step definitions like:
#./features/step_definition/jsonSteps.rb
Given(/^there is a DUT with '(\d+)\.(\d+)\.(\d+)\.(\d+)' and admin and test$/) do |arg1, arg2, arg3, arg4|
testdev(arg1)#pending # express the regexp above with the code you wish you had
end
Then(/^it should return the word PASSED$/) do
testdev(arg1)#pending # express the regexp above with the code you wish you had
end
as well as a support file:
#./support/support.rb
#!/usr/bin/ruby
require 'uri'
require 'net/http'
require 'net/http/digest_auth'
require 'json'
require 'rubygems'
def is_json(json)
begin
JSON.parse(json.to_json)
return true
rescue Exception => e
print e
return false
end
end
def gethash(route)
digest_auth = Net::HTTP::DigestAuth.new
uri = URI.parse route
uri.user = 'admin'
uri.password = 'terraceqam'
h = Net::HTTP.new uri.host, uri.port
h.use_ssl = true
h.verify_mode = OpenSSL::SSL::VERIFY_NONE
req = Net::HTTP::Get.new uri.request_uri
res = h.request req
#puts res['www-authenticate']
auth = digest_auth.auth_header uri, res['www-authenticate'], 'GET'
#puts auth
req = Net::HTTP::Get.new uri.request_uri
#puts req
req.add_field 'Authorization', auth
res = h.request req
#puts res.body
data = JSON.parse(res.body)
return data
end
def testdev(ip)
test = "PASSED"
hash = gethash('https://' + ip +'/views/')
hash["views"].each do |view|
routeapi = 'https://' + ip + '/views/' + view
#print routeapi + "---"
subhash = gethash(routeapi)
answer = is_json(subhash)
if answer == false
test = "FAILED"
end
end
return test
end
, когда я бег огурца, я получаю:
[email protected]:/home/robm/code/BDD/testtq# cucumber
Feature: Validate DUT JSON
JSON should be evaluated for all routes in API
All API routes should return valid JSON
If JSON is invalid for one or more route in API it has DUT failed
Scenario Outline: Validate JSON # features/testJson.feature:6
Given there is a DUT with <IP> and <USERNAME> and <PASSWORD> # features/step_definition/REST_Testing_Steps.rb:2
Then it should return the word PASSED # features/step_definition/REST_Testing_Steps.rb:6
Examples:
| IP | USERNAME | PASSWORD |
| '172.168.101.139' | admin | test |
Invalid argument - connect(2) (Errno::EINVAL)
./features/support/testJson.rb:30:in `gethash'
./features/support/testJson.rb:46:in `testdev'
./features/step_definition/REST_Testing_Steps.rb:3:in `/^there is a DUT with '(\d+)\.(\d+)\.(\d+)\.(\d+)' and admin and test$/'
features/testJson.feature:7:in `Given there is a DUT with <IP> and <USERNAME> and <PASSWORD>'
Failing Scenarios:
cucumber features/testJson.feature:6 # Scenario: Validate JSON
1 scenario (1 failed)
2 steps (1 failed, 1 skipped)
0m0.058s
имеет проблемы с ./features/support/testJson.rb:30: в `gethash ', который равен res = h.request req
Почему не могу получить запрос? в этом вспомогательном коде, когда я запускаю код в командной строке, он отлично работает.
Вы должны пройти arg1, arg2, arg3, arg4 к ваш метод 'testdev', так как ваш arg1 содержит только первую часть IP-адреса. – hidro