为什么返回“无法将nil转换为字符串”

时间:2012-10-25 22:33:25

标签: ruby cucumber pageobjects page-object-gem

我使用的几乎与Jeff Morgan的书“Cucumber& Cheese”完全相同,我有一个像这样的页面对象

class NewPublicationPage
  include PageObject
  include RSpec::Matchers
  ... 
  def submit_basic_message_with_tag
    @tag = Time.now.to_i
    ...
    self.tag_entry = @tag
    # the tag ends up getting added later on down the road to a div container.
    ...
  end

  def verify_last_tag
    done_loading
    # tag_list is a div container that should contain the tag.
    tag_list.should include @tag
  end
end

当我在Cucumber步骤中运行以下命令时,每个命令都有自己的步骤,它无法说cannot convert nil to string。我知道它与实例变量@tag有关,但我不确定原因。

When /^I submit a basic message with tags$/ do
  on_page(NewPublicationPage).submit_basic_message_with_tag
end

Then /^I should see the tag under Publish History$/ do
    visit_page(PublishHistoryPage) # goes to page with div container that holds tags
    on_page(NewPublicationPage).verify_last_tag #this creates the error
end

1 个答案:

答案 0 :(得分:0)

但无论如何,你只需要在尝试阅读之前设置@tag。例如,您可以在verify_last_tag方法的开头设置它,或者如果您在两个测试中都需要它,那么您可以查看that post 我不是黄瓜的专家,所以我无法真正帮助你。