正如托馬斯說,讓這個簡單的關鍵是把事情推下去。要做到這一點,你需要應用一個非常有紀律的簡單模式。
該模式是使每個步驟定義實現一個單一的調用輔助方法。一旦你在你的助手方法中,那麼你可以使用像使用環境變量,配置或一些條件來選擇實現的技術。
一個例子可能會說明這一點。可以說,這兩個應用程序都有能力添加一個朋友。當你第一次添加此功能,您將有一個像
When 'I add a friend' do
fill_in first_name: 'Frieda'
fill_in last_name: 'Fish'
...
end
這需要成爲
When 'I add a friend' do
add_friend name: 'Frieda'
end
通過
module FriendStepHelper
def add_friend(...)
// Only start thinking about IOS or Android from here down.
...
end
end
實現現在這似乎有點痛苦的一步,但你所做的就是將這個問題從Cucumber的領域(它不是爲了解決這類問題而設計的)中解決,並將它移植到Ruby的領域當中,這個領域當然是爲了處理這種類型的pr oblem。
現在,您已經掌握了編程語言,您可以使用各種技術來使用條件優雅而簡單的例如
#use hungarian prefix's
def ios_add_friend
def droid_add_friend
#return early from os specific functions if wrong OS
def ios_add_friend
return if droid?
...
end
# run both implementations when they are different
def add_friend
ios_add_friend
droid_add_friend
end
# loads of other alternatives
...
這正是我一直在尋找的東西。謝謝。 –