我有这种情况:
Given I am on the edit_stamp page
And I change the date to "14.5.2010" #<-- i need this data
...
Then I should see that the new times has been set #<-- down here
我基本上更新模型的日期,在最后一步中,我想验证模型是否确实更新了我在第一步中选择的日期。
如何在最后一步定义中从顶部抓取所选日期?
Then(/^I should see that the new times has been set$/) do
s = Stamp.first
find_by_id("day_date#{s.id}").has_text?("14.5.2010")
end
这就是我现在所拥有的,但我不想将日期(14.5.2010)写入步骤定义,我想从上一步中获取它。
答案 0 :(得分:2)
试试这个:
And (/^I change the date to "(.*?)"$/) do |input_date|
@new_date = input_date
# and here do whatever you are doing with the date
end
Then(/^I should see that the new times has been set$/) do
s = Stamp.first
s.date_or_whatever_attribute_you_are_using.to_s.should == @new_date
end
这些实例变量(@xx)与整个场景一起存在。