0
我怎樣才能讓下面的黃瓜更漂亮一點?如何將一些文本附加到字符串並將其作爲方法調用?
Then(/^I should see my (published|unpublished) project$/) do |published_state|
if published_state == "published"
project_name = published_name
elsif published_state == "unpublished"
project_name = unpublished_name
end
page.should have_content(project_name)
end
的,如果中間語句是我的問題,但我需要它採取正則表達式匹配,並決定是否叫「published_name」或「unpublished_name」。我希望自己是能夠做到這一點,而不是:
Then(/^I should see my (published|unpublished) project$/) do |published_state|
page.should have_content(published_state + "_name")
end
我也試過如下:
page.send should_or_not, have_content("#{pub_state}_name".constantize)
page.send should_or_not, have_content("#{pub_state}_name".to_sym)
基本上我想有一個字符串「發表」和「_name」追加到它,並稱之爲一種方法。
爲什麼published_name'沒有來電顯示的方法'? –