Vyacheslav Loginov
Vyacheslav Loginov

Reputation: 3216

How to write cucumber test?

I want to write test for edit post I write something like:

Given I'm on "/post/1/edit" page

but in this time I haven't record with ID = 1, even if I created it in previous test

How to solve it?

Upvotes: 0

Views: 331

Answers (2)

Andy Waite
Andy Waite

Reputation: 11086

You could say:

Given a post exists
When I edit that post

And the steps defs could be:

Given /^a post exists$/ do
  @post = Post.create!(:title => "...")
end

When /^I edit that post$/ do
  visit edit_post_path(@post)
end

Upvotes: 1

agmcleod
agmcleod

Reputation: 13621

Because it's a test database, you won't know what the id is exactly. I think you're better off to follow the edit link from the index after the post is created.

Upvotes: 2

Related Questions