我怎样才能让下面的黄瓜步骤更漂亮?
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
中间的 if 语句对我来说是个问题,但我需要它来进行 RegEx 匹配并决定是调用“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”附加到它,并将其作为方法调用。