简体   繁体   中英

Capybara with rspec

I just started creating test with capybara and I am facing a problem already.

So I have a before do which is creating a row in the DB with a value.

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

After that I test to see if on a page I can find that row. Further I test if create action is working:

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

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

And I get this failing test

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

I understand where is the problem, but how can I check the path against the new created row?

由于您知道它将永远是最后一个,因此请尝试:

Word.last

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM