开发者

how to test a stale link click (or link I can't get to) using capybara/rspec

开发者 https://www.devze.com 2023-04-06 21:47 出处:网络
Artists cannot rate their own artworks it \"should display error if voting on own artwork\", :js => true do

Artists cannot rate their own artworks

it "should display error if voting on own artwork", :js => true do
  sign_in
  visit "/upcoming"
  click_link "like_post_1"
  page.should have_content("Can't vote on your own artwork")
end

This was passing just fine.

However, I can't click on like_post_1 anymore because I added a feature to prevent voting links from appearing next to your own artworks.

Does this mean I no longer need test coverage for this scenario because it's extremely rare that someone can click on a voting link for their own artwork? Or should still have coverage to test the ajax response, because it's not tested anywhere else and it's possible for some stale page of links to somehow exist in a tabbed browser window. If so... how do I test it if I cannot call click_link?

I could try to create a POST request to create the vote, but capybara doesn't support posts, and I can't test the ajax response that way...

Or is there a way to simul开发者_如何学Goate tabbed browsing in capybara?

Suggestions?


You can use CSS display:none or visibility:hidden for the own artwork instead of eliminating the link from the DOM. You might have to set

Capybara.ignore_hidden_elements = false

Another way is giving up Capybara and putting them into the controller/model spec. Controller/model spec might be a better place for the extremely rare case or safeguarding your app case.


Please try this:

Use sleep function.

sleep 10 use to wait process upto 10 seconds..

it "should display error if voting on own artwork", :js => true do
  sign_in
  visit "/upcoming"
  click_link "like_post_1"
  sleep 10
  page.should have_content("Can't vote on your own artwork")
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号