如果您有一个地址概念(如所示here),那么您如何编写黄瓜功能来解释资产上所需的地址概念?我看到如何使用factory.newConcept()使用mocha.js示例,但是可以使用黄瓜来解决这个问题吗?
And I have added the following assets of type org.acme.Address
| addressId | street1 | city | state | zipcode |
| AddressA | 123 West 3rd | Anywhere | Texas | 12345 |
| AddressB | 123 West 3rd | Anywhere | Texas | 12345 |
And I have added the following assets of type org.acme.Delivery
| loadId | start | end |
| 1 | AddressA | AddressB |
| 2 | AddressA | AddressB |
模型定义:
concept Address {
o String street1
o String street2 optional
o String city
o String state
o String zipcode
o Double latitude optional
o Double longitude optional
}
asset Delivery identified by loadId {
o String loadId
o Address start
o Address end
}
我已经尝试在start列中传递参数哈希,但是这不起作用并收到错误
ValidationException:实例org.acme.Delivery#1中的模型违规 class org.acme.Address的值为addressConcept,期望一个Resource或 一个概念。
答案 0 :(得分:3)
使用Cucumber测试复杂数据时,需要使用JSON而不是数据表格式。这里有一个例子:
Scenario: given I have added the following assets
Given I have added the following assets
"""
[
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"},
{"$class":"org.acme.sample.SampleAsset", "assetId":"2", "owner":"bob@email.com", "value":"20"}
]
"""
Then I should have the following assets
"""
[
{"$class":"org.acme.sample.SampleAsset", "assetId":"1", "owner":"alice@email.com", "value":"10"},
{"$class":"org.acme.sample.SampleAsset", "assetId":"2", "owner":"bob@email.com", "value":"20"}
]
"""
无论您在哪里看到数据表,都应该能够提供JSON - 包括数组:
import random
print('Welcome to hangman')
print('Type one of the following catagories')
Animal=['Cat','Dog','Bird','Cow','Fish','Lizard']
Clothing=['Shirt','Jeans','Sweatshirt','Shoes','Hat','Scarf']
Weather=['Rain','Snow','Sunny','Sleet','Windy','Stormy']
Colors=['Red','Blue','Green','Purple','Yellow','Grey']
Alphabet= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
print('Type 1 for Animal, 2 for Clothing, 3 for Weather, 4 for Colors')
catagory=int(input())
while catagory > 4:
print('Your input isn\'t one of the catagories. Make sure your choice is a number from 1 to 4.')
print('Try entering again')
print('Type 1 for Animal, 2 for Clothing, 3 for Weather, 4 for Colors')
catagory=int(input())
while catagory == 0:
print('Your input isn\'t one of the catagories. Make sure your choice _
is a number from 1 to 4.')
print('Try entering again')
print('Type 1 for Animal, 2 for Clothing, 3 for Weather, 4 for Colors')
print('')
print('You have ' + str(numberofguesses) + ' left. Good luck.'
catagory=int(input())
if catagory == 1: secretword=random.choice(Animal)
if catagory == 2: secretword=random.choice(Clothing)
if catagory == 3: secretword=random.choice(Weather)
if catagory == 4: secretword=random.choice(Colors)
hiddenword = ('?'*len(secretword))
print('')
print('The word you\'re after is ' + hiddenword)
print('')
print('Type one of the following letters, it must be lowercase.')
print(Alphabet)
i = input()
while numberofguesses != 0:
if i in secretword:
Alphabet.remove(i)
print('')
print('You guessed correctly')
list(hiddenword)
hiddenword=[i if x==str("?") else x for x in hiddenword]
hiddenguessed= ''.join(hiddenword)
print('Here is what you have so far '+ str(hiddenguessed))
print('')
print('Avalable letters left')
print(Alphabet)
print('Guess another letter')
i=input()
else:
numberofguesses = numberofguesses - 1
Alphabet.remove(i)
print('')
print("You guessed wrong")
print("")
list(hiddenword)
hiddenword=[i if x==str("?") else x for x in hiddenword]
hiddenguessed= ''.join(hiddenword)
print('Here is what you have so far '+ str(hiddenguessed))
print('')
print('You now have '+str(numberofguesses)+' guesses left.')
print('Here is what you have so far '+ str(hiddenguessed))
print('')
print('Type one of the following letters, it must be lowercase.')
print(Alphabet)
i=input()
else:
Print('Congrats you have won the game. ' + _
str(hiddenguessed) + ' was the secret word')
答案 1 :(得分:0)
西蒙的答案很好,但实际上并没有回答被问到的问题(尽管它确实在某种程度上回答了问题)。
如果可以,我想采取刺戳(我假设org.acme
是名称空间):
你需要的小黄瓜看起来像这样:
Scenario: given I have added the following asset
Given I have added the following asset
"""
{"$class":"org.acme.Delivery", "loadId":"1", "start":{"$class":"org.acme.Address", "addressId":"AddressA", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}, "end":{"$class":"org.acme.Address", "addressId":"AddressB", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}}
"""
Then I have added the following asset
"""
{"$class":"org.acme.Delivery", "loadId":"1", "start":{"$class":"org.acme.Address", "addressId":"AddressA", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}, "end":{"$class":"org.acme.Address", "addressId":"AddressB", "street1":"123 West 3rd", "city":"Anywhere", "state": "Texas", "zipcode":"12345"}}
"""
使用标准JSON嵌套语法注意嵌套 Address对象。
同样,我认为Simon的答案很好,但如果你不是JSON专家,那么将他的答案(针对一个完全不同的场景)扩展到被问到的答案可能会有挑战性。
除了起始地址和结束地址相同(并且12345在德克萨斯州不是有效的邮政编码)之外,这应该回答所提出的确切问题。
- JSP