Skip to content

Instantly share code, notes, and snippets.

@jnicklas
Created November 14, 2012 12:40
Show Gist options
  • Select an option

  • Save jnicklas/4071870 to your computer and use it in GitHub Desktop.

Select an option

Save jnicklas/4071870 to your computer and use it in GitHub Desktop.
Capybara.add_selector :record do
xpath { |record| XPath.css("#" + ActionController::RecordIdentifier.dom_id(record)) }
match { |record| record.is_a?(ActiveRecord::Base) }
end
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
@andrewhr

Copy link
Copy Markdown

❤️

@gmile

gmile commented Nov 14, 2012

Copy link
Copy Markdown

Maybe?

Capybara.add_selector :post

@jnicklas

Copy link
Copy Markdown
Author

@gmile, it works with any ActiveRecord instance, not just Posts. That's the beauty of it. In fact it could be made to work with anything that works with dom_id, not just ActiveRecord, but I'm too lazy to figure out how.

@colszowka

Copy link
Copy Markdown

Awesome :)

@jipiboily

Copy link
Copy Markdown

🍻

@dcaliri

dcaliri commented Nov 14, 2012

Copy link
Copy Markdown

nice

@Hakon

Hakon commented Nov 14, 2012

Copy link
Copy Markdown

@JuarezLustosa

Copy link
Copy Markdown

\o/

@thiagofm

Copy link
Copy Markdown

nice

@sush

sush commented Nov 14, 2012

Copy link
Copy Markdown

Awesome ❤️

@pcreux

pcreux commented Nov 15, 2012

Copy link
Copy Markdown

😻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment