Add Capybara selector for your models
If you add this selector:
Capybara.add_selector :record do
xpath { |record| XPath.css("#" + ActionController::RecordIdentifier.dom_id(record)) }
match { |record| record.is_a?(ActiveRecord::Base) }
end
Capybara automatically identifies that you passed a model in find
and within
methods and selects with the appropriate xpath.
Example:
post = Post.first
find(post).click_link("Hello")
within post do
fill_in("What's going on here", :with => "Holy shit this works??")
click_button("Yes")
end
For Mongoid
, use:
match { |record| record.class.ancestors.include? Mongoid::Document }
Via https://gist.github.com/4071870
Written by Felipe Elias Philipp
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#