2012-10-25 161 views
1

我使用几乎杰夫·摩根的新书“黄瓜&奶酪”的确切相同的设置,我有一个页面对象,像这样为什么这个返回“无法转换零到字符串”

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 
+0

你没有添加你的步骤代码,但我不确定,但我会说,如果第二步失败,这是因为@tag是零。事实上,在'submit_basic_message_with_tag'函数中,您将为其分配一个值,但不在第二个函数中。 – pjam

+0

我认为你是对的,那么我将如何从'submit_basic_message_with_tag'方法中获取'@ tag'的值?因为这是我需要的,并且它需要在两种方法中保持相同的价值。 –

+0

因为我不知道你的步骤是怎么做的,所以很难说你如何实现这个 – pjam

回答

0

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

相关问题