【问题标题】:Capybara with rspec水豚与 rspec
【发布时间】:2013-09-17 20:03:48
【问题描述】:

我刚开始用 capybara 创建测试,我已经遇到了问题。

所以我有一个之前要做的,它是在数据库中创建一个带有值的行。

  @word = Word.create :word => 'bed'

之后,我会测试是否可以在页面上找到该行。 我进一步测试创建操作是否有效:

    visit keywords_path
    fill_in  'Word', :with => 'work'
    click_button 'Create Word'

    current_path.should == word_path(@word)
    page.should have_content 'work'

我得到了这个失败的测试

creates a new word
 Failure/Error: current_path.should == word_path(@word)
   expected: "/words/1"
        got: "/words/2" (using ==)

我知道问题出在哪里,但是如何根据新创建的行检查路径?

【问题讨论】:

  • 查询您的数据库以获取最新记录并获取 id?

标签: ruby-on-rails testing capybara


【解决方案1】:

既然你知道它永远是最后一个,那就试试吧:

Word.last

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多