简体   繁体   中英

rails+capybara+rspec visit generated url in rspec file

In my rspec file i need to visit a generated url.

I have controller, action and object. Is it possible to retrieve the url?

somethings like this:

#spec/file.rb
c=postsController
a=edit
p=Post.last

visit url_for(controller: c,action: e,post: p)

Maybe this:

c = 'posts'
a = 'edit'
p = Post.last.id
visit (url_for :controller => c, :action => a, :id => p)

I've you're using a standard routing pattern, this might work for you too:

visit edit_post_url(:id => Post.last.id)

Also you may need to create a test post before with something like FactoryGirl :)

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