How do I simulate an "Edit" or "Destroy" button click in Rails 3.2 w/ MiniTest? -
how can write integration test editing item? "create" test looks this:
"lets user create product" login_user click_link("products") click_link("new") fill_in "identifier", :with => "mystring" click_button "create" assert page.has_content?("product created") end and works great. confused how edit , destroy tests. index page provides list of products. first use factory create couple of products. in situation there multiple "edit" , "destroy" buttons. can't say:
click_button "destroy" because there 2 of them. how tell 1 click?
and if correct "destroy" button clicked, how hit "ok" button in javascript window pops up?
assuming you're using webrat, can use "within" selector.
the webrat "within" method takes css selector argument. supposing "destroy" button in div id "#product-2", can isolate button with:
within "#product-2" |scope| scope.click_button "destroy" end if need / rather use xpath, can like:
response.should have_xpath(xpath) |button| click_button(button) end alternatively, if using capybara, can use "find" method:
find("#product-2").find("button").click find(:xpath, "//div/div/button").click
Comments
Post a Comment